Class: Auth::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/token.rb

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Token

Returns a new instance of Token.



5
6
7
8
# File 'lib/token.rb', line 5

def initialize(payload)
  @payload = JSON.parse payload.to_json
  validate_payload
end

Instance Method Details

#encode(jwt_secret) ⇒ Object



30
31
32
# File 'lib/token.rb', line 30

def encode(jwt_secret)
  JWT.encode @payload, jwt_secret, 'HS256'
end

#scope?(scope) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/token.rb', line 14

def scope?(scope)
  @payload['scopes']&.include? scope
end

#scopes?(scopes) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/token.rb', line 18

def scopes?(scopes)
  scopes.all? { |scope| @payload['scopes']&.include? scope }
end

#subObject



10
11
12
# File 'lib/token.rb', line 10

def sub
  @payload['sub']
end

#supplemental(property = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/token.rb', line 22

def supplemental(property = nil)
  unless property.nil? || @payload['sup'][property].nil?
    return @payload['sup'][property]
  end

  @payload['sup']
end