Class: CosmosAuthentication::RackMiddleware::Authenticator
- Inherits:
-
Object
- Object
- CosmosAuthentication::RackMiddleware::Authenticator
- Defined in:
- lib/cosmos_authentication/rack_middleware.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
- #authenticate(scope = '') ⇒ Object
-
#initialize(opts, env) ⇒ Authenticator
constructor
A new instance of Authenticator.
- #logged_in? ⇒ Boolean
- #logout ⇒ Object
Constructor Details
#initialize(opts, env) ⇒ Authenticator
Returns a new instance of Authenticator.
8 9 10 11 |
# File 'lib/cosmos_authentication/rack_middleware.rb', line 8 def initialize(opts, env) @opts = opts @env = env end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
6 7 8 |
# File 'lib/cosmos_authentication/rack_middleware.rb', line 6 def current @current end |
Instance Method Details
#authenticate(scope = '') ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cosmos_authentication/rack_middleware.rb', line 13 def authenticate(scope = '') begin token = access_token(scope) @current = service.resource_owner(token) rescue Cosmos::UnknownLinkError, Cosmos::FailedCheckError session[:access_token] = nil authenticate end nil end |
#logged_in? ⇒ Boolean
25 26 27 |
# File 'lib/cosmos_authentication/rack_middleware.rb', line 25 def logged_in? !!current end |
#logout ⇒ Object
29 30 31 32 33 34 |
# File 'lib/cosmos_authentication/rack_middleware.rb', line 29 def logout session[:access_token] = nil session[:refresh_token] = nil nil end |