Class: Auth0::Mixins::Validation::IdTokenValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/auth0/mixins/validation.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ IdTokenValidator

Returns a new instance of IdTokenValidator.


33
34
35
# File 'lib/auth0/mixins/validation.rb', line 33

def initialize(context)
  @context = context
end

Instance Method Details

#validate(id_token) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/auth0/mixins/validation.rb', line 37

def validate(id_token)
  decoding_error = 'ID token could not be decoded'

  unless !id_token.to_s.empty? && id_token.split('.').count == 3
    raise Auth0::InvalidIdToken, decoding_error
  end

  begin
    header = JWT::JSON.parse(JWT::Base64.url_decode(id_token.split('.').first))
  rescue
    raise Auth0::InvalidIdToken, decoding_error
  end

  claims = decode_and_validate_signature(id_token, header)
  validate_claims(claims)
end