Class: Stormpath::Rails::ControllerAuthentication::FromCookies

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

Constant Summary collapse

OAUTH_ERROR_CODE_RANGE =
(10_000...10_100)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookies) ⇒ FromCookies

Returns a new instance of FromCookies.



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

def initialize(cookies)
  @cookies = cookies
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



7
8
9
# File 'app/services/stormpath/rails/controller_authentication/from_cookies.rb', line 7

def cookies
  @cookies
end

Instance Method Details

#authenticate!Object



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

def authenticate!
  begin
    AccountFromAccessToken.new(access_token_cookie).
  rescue AccountFromAccessToken::NoAccessToken, Stormpath::Oauth::Error, JWT::DecodeError
    delete_access_token_cookie
    
  rescue Stormpath::Error => error
    raise unless OAUTH_ERROR_CODE_RANGE.include?(error.code)
    delete_access_token_cookie
    
  rescue AccountFromAccessToken::AuthenticationWithRefreshTokenAttemptError, AccountFromAccessToken::DifferentIssuerError
    delete_access_token_cookie
    delete_refresh_token_cookie
    raise UnauthenticatedRequest
  end
end