Class: TokenAuthenticateMe::Authentication
- Inherits:
-
Object
- Object
- TokenAuthenticateMe::Authentication
- Defined in:
- lib/token_authenticate_me/authentication.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#token_handler ⇒ Object
readonly
Returns the value of attribute token_handler.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate(options = {}) ⇒ Object
-
#initialize(token:, token_handler: TokenAuthenticateMe::Authentication.method(:default_token_handler)) ⇒ Authentication
constructor
A new instance of Authentication.
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
#token ⇒ Object (readonly)
Returns the value of attribute token.
13 14 15 |
# File 'lib/token_authenticate_me/authentication.rb', line 13 def token @token end |
#token_handler ⇒ Object (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, ) 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( = {}) token_handler.call(token, ) end |