Sha256: 24cd749b622409284f0cfa336df005c0d94de37754ffc982aebefaa17f9169d0
Contents?: true
Size: 1.3 KB
Versions: 13
Compression:
Stored size: 1.3 KB
Contents
require 'devise/strategies/base' module Devise module Strategies class Oauth2GrantTypeStrategy < Authenticatable def valid? params[:controller] == 'devise/oauth2/tokens' && request.post? && params[:grant_type] == grant_type end # defined by subclass def grant_type end # defined by subclass def authenticate_grant_type(client) end def authenticate! client_id, client_secret = request.authorization ? decode_credentials : [params[:client_id], params[:client_secret]] client = Devise::Oauth2Providable::Client.find_by_identifier client_id if client && client.secret == client_secret env[Devise::Oauth2Providable::CLIENT_ENV_REF] = client authenticate_grant_type(client) else oauth_error! :invalid_client, 'invalid client credentials' end end # return custom error response in accordance with the oauth spec # see http://tools.ietf.org/html/draft-ietf-oauth-v2-16#section-4.3 def oauth_error!(error_code = :invalid_request, description = nil) body = {:error => error_code} body[:error_description] = description if description custom! [400, {'Content-Type' => 'application/json'}, [body.to_json]] throw :warden end end end end
Version data entries
13 entries across 13 versions & 1 rubygems