Skip to content

Commit f1926a3

Browse files
author
Michael Bleigh
committed
Switch to DSL methods for credentials and extra, update README
1 parent 0509a48 commit f1926a3

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

README.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# OmniAuth OAuth
22

3+
**Note:** This gem is designed to work with the unreleased OmniAuth 1.0
4+
library. It will not be officially released on RubyGems.org until
5+
OmniAuth 1.0 is released.
6+
37
This gem contains a generic OAuth strategy for OmniAuth. It is meant to
48
serve as a building block strategy for other strategies and not to be
59
used independently (since it has no inherent way to gather uid and user
@@ -22,29 +26,24 @@ subclass it and add a few extra methods like so:
2226
# initializing your consumer from the OAuth gem.
2327
option :client_options, {:site => "https://api.somesite.com"}
2428

25-
# This is called after authentication has succeeded. If
29+
# These are called after authentication has succeeded. If
2630
# possible, you should try to set the UID without making
2731
# additional calls (if the user id is returned with the token
2832
# or as a URI parameter). This may not be possible with all
2933
# providers.
30-
def uid
31-
request.params['user_id']
32-
end
34+
uid{ request.params['user_id'] }
3335

34-
# This is called after authentication has succeeded. You can
35-
# make signed API requests by using the #access_token method
36-
# which is simply an OAuth gem AccessToken object.
37-
def info
36+
info do
3837
{
3938
:name => raw_info['name'],
4039
:location => raw_info['city']
4140
}
4241
end
4342

44-
def extra
45-
super.merge({
43+
extra do
44+
{
4645
'raw_info' => raw_info
47-
})
46+
}
4847
end
4948

5049
def raw_info
@@ -54,4 +53,26 @@ subclass it and add a few extra methods like so:
5453
end
5554
end
5655

57-
That's pretty much it! Once you are successfully
56+
That's pretty much it!
57+
58+
## License
59+
60+
Copyright (C) 2011 by Michael Bleigh and Intridea, Inc.
61+
62+
Permission is hereby granted, free of charge, to any person obtaining a copy
63+
of this software and associated documentation files (the "Software"), to deal
64+
in the Software without restriction, including without limitation the rights
65+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
66+
copies of the Software, and to permit persons to whom the Software is
67+
furnished to do so, subject to the following conditions:
68+
69+
The above copyright notice and this permission notice shall be included in
70+
all copies or substantial portions of the Software.
71+
72+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
73+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
74+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
75+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
76+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
77+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
78+
THE SOFTWARE.

lib/omniauth/strategies/oauth.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def callback_phase
6767
fail!(:session_expired, e)
6868
end
6969

70-
def credentials
70+
credentials do
7171
{'token' => access_token.token, 'secret' => access_token.secret}
7272
end
7373

74-
def extra
74+
extra do
7575
{'access_token' => access_token}
7676
end
7777
end

spec/omniauth/strategies/oauth_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
describe "OmniAuth::Strategies::OAuth" do
44
class MyOAuthProvider < OmniAuth::Strategies::OAuth
5-
def uid
6-
access_token.token
7-
end
8-
9-
def info
10-
{'name' => access_token.token}
11-
end
5+
uid{ access_token.token }
6+
info{ {'name' => access_token.token} }
127
end
138

149
def app
@@ -40,6 +35,7 @@ def session
4035
before do
4136
get '/auth/example.org'
4237
end
38+
4339
it 'should redirect to authorize_url' do
4440
last_response.should be_redirect
4541
last_response.headers['Location'].should == 'https://api.example.org/oauth/authorize?oauth_token=yourtoken'

0 commit comments

Comments
 (0)