Class: Devise::Strategies::HeaderTokenAuthenticatable

Inherits:
TokenAuthenticatable
  • Object
show all
Defined in:
lib/devise_token_auth_headers/header_token_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#valid?Boolean

Devise accomplishes all the work of authentication through side-effects. What you see below is a much, much simpler version of how Devise’s strategies normally work.

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/devise_token_auth_headers/header_token_authenticatable.rb', line 7

def valid?
  super or begin
    if !@header_keys
      base = mapping.to.token_authentication_key.to_s
      @header_keys = [base, "X_#{base.camelize}", "X_#{base}"].map { |x| "HTTP_#{x.upcase}" }
    end
    self.authentication_hash = {}
    self.authentication_type = :token_auth
    headers = header_values
    @header_keys.each { |key|
      if token = headers[key]
        self.authentication_hash[mapping.to.token_authentication_key] = token
        return true
      end
    }
    false
  end
end