Class: Devise::Strategies::Auth0Authenticatable
- Inherits:
-
Base
- Object
- Base
- Devise::Strategies::Auth0Authenticatable
- Defined in:
- lib/devise/strategies/auth0_authenticatable.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.config ⇒ Object
9 10 11 |
# File 'lib/devise/strategies/auth0_authenticatable.rb', line 9 def self.config @config ||= Devise::Auth0::Config.new end |
Instance Method Details
#authenticate! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/devise/strategies/auth0_authenticatable.rb', line 13 def authenticate! token = env['HTTP_AUTHORIZATION'].to_s.gsub('Bearer ', '') begin decoded_token, header = JWT.decode(token, self.class.config.secret) rescue JWT::DecodeError Rails.logger.warn 'Unreadable Auth0 token' fail! 'Unreadable Auth0 token' return end if not decoded_token.is_a?(Hash) Rails.logger.warn "Unexpected Auth0 token structure: expected Hash, got #{decoded_token.inspect}" fail! "Unexpected Auth0 token structure: expected Hash, got #{decoded_token.inspect}" return end if decoded_token['aud'] == self.class.config.client_id user = mapping.to.find_or_sync_auth0(decoded_token) success! user return end Rails.logger.info "Invalid token" fail! 'Invalid token' end |
#store? ⇒ Boolean
40 41 42 |
# File 'lib/devise/strategies/auth0_authenticatable.rb', line 40 def store? false end |
#valid? ⇒ Boolean
44 45 46 |
# File 'lib/devise/strategies/auth0_authenticatable.rb', line 44 def valid? env['HTTP_AUTHORIZATION'].present? end |