Class: CosmosAuthentication::RackMiddleware::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/cosmos_authentication/rack_middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#currentObject (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

Returns:

  • (Boolean)


25
26
27
# File 'lib/cosmos_authentication/rack_middleware.rb', line 25

def logged_in?
  !!current
end

#logoutObject



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