class CognitoTokenVerifier::Token

Attributes

decoded_token[R]
header[R]

Public Class Methods

new(jwt) click to toggle source
# 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

Public Instance Methods

expired?() click to toggle source
# 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?() click to toggle source
# File lib/cognito_token_verifier/token.rb, line 25
def valid_iss?
  decoded_token['iss'] == CognitoTokenVerifier.config.iss
end
valid_token_use?() click to toggle source
# 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