Class: OctopusAuth::Authenticator
- Inherits:
-
Object
- Object
- OctopusAuth::Authenticator
- Defined in:
- lib/octopus_auth/authenticator.rb
Defined Under Namespace
Classes: ResultObject
Instance Method Summary collapse
- #authenticate {|build_success_result(access_token)| ... } ⇒ Object
-
#initialize(token, scope = nil) ⇒ Authenticator
constructor
A new instance of Authenticator.
Constructor Details
#initialize(token, scope = nil) ⇒ Authenticator
Returns a new instance of Authenticator.
3 4 5 6 |
# File 'lib/octopus_auth/authenticator.rb', line 3 def initialize(token, scope = nil) @token = token.to_s @scope = scope || OctopusAuth.configuration.default_scope end |
Instance Method Details
#authenticate {|build_success_result(access_token)| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/octopus_auth/authenticator.rb', line 8 def authenticate return false if @token.empty? access_token = OctopusAuth.configuration.model_class.find_by(token: @token) return false unless access_token && valid?(access_token) if access_token.expires_at.utc < Time.now.utc unless OctopusAuth.configuration.model_readonly access_token.update(active: false, expired_at: Time.now.utc) end return false end yield build_success_result(access_token) true end |