Class: Omniauth::HubAz::Token
- Inherits:
-
Object
- Object
- Omniauth::HubAz::Token
- Defined in:
- lib/omniauth/hub_az/hub_az/token.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
Instance Method Summary collapse
- #has_role?(role) ⇒ Boolean
-
#initialize(jwt, public_key: nil, algorithm: nil) ⇒ Token
constructor
A new instance of Token.
- #roles ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(jwt, public_key: nil, algorithm: nil) ⇒ Token
Returns a new instance of Token.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/omniauth/hub_az/hub_az/token.rb', line 11 def initialize(jwt, public_key: nil, algorithm: nil) public_key = Omniauth::HubAz.public_key if public_key.blank? algorithm = Omniauth::HubAz.algorithm if algorithm.blank? @decoded = JWT.decode(jwt, public_key, true, algorithm: algorithm) @payload = ActiveSupport::HashWithIndifferentAccess.new(@decoded[0]) @header = ActiveSupport::HashWithIndifferentAccess.new(@decoded[1]) @valid = true rescue JWT::VerificationError, JWT::ExpiredSignature, JWT::DecodeError, JWT::IncorrectAlgorithm @payload = {} @header = {} @valid = false end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
5 6 7 |
# File 'lib/omniauth/hub_az/hub_az/token.rb', line 5 def header @header end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/omniauth/hub_az/hub_az/token.rb', line 5 def payload @payload end |
Class Method Details
.verify!(jwt) ⇒ Object
7 8 9 |
# File 'lib/omniauth/hub_az/hub_az/token.rb', line 7 def self.verify!(jwt) self.new(jwt) end |
Instance Method Details
#has_role?(role) ⇒ Boolean
35 36 37 |
# File 'lib/omniauth/hub_az/hub_az/token.rb', line 35 def has_role?(role) roles.include?(role) end |
#roles ⇒ Object
31 32 33 |
# File 'lib/omniauth/hub_az/hub_az/token.rb', line 31 def roles @payload[:roles] || [] end |
#valid? ⇒ Boolean
27 28 29 |
# File 'lib/omniauth/hub_az/hub_az/token.rb', line 27 def valid? !!@valid end |