Sha256: 1fff03bc0463992ec74539099ddea73eb1cc1010b7972221248a76966352a01a
Contents?: true
Size: 1.22 KB
Versions: 9
Compression:
Stored size: 1.22 KB
Contents
require 'active_support/concern' require "cognito_token_verifier/token" module CognitoTokenVerifier module ControllerMacros extend ActiveSupport::Concern included do before_action :verify_cognito_token rescue_from CognitoTokenVerifier::TokenExpired, with: :handle_expired_token rescue_from CognitoTokenVerifier::Error, with: :handle_invalid_token end 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 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 def handle_expired_token(exception) raise exception # Just re-raise the exception: this is for the user to overwrite end def handle_invalid_token(exception) raise exception # Just re-raise the exception: this is for the user to overwrite end end end
Version data entries
9 entries across 9 versions & 1 rubygems