Class: Warden::Cognito::TokenDecoder
- Inherits:
-
Object
- Object
- Warden::Cognito::TokenDecoder
- Defined in:
- lib/warden/cognito/token_decoder.rb
Instance Attribute Summary collapse
-
#jwk_loader ⇒ Object
readonly
Returns the value of attribute jwk_loader.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #cognito_user ⇒ Object
- #decoded_token ⇒ Object
-
#initialize(token, pool_identifier = nil) ⇒ TokenDecoder
constructor
A new instance of TokenDecoder.
- #pool_identifier ⇒ Object
- #sub ⇒ Object
- #user_attribute(attribute_name) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(token, pool_identifier = nil) ⇒ TokenDecoder
Returns a new instance of TokenDecoder.
6 7 8 9 |
# File 'lib/warden/cognito/token_decoder.rb', line 6 def initialize(token, pool_identifier = nil) @token = token @jwk_loader = find_loader(pool_identifier) end |
Instance Attribute Details
#jwk_loader ⇒ Object (readonly)
Returns the value of attribute jwk_loader.
4 5 6 |
# File 'lib/warden/cognito/token_decoder.rb', line 4 def jwk_loader @jwk_loader end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/warden/cognito/token_decoder.rb', line 4 def token @token end |
Instance Method Details
#cognito_user ⇒ Object
24 25 26 |
# File 'lib/warden/cognito/token_decoder.rb', line 24 def cognito_user @cognito_user ||= CognitoClient.scope(pool_identifier).fetch(token) end |
#decoded_token ⇒ Object
19 20 21 22 |
# File 'lib/warden/cognito/token_decoder.rb', line 19 def decoded_token @decoded_token ||= ::JWT.decode(token, nil, true, iss: jwk_loader.jwt_issuer, verify_iss: true, algorithms: ['RS256'], jwks: jwk_loader) end |
#pool_identifier ⇒ Object
32 33 34 |
# File 'lib/warden/cognito/token_decoder.rb', line 32 def pool_identifier jwk_loader.pool_identifier end |
#sub ⇒ Object
15 16 17 |
# File 'lib/warden/cognito/token_decoder.rb', line 15 def sub decoded_token.first['sub'] end |
#user_attribute(attribute_name) ⇒ Object
28 29 30 |
# File 'lib/warden/cognito/token_decoder.rb', line 28 def user_attribute(attribute_name) token_attribute(attribute_name).presence || cognito_user_attribute(attribute_name) end |
#validate! ⇒ Object
11 12 13 |
# File 'lib/warden/cognito/token_decoder.rb', line 11 def validate! decoded_token.present? end |