Class: CognitoTokenVerifier::Token
- Inherits:
-
Object
- Object
- CognitoTokenVerifier::Token
- Defined in:
- lib/cognito_token_verifier/token.rb
Instance Attribute Summary collapse
-
#decoded_token ⇒ Object
readonly
Returns the value of attribute decoded_token.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(jwt) ⇒ Token
constructor
A new instance of Token.
- #valid_iss? ⇒ Boolean
- #valid_token_use? ⇒ Boolean
Constructor Details
#initialize(jwt) ⇒ Token
Returns a new instance of Token.
7 8 9 10 11 12 13 14 15 |
# File 'lib/cognito_token_verifier/token.rb', line 7 def initialize(jwt) begin @header= JSON.parse(Base64.decode64(jwt.split('.')[0])) @jwk = JSON::JWK.new(CognitoTokenVerifier.config.jwks["keys"].detect{|jwk| jwk['kid'] == header['kid']}) @decoded_token = JSON::JWT.decode(jwt, @jwk) rescue JSON::JWS::VerificationFailed, JSON::JSONError => e raise TokenDecodingError end end |
Instance Attribute Details
#decoded_token ⇒ Object (readonly)
Returns the value of attribute decoded_token.
5 6 7 |
# File 'lib/cognito_token_verifier/token.rb', line 5 def decoded_token @decoded_token end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
5 6 7 |
# File 'lib/cognito_token_verifier/token.rb', line 5 def header @header end |
Instance Method Details
#expired? ⇒ Boolean
17 18 19 |
# File 'lib/cognito_token_verifier/token.rb', line 17 def expired? decoded_token['exp'] < Time.now.to_i and not CognitoTokenVerifier.config.allow_expired_tokens? end |
#valid_iss? ⇒ Boolean
25 26 27 |
# File 'lib/cognito_token_verifier/token.rb', line 25 def valid_iss? decoded_token['iss'] == CognitoTokenVerifier.config.iss end |
#valid_token_use? ⇒ Boolean
21 22 23 |
# File 'lib/cognito_token_verifier/token.rb', line 21 def valid_token_use? CognitoTokenVerifier.config.any_token_use? || [CognitoTokenVerifier.config.token_use].flatten.include?(decoded_token['token_use']) end |