Module: CognitoTokenVerifier::ControllerMacros

Extended by:
ActiveSupport::Concern
Defined in:
lib/cognito_token_verifier/controller_macros.rb

Instance Method Summary collapse

Instance Method Details

#cognito_tokenObject

Raises:



14
15
16
17
18
# File 'lib/cognito_token_verifier/controller_macros.rb', line 14

def cognito_token
  return @cognito_token if @cognito_token.present? # Caching here, so gem user can access token themselves for additional checks
  raise TokenMissing unless request.headers['authorization'].present?
  @cognito_token = CognitoTokenVerifier::Token.new(request.headers['authorization'])
end

#handle_expired_token(exception) ⇒ Object



26
27
28
# File 'lib/cognito_token_verifier/controller_macros.rb', line 26

def handle_expired_token(exception)
  raise exception # Just re-raise the exception: this is for the user to overwrite
end

#handle_invalid_token(exception) ⇒ Object



30
31
32
# File 'lib/cognito_token_verifier/controller_macros.rb', line 30

def handle_invalid_token(exception)
  raise exception # Just re-raise the exception: this is for the user to overwrite
end

#verify_cognito_tokenObject

Raises:



20
21
22
23
24
# File 'lib/cognito_token_verifier/controller_macros.rb', line 20

def verify_cognito_token
  raise TokenExpired if cognito_token.expired?
  raise IncorrectTokenType.new(cognito_token) unless cognito_token.valid_token_use?
  raise InvalidIss.new(cognito_token) unless cognito_token.valid_iss?
end