Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Commit

Permalink
Changed access token path to be configurable as opposed to regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
Omer Jakobinsky committed Sep 13, 2011
1 parent ab8f0ac commit d6fe108
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/oauth2/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def #{model}_class

mattr_accessor :resource_owner_class_name
self.resource_owner_class_name = 'ResourceOwner'
mattr_accessor :access_token_path
self.access_token_path = '/oauth/access_token'

def self.configure
yield self
Expand Down
2 changes: 1 addition & 1 deletion lib/oauth2/provider/rack/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def call(env)
request = env['oauth2'] = ResourceRequest.new(env)

response = catch :oauth2 do
if request.path =~ /\/oauth\/access_token/
if request.path == OAuth2::Provider.access_token_path
handle_access_token_request(env)
else
@app.call(env)
Expand Down
34 changes: 20 additions & 14 deletions spec/requests/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ def app
end
end

describe "requests to %r{/oauth/access_token}" do
it "passes requests to /oauth/access_token to #handle_access_token_request" do
subject.expects(:handle_access_token_request).returns(
[418, {'Content-Type' => 'text/plain'}, 'Short and stout']
)
get "/oauth/access_token"
response.status.should eql(418)
response.body.should eql('Short and stout')
it "passes requests to /oauth/access_token to #handle_access_token_request" do
subject.expects(:handle_access_token_request).returns(
[418, {'Content-Type' => 'text/plain'}, 'Short and stout']
)
get "/oauth/access_token"
response.status.should eql(418)
response.body.should eql('Short and stout')
end

it "passes other requests to the main app" do
get "/any/other/path"
response.status.should eql(200)
response.body.should eql('Apptastic')
end

describe "with access_token_path configured to /api/oauth/access_token" do
before(:each) do
OAuth2::Provider.configure do |config|
config.access_token_path = '/api/oauth/access_token'
end
end

it "passes requests to /api/oauth/access_token to #handle_access_token_request" do
Expand All @@ -35,12 +47,6 @@ def app
response.body.should eql('Short and stout')
end
end

it "passes other requests to the main app" do
get "/any/other/path"
response.status.should eql(200)
response.body.should eql('Apptastic')
end
end

describe "when main app throws :oauth2 response" do
Expand Down

0 comments on commit d6fe108

Please sign in to comment.