Class: Auth::Token
- Inherits:
-
Object
- Object
- Auth::Token
- Defined in:
- lib/token.rb
Instance Method Summary collapse
- #encode(jwt_secret) ⇒ Object
-
#initialize(payload) ⇒ Token
constructor
A new instance of Token.
- #scope?(scope) ⇒ Boolean
- #scopes?(scopes) ⇒ Boolean
- #sub ⇒ Object
- #supplemental(property = nil) ⇒ Object
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
28 29 30 |
# File 'lib/token.rb', line 28 def encode(jwt_secret) JWT.encode @payload, jwt_secret, "HS256" end |
#scope?(scope) ⇒ Boolean
14 15 16 |
# File 'lib/token.rb', line 14 def scope?(scope) @payload["scopes"]&.include? scope end |
#scopes?(scopes) ⇒ Boolean
18 19 20 |
# File 'lib/token.rb', line 18 def scopes?(scopes) scopes.all? { |scope| @payload["scopes"]&.include? scope } end |
#sub ⇒ Object
10 11 12 |
# File 'lib/token.rb', line 10 def sub @payload["sub"] end |
#supplemental(property = nil) ⇒ Object
22 23 24 25 26 |
# File 'lib/token.rb', line 22 def supplemental(property = nil) return @payload["sup"][property] unless property.nil? || @payload["sup"][property].nil? @payload["sup"] end |