Class: AuthenticatorServer::TokenVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/authenticator_server/token_verifier.rb

Constant Summary collapse

ALGORITHM =

ALGORITHM = ‘RS256’

'HS512'

Class Method Summary collapse

Class Method Details

.verify(token, token_verification_key) ⇒ Object

This method verifies the token using token_verification_key

Parameters:

  • token (String)

    jwt to be verified

  • token_verification_key (String)

    secret key use to verify the token

Returns:

  • (Object)

    on success return the payload



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/authenticator_server/token_verifier.rb', line 21

def self.verify(token, token_verification_key)
  begin
    raise ArgumentError.new('String argument is expected')  unless token_verification_key.kind_of? String
    # rsa_public_key = AuthenticatorServer::RSAKeyPairProvider.public_key_from_base64 token_verification_key
    output = JWT.decode(token, token_verification_key, true, { algorithm: ALGORITHM })
    output.first
  rescue ArgumentError => e
    argument_error_message e
  rescue JWT::IncorrectAlgorithm => e
    incorrect_algorithm_message e
  rescue JWT::ExpiredSignature => e
    expired_signature_message e
  rescue JWT::VerificationError => e
    verification_error_message e
  rescue JWT::DecodeError => e
    decode_error_message e
  rescue Exception => e
    server_exception_message e
  end
end