Class: Stormpath::Rails::ControllerAuthentication

Inherits:
Object
  • Object
show all
Defined in:
app/services/stormpath/rails/controller_authentication.rb,
app/services/stormpath/rails/controller_authentication/from_cookies.rb,
app/services/stormpath/rails/controller_authentication/from_basic_auth.rb,
app/services/stormpath/rails/controller_authentication/from_bearer_auth.rb

Defined Under Namespace

Classes: FromBasicAuth, FromBearerAuth, FromCookies

Constant Summary collapse

UnauthenticatedRequest =
Class.new(StandardError)
BEARER_PATTERN =
/^Bearer /
BASIC_PATTERN =
/^Basic /
Stormpath::Rails.config.web.access_token_cookie.name
Stormpath::Rails.config.web.refresh_token_cookie.name

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookies, authorization_header) ⇒ ControllerAuthentication

Returns a new instance of ControllerAuthentication.



12
13
14
15
# File 'app/services/stormpath/rails/controller_authentication.rb', line 12

def initialize(cookies, authorization_header)
  @cookies = cookies
  @authorization_header = authorization_header
end

Instance Attribute Details

#authorization_headerObject (readonly)

Returns the value of attribute authorization_header.



10
11
12
# File 'app/services/stormpath/rails/controller_authentication.rb', line 10

def authorization_header
  @authorization_header
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



10
11
12
# File 'app/services/stormpath/rails/controller_authentication.rb', line 10

def cookies
  @cookies
end

Instance Method Details

#authenticate!Object



17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/stormpath/rails/controller_authentication.rb', line 17

def authenticate!
  if any_auth_cookie_present?
    FromCookies.new(cookies).authenticate!
  elsif bearer_authorization_header?
    FromBearerAuth.new(authorization_header).authenticate!
  elsif basic_authorization_header?
    FromBasicAuth.new(authorization_header).authenticate!
  else
    raise UnauthenticatedRequest
  end
end