Class: Virgil::Jwt::JwtVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/virgil/jwt/jwt_verifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token_signer:, api_public_key:, api_public_key_id:) ⇒ JwtVerifier

Initializes a new instance of the class

Parameters:

  • access_token_signer (AccessTokenSigner)
  • api_public_key (PublicKey)
  • api_public_key_id (String)


55
56
57
58
59
# File 'lib/virgil/jwt/jwt_verifier.rb', line 55

def initialize(access_token_signer:, api_public_key:, api_public_key_id:)
  @access_token_signer = access_token_signer
  @api_public_key = api_public_key
  @api_public_key_id = api_public_key_id
end

Instance Attribute Details

#access_token_signerAccessTokenSigner (readonly)

verify token signature.

Returns:

  • (AccessTokenSigner)

    that is used to



41
42
43
# File 'lib/virgil/jwt/jwt_verifier.rb', line 41

def access_token_signer
  @access_token_signer
end

#api_public_keyPublicKey (readonly)

Public Key which should be used to verify signatures

Returns:

  • (PublicKey)


45
46
47
# File 'lib/virgil/jwt/jwt_verifier.rb', line 45

def api_public_key
  @api_public_key
end

#api_public_key_idString (readonly)

Id of public key which should be used to verify signatures

Returns:

  • (String)


49
50
51
# File 'lib/virgil/jwt/jwt_verifier.rb', line 49

def api_public_key_id
  @api_public_key_id
end

Instance Method Details

#verify_token(jwt) ⇒ Object

Verifies specified token.

Parameters:

  • jwt (Jwt)

    token to be virefied.

Returns:

  • true if token is verified, otherwise false.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/virgil/jwt/jwt_verifier.rb', line 64

def verify_token(jwt)
  if jwt.header_content.key_id != @api_public_key_id ||
     jwt.header_content.algorithm != @access_token_signer.algorithm ||
     jwt.header_content.content_type != JwtHeaderContent::VIRGIL_CONTENT_TYPE ||
     jwt.header_content.type != JwtHeaderContent::JWT_TYPE
    return false
  end

  @access_token_signer.verify_token_signature(jwt.signature_data,
                                              jwt.unsigned_data,
                                              api_public_key)
end