Module: Devise::Rownd::Token

Included in:
Strategies
Defined in:
lib/devise/rownd/token.rb

Class Method Summary collapse

Class Method Details

.fetch_jwks_from_apiObject



29
30
31
32
33
34
35
# File 'lib/devise/rownd/token.rb', line 29

def fetch_jwks_from_api
  response = ::Devise::Rownd::API.make_api_call('/hub/auth/keys')
  return response.body['keys'] if response.success?

  Devise::Rownd::Log.error("Failed to fetch JWKs: #{response.body['message']}")
  nil
end

.jwksObject



25
26
27
# File 'lib/devise/rownd/token.rb', line 25

def jwks
  Devise::Rownd::Caching.fetch('rownd_jwks', 15.minutes) { fetch_jwks_from_api }
end

.verify_token(access_token) ⇒ Object

Raises:

  • (StandardError)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/devise/rownd/token.rb', line 12

def verify_token(access_token)
  raise StandardError, 'No JWKs' unless jwks

  jwks.each do |jwk|
    response = JOSE::JWT.verify_strict(jwk, ['EdDSA'], access_token)
    return response[1].fields if response[0]
  rescue StandardError => e
    Devise::Rownd::Log.debug("jwt not validated: #{e.message}")
    next
  end
  raise StandardError, 'Failed to verify JWT. No matching JWKs'
end