Class: Zaikio::Hub::TokenData

Inherits:
Object
  • Object
show all
Defined in:
lib/zaikio/hub/token_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audience:, on_behalf_of:, subject:, scopes:) ⇒ TokenData

Returns a new instance of TokenData.



17
18
19
20
21
22
# File 'lib/zaikio/hub/token_data.rb', line 17

def initialize(audience:, on_behalf_of:, subject:, scopes:)
  @audience = audience
  @on_behalf_of = on_behalf_of
  @subject = subject
  @scopes = scopes
end

Instance Attribute Details

#audienceObject (readonly)

Returns the value of attribute audience.



4
5
6
# File 'lib/zaikio/hub/token_data.rb', line 4

def audience
  @audience
end

#on_behalf_ofObject (readonly)

Returns the value of attribute on_behalf_of.



4
5
6
# File 'lib/zaikio/hub/token_data.rb', line 4

def on_behalf_of
  @on_behalf_of
end

#scopesObject (readonly)

Returns the value of attribute scopes.



4
5
6
# File 'lib/zaikio/hub/token_data.rb', line 4

def scopes
  @scopes
end

#subjectObject (readonly)

Returns the value of attribute subject.



4
5
6
# File 'lib/zaikio/hub/token_data.rb', line 4

def subject
  @subject
end

Class Method Details

.from(payload) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/zaikio/hub/token_data.rb', line 6

def self.from(payload)
  subjects = payload["sub"].split(">")

  new(
    audience: payload["aud"].first,
    on_behalf_of: subjects.first,
    subject: subjects.last,
    scopes: payload["scope"]
  )
end

Instance Method Details

#on_behalf_of_idObject



28
29
30
# File 'lib/zaikio/hub/token_data.rb', line 28

def on_behalf_of_id
  @on_behalf_of_id ||= id_for(:on_behalf_of)
end

#on_behalf_of_typeObject



24
25
26
# File 'lib/zaikio/hub/token_data.rb', line 24

def on_behalf_of_type
  @on_behalf_of_type ||= type_for(:on_behalf_of)
end

#subject_idObject



36
37
38
# File 'lib/zaikio/hub/token_data.rb', line 36

def subject_id
  @subject_id ||= id_for(:subject)
end

#subject_typeObject



32
33
34
# File 'lib/zaikio/hub/token_data.rb', line 32

def subject_type
  @subject_type ||= type_for(:subject)
end