Class: Devise::Strategies::Auth0Authenticatable

Inherits:
Base
  • Object
show all
Defined in:
lib/devise/strategies/auth0_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/devise/strategies/auth0_authenticatable.rb', line 8

def authenticate!
  token = env['HTTP_AUTHORIZATION'].to_s.gsub('Bearer ', '')

  begin
    decoded_token, header = JWT.decode(token, Devise::Auth0::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'] == Auth0::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



35
36
37
# File 'lib/devise/strategies/auth0_authenticatable.rb', line 35

def store?
  false
end

#valid?Boolean



39
40
41
# File 'lib/devise/strategies/auth0_authenticatable.rb', line 39

def valid?
  env['HTTP_AUTHORIZATION'].present?
end