oauth-plugin 0.4.0.pre5 → 0.4.0.pre6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +6 -3
- data/README.rdoc +39 -39
- data/generators/oauth_consumer/templates/controller.rb +1 -1
- data/generators/oauth_consumer/templates/oauth_config.rb +33 -33
- data/generators/oauth_provider/templates/client_application_test.rb +1 -1
- data/generators/oauth_provider/templates/clients_controller_spec.rb +6 -6
- data/generators/oauth_provider/templates/clients_controller_test.rb +5 -5
- data/generators/oauth_provider/templates/oauth2_token.rb +1 -1
- data/lib/generators/erb/oauth_provider_generator.rb +2 -0
- data/lib/generators/oauth_provider/oauth_provider_generator.rb +0 -10
- data/lib/oauth-plugin/version.rb +1 -1
- data/lib/oauth/controllers/provider_controller.rb +20 -18
- data/oauth-plugin.gemspec +3 -3
- metadata +3 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
0.4.0-pre6
|
2
|
+
- fixes issue with erb generator in rails 3 [pelleb]
|
3
|
+
- various cleanups in generators [akonan]
|
1
4
|
0.4.0-pre5
|
2
5
|
- protect oauth consumer relay with :expose configuration option. It's off by default. [pelle]
|
3
6
|
- Reenable twitter client. It is now configurable for twitter tokens. :client=>:twitter_gem or :oauth_gem [pelle]
|
@@ -40,7 +43,7 @@
|
|
40
43
|
0.3.12
|
41
44
|
- Added a simple PortableContacts adapter for GoogleToken
|
42
45
|
- Added a SimpleClient wrapper to provide really simple wrapper for OAuth based json web services
|
43
|
-
- Increased token size in consumer_tokens table because of Yahoo's oversized tokens
|
46
|
+
- Increased token size in consumer_tokens table because of Yahoo's oversized tokens
|
44
47
|
- Added support for Yahoo
|
45
48
|
- Added support for Google (Boon Low)
|
46
49
|
9/26/2009
|
@@ -58,11 +61,11 @@
|
|
58
61
|
- Added invalidate action to provider, which allows a token to invalidate itself /oauth/invalidate
|
59
62
|
- Added capabilities action to provider. Lets you expand to allow auto discovery of permissions and services that token provides.
|
60
63
|
- Can override how authorize form indicates an authorization. To get around ugly checkbox
|
61
|
-
|
64
|
+
|
62
65
|
def user_authorizes_token?
|
63
66
|
params[:commit] == 'Authorize'
|
64
67
|
end
|
65
|
-
|
68
|
+
|
66
69
|
7/23/2009
|
67
70
|
0.3.8
|
68
71
|
- Fixed Gem Plugins Loading
|
data/README.rdoc
CHANGED
@@ -28,7 +28,7 @@ You need to install the oauth gem (0.4.4) which is the core OAuth ruby library.
|
|
28
28
|
|
29
29
|
Add the plugin to your Gemfile:
|
30
30
|
|
31
|
-
gem "oauth-plugin", ">=0.4.0.pre1"
|
31
|
+
gem "oauth-plugin", ">= 0.4.0.pre1"
|
32
32
|
|
33
33
|
And install it:
|
34
34
|
|
@@ -90,7 +90,7 @@ The generator supports the defaults you have created in your application.rb file
|
|
90
90
|
Add the following lines to your user model:
|
91
91
|
|
92
92
|
has_many :client_applications
|
93
|
-
has_many :tokens, :class_name=>"OauthToken"
|
93
|
+
has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
|
94
94
|
|
95
95
|
== OAuth Provider generator (Rails 2)
|
96
96
|
|
@@ -115,7 +115,7 @@ These can of course be used individually as well.
|
|
115
115
|
Add the following lines to your user model:
|
116
116
|
|
117
117
|
has_many :client_applications
|
118
|
-
has_many :tokens, :class_name=>"OauthToken"
|
118
|
+
has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
|
119
119
|
|
120
120
|
=== Migrate database
|
121
121
|
|
@@ -141,13 +141,13 @@ Make it look like this:
|
|
141
141
|
|
142
142
|
class UpgradeOauth < ActiveRecord::Migration
|
143
143
|
def self.up
|
144
|
-
add_column :oauth_tokens
|
145
|
-
add_column :oauth_tokens
|
144
|
+
add_column :oauth_tokens, :callback_url, :string
|
145
|
+
add_column :oauth_tokens, :verifier, :string, :limit => 20
|
146
146
|
end
|
147
147
|
|
148
148
|
def self.down
|
149
|
-
remove_column :oauth_tokens
|
150
|
-
remove_column :oauth_tokens
|
149
|
+
remove_column :oauth_tokens, :callback_url
|
150
|
+
remove_column :oauth_tokens, :verifier
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -168,7 +168,7 @@ Add the following towards the top of the model class
|
|
168
168
|
Then change the create_request_token method to the following:
|
169
169
|
|
170
170
|
def create_request_token
|
171
|
-
RequestToken.create :client_application =>self
|
171
|
+
RequestToken.create :client_application => self, :callback_url => token_callback_url
|
172
172
|
end
|
173
173
|
|
174
174
|
=== Changes in request_token.rb
|
@@ -191,7 +191,7 @@ Make sure it looks like this:
|
|
191
191
|
|
192
192
|
def exchange!
|
193
193
|
return false unless authorized?
|
194
|
-
return false unless oauth10? || verifier==provided_oauth_verifier
|
194
|
+
return false unless oauth10? || verifier == provided_oauth_verifier
|
195
195
|
|
196
196
|
RequestToken.transaction do
|
197
197
|
access_token = AccessToken.create(:user => user, :client_application => client_application)
|
@@ -204,12 +204,12 @@ Make sure it looks like this:
|
|
204
204
|
if oauth10?
|
205
205
|
super
|
206
206
|
else
|
207
|
-
"#{super}&oauth_callback_confirmed=true"
|
207
|
+
"#{super}&oauth_callback_confirmed = true"
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
211
|
def oob?
|
212
|
-
self.callback_url=='oob'
|
212
|
+
self.callback_url == 'oob'
|
213
213
|
end
|
214
214
|
|
215
215
|
def oauth10?
|
@@ -286,8 +286,8 @@ If you want to give oauth access to everything a registered user can do, just re
|
|
286
286
|
|
287
287
|
If you want to restrict consumers to the index and show methods of your controller do the following:
|
288
288
|
|
289
|
-
before_filter :login_required
|
290
|
-
before_filter :login_or_oauth_required
|
289
|
+
before_filter :login_required, :except => [:show,:index]
|
290
|
+
before_filter :login_or_oauth_required, :only => [:show,:index]
|
291
291
|
|
292
292
|
If you have an action you only want used via oauth:
|
293
293
|
|
@@ -330,33 +330,33 @@ All configuration of applications is done in
|
|
330
330
|
|
331
331
|
Add entries to OAUTH_CREDENTIALS for all OAuth Applications you wish to connect to. Get this information by registering your application at the particular applications developer page.
|
332
332
|
|
333
|
-
OAUTH_CREDENTIALS={
|
334
|
-
:twitter=>{
|
335
|
-
:key=>"key",
|
336
|
-
:secret=>"secret",
|
337
|
-
:client
|
333
|
+
OAUTH_CREDENTIALS = {
|
334
|
+
:twitter => {
|
335
|
+
:key => "key",
|
336
|
+
:secret => "secret",
|
337
|
+
:client => :twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
|
338
338
|
:expose => false, # set to true to expose client via the web
|
339
339
|
},
|
340
|
-
:agree2=>{
|
341
|
-
:key=>"key",
|
342
|
-
:secret=>"secret",
|
340
|
+
:agree2 => {
|
341
|
+
:key => "key",
|
342
|
+
:secret => "secret",
|
343
343
|
:expose => false, # set to true to expose client via the web
|
344
344
|
},
|
345
|
-
:hour_feed=>{
|
346
|
-
:key=>"",
|
347
|
-
:secret=>"",
|
348
|
-
:options={
|
349
|
-
:site=>"http://hourfeed.com"
|
345
|
+
:hour_feed => {
|
346
|
+
:key => "",
|
347
|
+
:secret => "",
|
348
|
+
:options = {
|
349
|
+
:site => "http://hourfeed.com"
|
350
350
|
}
|
351
351
|
},
|
352
|
-
:nu_bux=>{
|
353
|
-
:key=>"",
|
354
|
-
:secret=>"",
|
355
|
-
:super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
|
352
|
+
:nu_bux => {
|
353
|
+
:key => "",
|
354
|
+
:secret => "",
|
355
|
+
:super_class => "OpenTransactToken", # if a OAuth service follows a particular standard
|
356
356
|
# with a token implementation you can set the superclass
|
357
357
|
# to use
|
358
|
-
:options=>{
|
359
|
-
:site=>"http://nubux.heroku.com"
|
358
|
+
:options => {
|
359
|
+
:site => "http://nubux.heroku.com"
|
360
360
|
}
|
361
361
|
}
|
362
362
|
}
|
@@ -373,11 +373,11 @@ eg. If you connect to Yahoo's FireEagle you would add the :fire_eagle entry to O
|
|
373
373
|
|
374
374
|
This allows you to add a has_one association in your user model:
|
375
375
|
|
376
|
-
has_one :fire_eagle, :class_name=>"FireEagleToken", :dependent
|
376
|
+
has_one :fire_eagle, :class_name => "FireEagleToken", :dependent => :destroy
|
377
377
|
|
378
378
|
And you could do:
|
379
379
|
|
380
|
-
@location
|
380
|
+
@location = @user.fire_eagle.client.location
|
381
381
|
|
382
382
|
The client method gives you a OAuth::AccessToken which you can use to perform rest operations on the client site - see http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html
|
383
383
|
|
@@ -413,11 +413,11 @@ You can specify this url to the service you're calling when you register, but it
|
|
413
413
|
|
414
414
|
This is designed to let your local javascript apps access remote OAuth apis. You have to specifically enable this by adding the expose flag to your oauth config file. eg:
|
415
415
|
|
416
|
-
OAUTH_CREDENTIALS={
|
417
|
-
:twitter=>{
|
418
|
-
:key=>"key",
|
419
|
-
:secret=>"secret",
|
420
|
-
:client
|
416
|
+
OAUTH_CREDENTIALS = {
|
417
|
+
:twitter => {
|
418
|
+
:key => "key",
|
419
|
+
:secret => "secret",
|
420
|
+
:client => :oauth_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
|
421
421
|
:expose => true # set to true to expose client via the web
|
422
422
|
}
|
423
423
|
|
@@ -3,7 +3,7 @@ class OauthConsumersController < ApplicationController
|
|
3
3
|
include Oauth::Controllers::ConsumerController
|
4
4
|
|
5
5
|
def index
|
6
|
-
@consumer_tokens=ConsumerToken.all :conditions=>{:user_id=>current_user.id}
|
6
|
+
@consumer_tokens=ConsumerToken.all :conditions => {:user_id => current_user.id}
|
7
7
|
@services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
|
8
8
|
end
|
9
9
|
|
@@ -3,66 +3,66 @@
|
|
3
3
|
#
|
4
4
|
# eg. :twitter => TwitterToken, :hour_feed => HourFeedToken etc.
|
5
5
|
#
|
6
|
-
# OAUTH_CREDENTIALS
|
7
|
-
# :twitter=>{
|
8
|
-
# :key=>"",
|
9
|
-
# :secret=>"",
|
10
|
-
# :client
|
6
|
+
# OAUTH_CREDENTIALS => {
|
7
|
+
# :twitter => {
|
8
|
+
# :key => "",
|
9
|
+
# :secret => "",
|
10
|
+
# :client => :twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
|
11
11
|
# :expose => false, # expose client at /oauth_consumers/twitter/client see docs
|
12
12
|
# :allow_login => true # Use :allow_login => true to allow user to login to account
|
13
13
|
# },
|
14
|
-
# :google=>{
|
15
|
-
# :key=>"",
|
16
|
-
# :secret=>"",
|
14
|
+
# :google => {
|
15
|
+
# :key => "",
|
16
|
+
# :secret => "",
|
17
17
|
# :expose => false, # expose client at /oauth_consumers/google/client see docs
|
18
|
-
# :scope=>"" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
|
18
|
+
# :scope => "" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
|
19
19
|
# },
|
20
|
-
# :github=>{
|
20
|
+
# :github => {
|
21
21
|
# :key => "",
|
22
22
|
# :secret => "",
|
23
23
|
# :expose => false, # expose client at /oauth_consumers/twitter/client see docs
|
24
24
|
#
|
25
25
|
# },
|
26
|
-
# :facebook=>{
|
26
|
+
# :facebook => {
|
27
27
|
# :key => "",
|
28
28
|
# :secret => ""
|
29
29
|
# },
|
30
|
-
# :agree2=>{
|
31
|
-
# :key=>"",
|
32
|
-
# :secret=>""
|
30
|
+
# :agree2 => {
|
31
|
+
# :key => "",
|
32
|
+
# :secret => ""
|
33
33
|
# },
|
34
|
-
# :fireeagle=>{
|
35
|
-
# :key=>"",
|
36
|
-
# :secret=>""
|
34
|
+
# :fireeagle => {
|
35
|
+
# :key => "",
|
36
|
+
# :secret => ""
|
37
37
|
# },
|
38
38
|
# :oauth2_server => {
|
39
|
-
# :key=>"",
|
40
|
-
# :secret=>"",
|
39
|
+
# :key => "",
|
40
|
+
# :secret => "",
|
41
41
|
# :oauth_version => 2
|
42
|
-
# :options=>{ # OAuth::Consumer options
|
43
|
-
# :site=>"http://hourfeed.com" # Remember to add a site for a generic OAuth site
|
42
|
+
# :options => { # OAuth::Consumer options
|
43
|
+
# :site => "http://hourfeed.com" # Remember to add a site for a generic OAuth site
|
44
44
|
# }
|
45
45
|
# },
|
46
|
-
# :hour_feed=>{
|
47
|
-
# :key=>"",
|
48
|
-
# :secret=>"",
|
49
|
-
# :options=>{ # OAuth::Consumer options
|
50
|
-
# :site=>"http://hourfeed.com" # Remember to add a site for a generic OAuth site
|
46
|
+
# :hour_feed => {
|
47
|
+
# :key => "",
|
48
|
+
# :secret => "",
|
49
|
+
# :options => { # OAuth::Consumer options
|
50
|
+
# :site => "http://hourfeed.com" # Remember to add a site for a generic OAuth site
|
51
51
|
# }
|
52
52
|
# },
|
53
|
-
# :nu_bux=>{
|
54
|
-
# :key=>"",
|
55
|
-
# :secret=>"",
|
56
|
-
# :super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
|
53
|
+
# :nu_bux => {
|
54
|
+
# :key => "",
|
55
|
+
# :secret => "",
|
56
|
+
# :super_class => "OpenTransactToken", # if a OAuth service follows a particular standard
|
57
57
|
# # with a token implementation you can set the superclass
|
58
58
|
# # to use
|
59
|
-
# :options=>{ # OAuth::Consumer options
|
60
|
-
# :site=>"http://nubux.heroku.com"
|
59
|
+
# :options => { # OAuth::Consumer options
|
60
|
+
# :site => "http://nubux.heroku.com"
|
61
61
|
# }
|
62
62
|
# }
|
63
63
|
# }
|
64
64
|
#
|
65
|
-
OAUTH_CREDENTIALS={
|
65
|
+
OAUTH_CREDENTIALS = {
|
66
66
|
} unless defined? OAUTH_CREDENTIALS
|
67
67
|
|
68
68
|
load 'oauth/models/consumers/service_loader.rb'
|
@@ -15,7 +15,7 @@ class ClientApplicationTest < ActiveSupport::TestCase
|
|
15
15
|
fixtures :users,:client_applications,:oauth_tokens
|
16
16
|
|
17
17
|
def setup
|
18
|
-
@application = ClientApplication.create :name=>"Agree2"
|
18
|
+
@application = ClientApplication.create :name => "Agree2", :url => "http://agree2.com", :user => users(:quentin)
|
19
19
|
create_consumer
|
20
20
|
end
|
21
21
|
|
@@ -50,7 +50,7 @@ describe OauthClientsController do
|
|
50
50
|
|
51
51
|
it "should assign client_applications" do
|
52
52
|
do_get
|
53
|
-
assigns[:client_application].should==current_client_application
|
53
|
+
assigns[:client_application].should == current_client_application
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should render show template" do
|
@@ -73,7 +73,7 @@ describe OauthClientsController do
|
|
73
73
|
|
74
74
|
it "should assign client_applications" do
|
75
75
|
do_get
|
76
|
-
assigns[:client_application].class.should==ClientApplication
|
76
|
+
assigns[:client_application].class.should == ClientApplication
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should render show template" do
|
@@ -95,7 +95,7 @@ describe OauthClientsController do
|
|
95
95
|
|
96
96
|
it "should assign client_applications" do
|
97
97
|
do_get
|
98
|
-
assigns[:client_application].should==current_client_application
|
98
|
+
assigns[:client_application].should == current_client_application
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should render edit template" do
|
@@ -108,7 +108,7 @@ describe OauthClientsController do
|
|
108
108
|
describe "create" do
|
109
109
|
|
110
110
|
def do_valid_post
|
111
|
-
post :create, 'client_application'=>{'name' => 'my site', :url=>"http://test.com"}
|
111
|
+
post :create, 'client_application' => {'name' => 'my site', :url => "http://test.com"}
|
112
112
|
@client_application = ClientApplication.last
|
113
113
|
end
|
114
114
|
|
@@ -150,11 +150,11 @@ describe OauthClientsController do
|
|
150
150
|
describe "update" do
|
151
151
|
|
152
152
|
def do_valid_update
|
153
|
-
put :update, :id => '1', 'client_application'=>{'name' => 'updated site'}
|
153
|
+
put :update, :id => '1', 'client_application' => {'name' => 'updated site'}
|
154
154
|
end
|
155
155
|
|
156
156
|
def do_invalid_update
|
157
|
-
put :update, :id => '1', 'client_application'=>{'name' => nil}
|
157
|
+
put :update, :id => '1', 'client_application' => {'name' => nil}
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should redirect to show client_application" do
|
@@ -54,7 +54,7 @@ class OauthClientsControllerShowTest < ActionController::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def do_get
|
57
|
-
get :show, :id=>'3'
|
57
|
+
get :show, :id => '3'
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_should_be_successful
|
@@ -169,12 +169,12 @@ class OauthClientsControllerCreateTest < ActionController::TestCase
|
|
169
169
|
|
170
170
|
def do_valid_post
|
171
171
|
@client_application.expects(:save).returns(true)
|
172
|
-
post :create,'client_application'=>{'name'=>'my site'}
|
172
|
+
post :create,'client_application' => {'name' => 'my site'}
|
173
173
|
end
|
174
174
|
|
175
175
|
def do_invalid_post
|
176
176
|
@client_application.expects(:save).returns(false)
|
177
|
-
post :create,:client_application=>{:name=>'my site'}
|
177
|
+
post :create,:client_application=>{:name => 'my site'}
|
178
178
|
end
|
179
179
|
|
180
180
|
def test_should_query_current_users_client_applications
|
@@ -248,12 +248,12 @@ class OauthClientsControllerUpdateTest < ActionController::TestCase
|
|
248
248
|
|
249
249
|
def do_valid_update
|
250
250
|
@client_application.expects(:update_attributes).returns(true)
|
251
|
-
put :update, :id => '1', 'client_application' => {'name'=>'my site'}
|
251
|
+
put :update, :id => '1', 'client_application' => {'name' => 'my site'}
|
252
252
|
end
|
253
253
|
|
254
254
|
def do_invalid_update
|
255
255
|
@client_application.expects(:update_attributes).returns(false)
|
256
|
-
put :update, :id=>'1', 'client_application' => {'name'=>'my site'}
|
256
|
+
put :update, :id=>'1', 'client_application' => {'name' => 'my site'}
|
257
257
|
end
|
258
258
|
|
259
259
|
def test_should_query_current_users_client_applications
|
@@ -5,6 +5,8 @@ module Erb
|
|
5
5
|
class OauthProviderGenerator < Erb::Generators::Base
|
6
6
|
source_root File.expand_path('../oauth_provider_templates', __FILE__)
|
7
7
|
|
8
|
+
argument :name, :type => :string, :default => 'Oauth'
|
9
|
+
|
8
10
|
def copy_view_files
|
9
11
|
template '_form.html.erb', File.join('app/views', class_path, 'oauth_clients', '_form.html.erb')
|
10
12
|
template 'new.html.erb', File.join('app/views', class_path, 'oauth_clients', 'new.html.erb')
|
@@ -34,14 +34,4 @@ class OauthProviderGenerator < Rails::Generators::NamedBase
|
|
34
34
|
|
35
35
|
route "resources :#{file_name}_clients"
|
36
36
|
end
|
37
|
-
def add_routes
|
38
|
-
route "match '/oauth', :to => 'oauth#index', :as => :oauth"
|
39
|
-
route "match '/oauth/authorize', :to => 'oauth#authorize', :as => :authorize"
|
40
|
-
route "match '/oauth/request_token', :to => 'oauth#request_token', :as => :request_token"
|
41
|
-
route "match '/oauth/access_token', :to => 'oauth#access_token', :as => :access_token"
|
42
|
-
route "match '/oauth/token', :to => 'oauth#token', :as => :token"
|
43
|
-
route "match '/oauth/test_request', :to => 'oauth#test_request', :as => :test_request"
|
44
|
-
|
45
|
-
route "resources :#{file_name}_clients"
|
46
|
-
end
|
47
37
|
end
|
data/lib/oauth-plugin/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module OAuth
|
2
2
|
module Controllers
|
3
|
-
|
3
|
+
|
4
4
|
module ProviderController
|
5
5
|
def self.included(controller)
|
6
6
|
controller.class_eval do
|
@@ -12,7 +12,7 @@ module OAuth
|
|
12
12
|
skip_before_filter :verify_authenticity_token, :only=>[:request_token, :access_token, :invalidate, :test_request]
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def request_token
|
17
17
|
@token = current_client_application.create_request_token params
|
18
18
|
if @token
|
@@ -20,7 +20,7 @@ module OAuth
|
|
20
20
|
else
|
21
21
|
render :nothing => true, :status => 401
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
24
24
|
|
25
25
|
def access_token
|
26
26
|
@token = current_token && current_token.exchange!
|
@@ -32,14 +32,14 @@ module OAuth
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def token
|
35
|
-
@client_application = ClientApplication.find_by_key params[:client_id]
|
35
|
+
@client_application = ClientApplication.find_by_key! params[:client_id]
|
36
36
|
if @client_application.secret != params[:client_secret]
|
37
37
|
oauth2_error "invalid_client"
|
38
38
|
return
|
39
39
|
end
|
40
40
|
if ["authorization_code","password","none"].include?(params[:grant_type])
|
41
41
|
send "oauth2_token_#{params[:grant_type].underscore}"
|
42
|
-
else
|
42
|
+
else
|
43
43
|
oauth2_error "unsupported_grant_type"
|
44
44
|
end
|
45
45
|
end
|
@@ -50,28 +50,30 @@ module OAuth
|
|
50
50
|
|
51
51
|
def authorize
|
52
52
|
if params[:oauth_token]
|
53
|
-
@token = ::RequestToken.find_by_token params[:oauth_token]
|
53
|
+
@token = ::RequestToken.find_by_token! params[:oauth_token]
|
54
54
|
oauth1_authorize
|
55
55
|
elsif ["code","token"].include?(params[:response_type]) # pick flow
|
56
56
|
send "oauth2_authorize_#{params[:response_type]}"
|
57
|
+
else
|
58
|
+
render :status=>404, :text=>"No token provided"
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
62
|
def revoke
|
61
|
-
@token = current_user.tokens.find_by_token params[:token]
|
63
|
+
@token = current_user.tokens.find_by_token! params[:token]
|
62
64
|
if @token
|
63
65
|
@token.invalidate!
|
64
66
|
flash[:notice] = "You've revoked the token for #{@token.client_application.name}"
|
65
67
|
end
|
66
68
|
redirect_to oauth_clients_url
|
67
69
|
end
|
68
|
-
|
70
|
+
|
69
71
|
# Invalidate current token
|
70
72
|
def invalidate
|
71
73
|
current_token.invalidate!
|
72
74
|
head :status=>410
|
73
75
|
end
|
74
|
-
|
76
|
+
|
75
77
|
# Capabilities of current_token
|
76
78
|
def capabilities
|
77
79
|
if current_token.respond_to?(:capabilities)
|
@@ -79,7 +81,7 @@ module OAuth
|
|
79
81
|
else
|
80
82
|
@capabilities={:invalidate=>url_for(:action=>:invalidate)}
|
81
83
|
end
|
82
|
-
|
84
|
+
|
83
85
|
respond_to do |format|
|
84
86
|
format.json {render :json=>@capabilities}
|
85
87
|
format.xml {render :xml=>@capabilities}
|
@@ -87,15 +89,15 @@ module OAuth
|
|
87
89
|
end
|
88
90
|
|
89
91
|
protected
|
90
|
-
|
92
|
+
|
91
93
|
def oauth1_authorize
|
92
94
|
unless @token
|
93
95
|
render :action=>"authorize_failure"
|
94
96
|
return
|
95
97
|
end
|
96
98
|
|
97
|
-
unless @token.invalidated?
|
98
|
-
if request.post?
|
99
|
+
unless @token.invalidated?
|
100
|
+
if request.post?
|
99
101
|
if user_authorizes_token?
|
100
102
|
@token.authorize!(current_user)
|
101
103
|
@redirect_url = URI.parse(@token.oob? ? @token.client_application.callback_url : @token.callback_url)
|
@@ -186,7 +188,7 @@ module OAuth
|
|
186
188
|
return
|
187
189
|
end
|
188
190
|
@token = @verification_code.exchange!
|
189
|
-
render :json=>@token
|
191
|
+
render :json=>@token
|
190
192
|
end
|
191
193
|
|
192
194
|
# http://tools.ietf.org/html/draft-ietf-oauth-v2-08#section-4.1.2
|
@@ -197,9 +199,9 @@ module OAuth
|
|
197
199
|
return
|
198
200
|
end
|
199
201
|
@token = Oauth2Token.create :client_application=>@client_application, :user=>@user, :scope=>params[:scope]
|
200
|
-
render :json=>@token
|
202
|
+
render :json=>@token
|
201
203
|
end
|
202
|
-
|
204
|
+
|
203
205
|
# should authenticate and return a user if valid password. Override in your own controller
|
204
206
|
def authenticate_user(username,password)
|
205
207
|
User.authenticate(username,password)
|
@@ -208,13 +210,13 @@ module OAuth
|
|
208
210
|
# autonomous authorization which creates a token for client_applications user
|
209
211
|
def oauth2_token_none
|
210
212
|
@token = Oauth2Token.create :client_application=>@client_application, :user=>@client_application.user, :scope=>params[:scope]
|
211
|
-
render :json=>@token
|
213
|
+
render :json=>@token
|
212
214
|
end
|
213
215
|
|
214
216
|
# Override this to match your authorization page form
|
215
217
|
def user_authorizes_token?
|
216
218
|
params[:authorize] == '1'
|
217
|
-
end
|
219
|
+
end
|
218
220
|
|
219
221
|
def oauth2_error(error="invalid_grant")
|
220
222
|
render :json=>{:error=>error}.to_json
|
data/oauth-plugin.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
10
10
|
s.authors = ["Pelle Braendgaard"]
|
11
|
-
s.date = %q{
|
11
|
+
s.date = %q{2011-06-28}
|
12
12
|
s.description = %q{Rails plugin for implementing an OAuth Provider or Consumer}
|
13
13
|
s.email = %q{oauth-ruby@googlegroups.com}
|
14
14
|
s.extra_rdoc_files = [
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
|
20
|
+
|
21
21
|
s.homepage = %q{http://github.com/pelle/oauth-plugin}
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
s.rubyforge_project = %q{oauth}
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_development_dependency "guard-rspec"
|
31
31
|
s.add_development_dependency "growl"
|
32
32
|
s.add_development_dependency "rack-test"
|
33
|
-
|
33
|
+
|
34
34
|
s.add_dependency "multi_json"
|
35
35
|
s.add_dependency("oauth", ["~> 0.4.4"])
|
36
36
|
s.add_dependency("rack")
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: oauth-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 0.4.0.
|
5
|
+
version: 0.4.0.pre6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pelle Braendgaard
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
14
|
-
default_executable:
|
13
|
+
date: 2011-06-28 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: opentransact
|
@@ -306,7 +305,6 @@ files:
|
|
306
305
|
- spec/spec_helper.rb
|
307
306
|
- tasks/oauth_tasks.rake
|
308
307
|
- uninstall.rb
|
309
|
-
has_rdoc: true
|
310
308
|
homepage: http://github.com/pelle/oauth-plugin
|
311
309
|
licenses: []
|
312
310
|
|
@@ -330,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
328
|
requirements: []
|
331
329
|
|
332
330
|
rubyforge_project: oauth
|
333
|
-
rubygems_version: 1.
|
331
|
+
rubygems_version: 1.8.5
|
334
332
|
signing_key:
|
335
333
|
specification_version: 3
|
336
334
|
summary: Ruby on Rails Plugin for OAuth Provider and Consumer
|