Class: JsonWebToken
- Inherits:
-
Object
- Object
- JsonWebToken
- Defined in:
- lib/auth0_current_user/json_web_token.rb
Class Method Summary collapse
- .configuration ⇒ Object
- .get_claim(token, claim_name) ⇒ Object
- .jwks_hash ⇒ Object
- .verify(token) ⇒ Object
Class Method Details
.configuration ⇒ Object
41 42 43 |
# File 'lib/auth0_current_user/json_web_token.rb', line 41 def self.configuration @configuration ||= Auth0CurrentUser::Configuration.new end |
.get_claim(token, claim_name) ⇒ Object
37 38 39 |
# File 'lib/auth0_current_user/json_web_token.rb', line 37 def self.get_claim(token, claim_name) JWT.decode(token, nil, false).first[0][claim_name] end |
.jwks_hash ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/auth0_current_user/json_web_token.rb', line 21 def self.jwks_hash jwks_raw = Net::HTTP.get URI("#{configuration.auth0_domain}/.well-known/jwks.json") jwks_keys = Array(JSON.parse(jwks_raw)['keys']) Hash[ jwks_keys .map do |k| [ k['kid'], OpenSSL::X509::Certificate.new( Base64.decode64(k['x5c'].first) ).public_key ] end ] end |
.verify(token) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/auth0_current_user/json_web_token.rb', line 9 def self.verify(token) JWT.decode(token, nil, true, # Verify the signature of this token algorithms: 'RS256', iss: configuration.auth0_domain, verify_iss: true, aud: configuration.auth0_audience, verify_aud: true) do |header| jwks_hash[header['kid']] end end |