Skip to content

Commit

Permalink
Use models defined by mappings in auth. controller, refs socialcast#23
Browse files Browse the repository at this point in the history
  • Loading branch information
BRMatt committed Dec 12, 2011
1 parent 106c7e1 commit 2999df8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ def respond(status, header, response)
end

def authorize_endpoint(allow_approval = false)
models = self.devise_oauth_mapping.models

Rack::OAuth2::Server::Authorize.new do |req, res|
@client = Client.find_by_identifier(req.client_id) || req.bad_request!
@client = models[:client].find_by_identifier(req.client_id) || req.bad_request!
res.redirect_uri = req.verify_redirect_uri!(@client.redirect_uri)
if allow_approval
if params[:approve].present?
case req.response_type
when :code
authorization_code = current_user.authorization_codes.create!(:client => @client)
authorization_code = self.resource.authorization_codes.create!(:client => @client)
res.code = authorization_code.token
when :token
access_token = current_user.access_tokens.create!(:client => @client).token
access_token = self.resource.access_tokens.create!(:client => @client).token
bearer_token = Rack::OAuth2::AccessToken::Bearer.new(:access_token => access_token)
res.access_token = bearer_token
res.uid = resource.id
Expand Down
15 changes: 9 additions & 6 deletions lib/devise/oauth2_providable/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ module Oauth2Providable
module Controllers
module Helpers

# Authenticates the current scope and gets the current resource from the session.
# Taken from devise
def authenticate_scope!
send(:"authenticate_#{resource_name}!", :force => true)
self.resource = send(:"current_#{resource_name}")
end
# Authenticates the current scope and gets the current resource from the session.
# Taken from devise
def authenticate_scope!
send(:"authenticate_#{resource_name}!", :force => true)
self.resource = send(:"current_#{resource_name}")
end
def devise_oauth_mapping
@devise_oauth_mapping ||= request.env[Devise::Oauth2Providable::MAPPING_ENV_REF]
end
end
end
end
Expand Down

0 comments on commit 2999df8

Please sign in to comment.