Class: TokenAuthenticateMe::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/token_authenticate_me/authentication.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, token_handler: TokenAuthenticateMe::Authentication.method(:default_token_handler)) ⇒ Authentication

Returns a new instance of Authentication.



15
16
17
18
# File 'lib/token_authenticate_me/authentication.rb', line 15

def initialize(token:, token_handler: TokenAuthenticateMe::Authentication.method(:default_token_handler))
  @token = token
  @token_handler = token_handler
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/token_authenticate_me/authentication.rb', line 13

def token
  @token
end

#token_handlerObject (readonly)

Returns the value of attribute token_handler.



13
14
15
# File 'lib/token_authenticate_me/authentication.rb', line 13

def token_handler
  @token_handler
end

Class Method Details

.default_token_handler(token, _options) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/token_authenticate_me/authentication.rb', line 3

def self.default_token_handler(token, _options)
  session = TokenAuthenticateMe::Session.find_by_key(token)

  if session && session.expiration > DateTime.now
    session
  else
    false
  end
end

Instance Method Details

#authenticate(options = {}) ⇒ Object



20
21
22
# File 'lib/token_authenticate_me/authentication.rb', line 20

def authenticate(options = {})
  token_handler.call(token, options)
end