Class: Devise::Strategies::OauthTokenAuthenticatable

Inherits:
Authenticatable
  • Object
show all
Defined in:
lib/devise/oauth_token_authenticatable/strategies/oauth_token_authenticatable_strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/devise/oauth_token_authenticatable/strategies/oauth_token_authenticatable_strategy.rb', line 20

def authenticate!
  resource = mapping.to.find_for_oauth_token_authentication( @token )
  if validate(resource)
    resource.after_oauth_token_authentication
    success! resource
  elsif !halted?
    fail(:invalid_token)
  end
rescue ::OAuth2::Error
  oauth_error! :invalid_token, 'invalid access token'
end

#oauth_error!(error_code = :invalid_request, description = nil) ⇒ Object

This method copied in from ‘devise_oauth2_providable’ lib/devise/oauth2_providable/strategies/oauth2_grant_type_strategy.rb return custom error response in accordance with the oauth spec see tools.ietf.org/html/draft-ietf-oauth-v2-16#section-4.3



36
37
38
39
40
41
# File 'lib/devise/oauth_token_authenticatable/strategies/oauth_token_authenticatable_strategy.rb', line 36

def oauth_error!(error_code = :invalid_request, description = nil)
  body = {:error => error_code}
  body[:error_description] = description if description
  custom! [401, {'Content-Type' => 'application/json'}, [body.to_json]]
  throw :warden
end

#store?Boolean

Do not store OauthToken validation in session. This forces the strategy to check the token on every request.

Returns:

  • (Boolean)


45
46
47
# File 'lib/devise/oauth_token_authenticatable/strategies/oauth_token_authenticatable_strategy.rb', line 45

def store?
  false
end

#valid?Boolean

Return true or false, indicating if this strategy is applicable

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/devise/oauth_token_authenticatable/strategies/oauth_token_authenticatable_strategy.rb', line 15

def valid?
  @token = setup!
  @token.present?
end