oauth-plugin 0.3.14 → 0.4.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.rdoc +44 -9
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/generators/oauth_consumer/templates/migration.rb +1 -1
- data/generators/oauth_provider/oauth_provider_generator.rb +6 -0
- data/generators/oauth_provider/templates/access_token.rb +2 -2
- data/generators/oauth_provider/templates/client_application.rb +8 -6
- data/generators/oauth_provider/templates/client_applications.yml +6 -6
- data/generators/oauth_provider/templates/clients_controller_spec.rb +130 -193
- data/generators/oauth_provider/templates/controller.rb +12 -0
- data/generators/oauth_provider/templates/controller_spec.rb +762 -291
- data/generators/oauth_provider/templates/controller_spec_helper.rb +49 -63
- data/generators/oauth_provider/templates/migration.rb +6 -5
- data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
- data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
- data/generators/oauth_provider/templates/oauth2_token.rb +6 -0
- data/generators/oauth_provider/templates/oauth2_token_spec.rb +29 -0
- data/generators/oauth_provider/templates/oauth2_verifier.rb +28 -0
- data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +54 -0
- data/generators/oauth_provider/templates/oauth_nonce_test.rb +1 -1
- data/generators/oauth_provider/templates/oauth_token.rb +3 -4
- data/generators/oauth_provider/templates/request_token.rb +1 -1
- data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
- data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +5 -0
- data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
- data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
- data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
- data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
- data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +5 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +28 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
- data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
- data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
- data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
- data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
- data/lib/generators/erb/oauth_provider_generator.rb +21 -0
- data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
- data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
- data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
- data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
- data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
- data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
- data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
- data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
- data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
- data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
- data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
- data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
- data/lib/generators/haml/oauth_provider_generator.rb +28 -0
- data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
- data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
- data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
- data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
- data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
- data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
- data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
- data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
- data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
- data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
- data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +14 -0
- data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
- data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
- data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +5 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +25 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
- data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
- data/lib/generators/oauth_consumer/USAGE +8 -0
- data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +27 -0
- data/lib/generators/oauth_consumer/templates/controller.rb +19 -0
- data/lib/generators/oauth_consumer/templates/oauth_config.rb +46 -0
- data/lib/generators/oauth_inflections.rb +6 -0
- data/lib/generators/oauth_plugin.rb +0 -0
- data/lib/generators/oauth_provider/USAGE +18 -0
- data/lib/generators/oauth_provider/oauth_provider_generator.rb +47 -0
- data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
- data/lib/generators/oauth_provider/templates/controller.rb +23 -0
- data/lib/generators/rspec/oauth_provider_generator.rb +39 -0
- data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
- data/lib/generators/rspec/templates/client_applications.yml +23 -0
- data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
- data/lib/generators/rspec/templates/controller_spec.rb +838 -0
- data/lib/generators/rspec/templates/controller_spec_helper.rb +66 -0
- data/lib/generators/rspec/templates/oauth2_token_spec.rb +29 -0
- data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +54 -0
- data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
- data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
- data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
- data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
- data/lib/generators/test_unit/oauth_provider_generator.rb +37 -0
- data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
- data/lib/generators/test_unit/templates/client_applications.yml +23 -0
- data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
- data/lib/generators/test_unit/templates/controller_test.rb +310 -0
- data/lib/generators/test_unit/templates/controller_test_helper.rb +115 -0
- data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
- data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
- data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
- data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
- data/lib/oauth/controllers/application_controller_methods.rb +169 -66
- data/lib/oauth/controllers/provider_controller.rb +154 -38
- data/lib/oauth/models/consumers/service_loader.rb +2 -0
- data/lib/oauth/models/consumers/token.rb +0 -1
- data/oauth-plugin.gemspec +97 -10
- data/rails/init.rb +6 -2
- metadata +119 -12
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
0.4.0
|
2
|
+
- mongoid support in rails 3 [Alexander Semyonov]
|
3
|
+
- OAUTH 2.0 authorization_code and password grant types
|
4
|
+
- Supports OAuth 2.0 draft 10 (Note this is incompatible with previous drafts)
|
5
|
+
- Refactored application_controller_methods to be a lot less intrusive
|
6
|
+
- Increased default token and key size in anticipation of OAuth2 support
|
7
|
+
- Rails 3 support
|
8
|
+
- Rails 3 generators [Paul Rosiana] and patches by [Alexander Flatter]
|
9
|
+
- Modularized Rails 3 generators [Alexander Semyonov]
|
10
|
+
- Callback urls now allow query parameters. Multiple patches but I used [Unk]'s.
|
1
11
|
10/08/2009
|
2
12
|
0.3.14
|
3
13
|
- Fixed the class generation when you have a custom token defined. [Brian Morearty]
|
data/README.rdoc
CHANGED
@@ -6,6 +6,10 @@ We support the revised OAuth 1.0a specs at:
|
|
6
6
|
|
7
7
|
http://oauth.net/core/1.0a
|
8
8
|
|
9
|
+
As well as support for OAuth 2.0:
|
10
|
+
|
11
|
+
http://tools.ietf.org/html/draft-ietf-oauth-v2-10
|
12
|
+
|
9
13
|
and the OAuth site at:
|
10
14
|
|
11
15
|
http://oauth.net
|
@@ -16,7 +20,7 @@ http://mojodna.net/2009/05/20/an-idiots-guide-to-oauth-10a.html
|
|
16
20
|
|
17
21
|
== Requirements
|
18
22
|
|
19
|
-
You need to install the oauth gem (0.
|
23
|
+
You need to install the oauth gem (0.4.1) which is the core OAuth ruby library. It will NOT work on any previous version of the gem.
|
20
24
|
|
21
25
|
sudo gem install oauth
|
22
26
|
|
@@ -35,7 +39,7 @@ Alternatively you can install it in vendors/plugin:
|
|
35
39
|
|
36
40
|
script/plugin install git://github.com/pelle/oauth-plugin.git
|
37
41
|
|
38
|
-
The Generator currently creates code (in particular views) that only work in Rails 2.
|
42
|
+
The Generator currently creates code (in particular views) that only work in Rails 2 and 3.
|
39
43
|
|
40
44
|
It should not be difficult to manually modify the code to work on Rails 1.2.x
|
41
45
|
|
@@ -43,7 +47,34 @@ I think the only real issue is that the views have .html.erb extensions. So thes
|
|
43
47
|
|
44
48
|
Please let me know if this works and I will see if I can make the generator conditionally create .rhtml for pre 2.0 versions of RAILS.
|
45
49
|
|
46
|
-
== OAuth Provider generator
|
50
|
+
== OAuth Provider generator (Rails 3)
|
51
|
+
|
52
|
+
This currently supports rspec, test_unit, haml, erb, active_record and mongoid:
|
53
|
+
|
54
|
+
rails g oauth_provider
|
55
|
+
|
56
|
+
This generates OAuth and OAuth client controllers as well as the required models.
|
57
|
+
|
58
|
+
It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.
|
59
|
+
|
60
|
+
=== Generator Options
|
61
|
+
|
62
|
+
The generator supports the defaults you have created in your application.rb file. eg:
|
63
|
+
|
64
|
+
config.generators do |g|
|
65
|
+
g.orm :mongoid
|
66
|
+
g.template_engine :haml
|
67
|
+
g.test_framework :rspec
|
68
|
+
end
|
69
|
+
|
70
|
+
=== User Model
|
71
|
+
|
72
|
+
Add the following lines to your user model:
|
73
|
+
|
74
|
+
has_many :client_applications
|
75
|
+
has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
|
76
|
+
|
77
|
+
== OAuth Provider generator (Rails 2)
|
47
78
|
|
48
79
|
While it isn't very flexible at the moment there is an oauth_provider generator which you can use like this:
|
49
80
|
|
@@ -255,18 +286,24 @@ You could add application specific information to the OauthToken and ClientAppli
|
|
255
286
|
|
256
287
|
The oauth_consumer generator creates a controller to manage the authentication flow between your application and any number of external OAuth secured applications that you wish to connect to.
|
257
288
|
|
258
|
-
To run it simply run:
|
289
|
+
To run it in Rails 3 simply run:
|
290
|
+
|
291
|
+
rails g oauth_consumer
|
292
|
+
|
293
|
+
In previous versions:
|
259
294
|
|
260
295
|
./script/generate oauth_consumer
|
261
296
|
|
262
297
|
This generates the OauthConsumerController as well as the ConsumerToken model.
|
263
298
|
|
264
|
-
=== Generator Options
|
299
|
+
=== Generator Options (Rails 2)
|
265
300
|
|
266
301
|
By default the generator generates ERB templates. The generator can instead create HAML templates. To do this use the following options:
|
267
302
|
|
268
303
|
./script/generate oauth_consumer --haml
|
269
304
|
|
305
|
+
Rails 3 respects your application defaults, see the oauth provider generator section above for more info.
|
306
|
+
|
270
307
|
=== Configuration
|
271
308
|
|
272
309
|
All configuration of applications is done in
|
@@ -315,7 +352,7 @@ eg. If you connect to Yahoo's FireEagle you would add the :fire_eagle entry to O
|
|
315
352
|
|
316
353
|
This allows you to add a has_one association in your user model:
|
317
354
|
|
318
|
-
has_one :fire_eagle
|
355
|
+
has_one :fire_eagle, :class_name=>"FireEagleToken", :dependent=>:destroy
|
319
356
|
|
320
357
|
And you could do:
|
321
358
|
|
@@ -359,8 +396,6 @@ Run them as any other normal migration in rails with:
|
|
359
396
|
|
360
397
|
== More
|
361
398
|
|
362
|
-
The Google Code project is http://code.google.com/p/oauth-plugin/
|
363
|
-
|
364
399
|
The Mailing List for all things OAuth in Ruby is:
|
365
400
|
|
366
401
|
http://groups.google.com/group/oauth-ruby
|
@@ -373,4 +408,4 @@ The OAuth Ruby Gem home page is http://oauth.rubyforge.org
|
|
373
408
|
|
374
409
|
Please help documentation, patches and testing.
|
375
410
|
|
376
|
-
Copyright (c) 2007-
|
411
|
+
Copyright (c) 2007-2010 Pelle Braendgaard and contributors, released under the MIT license
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ end
|
|
15
15
|
desc 'Generate documentation for the oauth plugin.'
|
16
16
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
17
|
rdoc.rdoc_dir = 'rdoc'
|
18
|
-
rdoc.title = '
|
18
|
+
rdoc.title = 'OAuth Plugin'
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
20
20
|
rdoc.rdoc_files.include('README')
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
@@ -30,7 +30,7 @@ begin
|
|
30
30
|
gemspec.email = "oauth-ruby@googlegroups.com"
|
31
31
|
gemspec.homepage = "http://github.com/pelle/oauth-plugin"
|
32
32
|
gemspec.authors = ["Pelle Braendgaard"]
|
33
|
-
gemspec.add_dependency('oauth', '>= 0.
|
33
|
+
gemspec.add_dependency('oauth', '>= 0.4.4')
|
34
34
|
gemspec.rubyforge_project = 'oauth'
|
35
35
|
end
|
36
36
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0.pre1
|
@@ -43,6 +43,8 @@ class OauthProviderGenerator < Rails::Generator::Base
|
|
43
43
|
m.template 'oauth_token.rb', File.join('app/models',"oauth_token.rb")
|
44
44
|
m.template 'request_token.rb', File.join('app/models',"request_token.rb")
|
45
45
|
m.template 'access_token.rb', File.join('app/models',"access_token.rb")
|
46
|
+
m.template 'oauth2_token.rb', File.join('app/models',"oauth2_token.rb")
|
47
|
+
m.template 'oauth2_verifier.rb', File.join('app/models',"oauth2_verifier.rb")
|
46
48
|
m.template 'oauth_nonce.rb', File.join('app/models',"oauth_nonce.rb")
|
47
49
|
|
48
50
|
m.template 'controller.rb',File.join('app/controllers',controller_class_path,"#{controller_file_name}_controller.rb")
|
@@ -52,6 +54,7 @@ class OauthProviderGenerator < Rails::Generator::Base
|
|
52
54
|
m.route_name 'authorize', '/oauth/authorize',:controller=>'oauth',:action=>'authorize'
|
53
55
|
m.route_name 'request_token', '/oauth/request_token',:controller=>'oauth',:action=>'request_token'
|
54
56
|
m.route_name 'access_token', '/oauth/access_token',:controller=>'oauth',:action=>'access_token'
|
57
|
+
m.route_name 'token', '/oauth/token',:controller=>'oauth',:action=>'token'
|
55
58
|
m.route_name 'test_request', '/oauth/test_request',:controller=>'oauth',:action=>'test_request'
|
56
59
|
|
57
60
|
m.route_resources "#{controller_file_name}_clients".to_sym
|
@@ -64,6 +67,8 @@ class OauthProviderGenerator < Rails::Generator::Base
|
|
64
67
|
|
65
68
|
m.template 'client_application_spec.rb',File.join('spec/models',"client_application_spec.rb")
|
66
69
|
m.template 'oauth_token_spec.rb', File.join('spec/models',"oauth_token_spec.rb")
|
70
|
+
m.template 'oauth2_token_spec.rb', File.join('spec/models',"oauth2_token_spec.rb")
|
71
|
+
m.template 'oauth2_verifier_spec.rb', File.join('spec/models',"oauth2_verifier_spec.rb")
|
67
72
|
m.template 'oauth_nonce_spec.rb', File.join('spec/models',"oauth_nonce_spec.rb")
|
68
73
|
m.template 'client_applications.yml',File.join('spec/fixtures',"client_applications.yml")
|
69
74
|
m.template 'oauth_tokens.yml', File.join('spec/fixtures',"oauth_tokens.yml")
|
@@ -96,6 +101,7 @@ class OauthProviderGenerator < Rails::Generator::Base
|
|
96
101
|
m.template "show.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "show.html.#{@template_extension}")
|
97
102
|
m.template "edit.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "edit.html.#{@template_extension}")
|
98
103
|
m.template "authorize.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize.html.#{@template_extension}")
|
104
|
+
m.template "oauth2_authorize.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "oauth2_authorize.html.#{@template_extension}")
|
99
105
|
m.template "authorize_success.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_success.html.#{@template_extension}")
|
100
106
|
m.template "authorize_failure.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_failure.html.#{@template_extension}")
|
101
107
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class AccessToken < OauthToken
|
2
|
-
validates_presence_of :user
|
2
|
+
validates_presence_of :user, :secret
|
3
3
|
before_create :set_authorized_at
|
4
4
|
|
5
5
|
# Implement this to return a hash or array of the capabilities the access token has
|
@@ -13,4 +13,4 @@ class AccessToken < OauthToken
|
|
13
13
|
def set_authorized_at
|
14
14
|
self.authorized_at = Time.now
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
@@ -2,6 +2,9 @@ require 'oauth'
|
|
2
2
|
class ClientApplication < ActiveRecord::Base
|
3
3
|
belongs_to :user
|
4
4
|
has_many :tokens, :class_name => "OauthToken"
|
5
|
+
has_many :access_tokens
|
6
|
+
has_many :oauth2_verifiers
|
7
|
+
has_many :oauth_tokens
|
5
8
|
validates_presence_of :name, :url, :key, :secret
|
6
9
|
validates_uniqueness_of :key
|
7
10
|
before_validation_on_create :generate_keys
|
@@ -28,7 +31,6 @@ class ClientApplication < ActiveRecord::Base
|
|
28
31
|
value = signature.verify
|
29
32
|
value
|
30
33
|
rescue OAuth::Signature::UnknownSignatureMethod => e
|
31
|
-
logger.info "ERROR"+e.to_s
|
32
34
|
false
|
33
35
|
end
|
34
36
|
end
|
@@ -41,15 +43,15 @@ class ClientApplication < ActiveRecord::Base
|
|
41
43
|
@oauth_client ||= OAuth::Consumer.new(key, secret)
|
42
44
|
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
# If your application requires passing in extra parameters handle it here
|
47
|
+
def create_request_token(params={})
|
48
|
+
RequestToken.create :client_application => self, :callback_url=>self.token_callback_url
|
46
49
|
end
|
47
50
|
|
48
51
|
protected
|
49
52
|
|
50
53
|
def generate_keys
|
51
|
-
|
52
|
-
self.
|
53
|
-
self.secret = oauth_client.secret[0,40]
|
54
|
+
self.key = OAuth::Helper.generate_key(40)[0,40]
|
55
|
+
self.secret = OAuth::Helper.generate_key(40)[0,40]
|
54
56
|
end
|
55
57
|
end
|
@@ -2,9 +2,9 @@
|
|
2
2
|
one:
|
3
3
|
id: 1
|
4
4
|
name: MyString
|
5
|
-
url:
|
6
|
-
support_url:
|
7
|
-
callback_url:
|
5
|
+
url: http://test.com
|
6
|
+
support_url: http://test.com/support
|
7
|
+
callback_url: http://test.com/callback
|
8
8
|
key: one_key
|
9
9
|
secret: MyString
|
10
10
|
user_id: 1
|
@@ -13,9 +13,9 @@ one:
|
|
13
13
|
two:
|
14
14
|
id: 2
|
15
15
|
name: MyString
|
16
|
-
url:
|
17
|
-
support_url:
|
18
|
-
callback_url:
|
16
|
+
url: http://test.com
|
17
|
+
support_url: http://test.com/support
|
18
|
+
callback_url: http://test.com/callback
|
19
19
|
key: two_key
|
20
20
|
secret: MyString
|
21
21
|
user_id: 1
|
@@ -2,238 +2,175 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
require File.dirname(__FILE__) + '/oauth_controller_spec_helper'
|
3
3
|
require 'oauth/client/action_controller_request'
|
4
4
|
|
5
|
-
describe OauthClientsController
|
5
|
+
describe OauthClientsController do
|
6
|
+
if defined?(Devise)
|
7
|
+
include Devise::TestHelpers
|
8
|
+
end
|
6
9
|
include OAuthControllerSpecHelper
|
10
|
+
fixtures :client_applications, :oauth_tokens, :users
|
7
11
|
before(:each) do
|
8
12
|
login_as_application_owner
|
9
13
|
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
do_get
|
17
|
-
|
18
|
-
|
15
|
+
describe "index" do
|
16
|
+
before do
|
17
|
+
@client_applications = @user.client_applications
|
18
|
+
end
|
19
|
+
|
20
|
+
def do_get
|
21
|
+
get :index
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
it "should be successful" do
|
25
|
+
do_get
|
26
|
+
response.should be_success
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
it "should assign client_applications" do
|
30
|
+
do_get
|
31
|
+
assigns[:client_applications].should==@client_applications
|
32
|
+
end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
it "should render index template" do
|
35
|
+
do_get
|
36
|
+
response.should render_template('index')
|
37
|
+
end
|
33
38
|
end
|
34
|
-
end
|
35
39
|
|
36
|
-
describe
|
37
|
-
include OAuthControllerSpecHelper
|
38
|
-
before(:each) do
|
39
|
-
login_as_application_owner
|
40
|
-
end
|
41
|
-
|
42
|
-
def do_get
|
43
|
-
get :show, :id => '3'
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should be successful" do
|
47
|
-
do_get
|
48
|
-
response.should be_success
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should query current_users client applications" do
|
52
|
-
@user.should_receive(:client_applications).and_return(@client_applications)
|
53
|
-
@client_applications.should_receive(:find).with('3').and_return(@client_application)
|
54
|
-
do_get
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should assign client_applications" do
|
58
|
-
do_get
|
59
|
-
assigns[:client_application].should equal(@client_application)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should render show template" do
|
63
|
-
do_get
|
64
|
-
response.should render_template('show')
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
40
|
+
describe "show" do
|
68
41
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
login_as_application_owner
|
73
|
-
ClientApplication.stub!(:new).and_return(@client_application)
|
74
|
-
end
|
42
|
+
def do_get
|
43
|
+
get :show, :id => '1'
|
44
|
+
end
|
75
45
|
|
76
|
-
|
77
|
-
|
78
|
-
|
46
|
+
it "should be successful" do
|
47
|
+
do_get
|
48
|
+
response.should be_success
|
49
|
+
end
|
79
50
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
51
|
+
it "should assign client_applications" do
|
52
|
+
do_get
|
53
|
+
assigns[:client_application].should==current_client_application
|
54
|
+
end
|
84
55
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
56
|
+
it "should render show template" do
|
57
|
+
do_get
|
58
|
+
response.should render_template('show')
|
59
|
+
end
|
89
60
|
|
90
|
-
it "should render show template" do
|
91
|
-
do_get
|
92
|
-
response.should render_template('new')
|
93
61
|
end
|
94
|
-
|
95
|
-
end
|
96
62
|
|
97
|
-
describe
|
98
|
-
include OAuthControllerSpecHelper
|
99
|
-
before(:each) do
|
100
|
-
login_as_application_owner
|
101
|
-
end
|
102
|
-
|
103
|
-
def do_get
|
104
|
-
get :edit, :id => '3'
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should be successful" do
|
108
|
-
do_get
|
109
|
-
response.should be_success
|
110
|
-
end
|
63
|
+
describe "new" do
|
111
64
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
do_get
|
116
|
-
end
|
65
|
+
def do_get
|
66
|
+
get :new
|
67
|
+
end
|
117
68
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
69
|
+
it "should be successful" do
|
70
|
+
do_get
|
71
|
+
response.should be_success
|
72
|
+
end
|
122
73
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
describe OauthClientsController, "create" do
|
131
|
-
include OAuthControllerSpecHelper
|
74
|
+
it "should assign client_applications" do
|
75
|
+
do_get
|
76
|
+
assigns[:client_application].class.should==ClientApplication
|
77
|
+
end
|
132
78
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
79
|
+
it "should render show template" do
|
80
|
+
do_get
|
81
|
+
response.should render_template('new')
|
82
|
+
end
|
138
83
|
|
139
|
-
def do_valid_post
|
140
|
-
@client_application.should_receive(:save).and_return(true)
|
141
|
-
post :create, 'client_application'=>{'name' => 'my site'}
|
142
84
|
end
|
143
85
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
86
|
+
describe "edit" do
|
87
|
+
def do_get
|
88
|
+
get :edit, :id => '1'
|
89
|
+
end
|
148
90
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
91
|
+
it "should be successful" do
|
92
|
+
do_get
|
93
|
+
response.should be_success
|
94
|
+
end
|
153
95
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
96
|
+
it "should assign client_applications" do
|
97
|
+
do_get
|
98
|
+
assigns[:client_application].should==current_client_application
|
99
|
+
end
|
159
100
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
101
|
+
it "should render edit template" do
|
102
|
+
do_get
|
103
|
+
response.should render_template('edit')
|
104
|
+
end
|
164
105
|
|
165
|
-
it "should render show template" do
|
166
|
-
do_invalid_post
|
167
|
-
response.should render_template('new')
|
168
106
|
end
|
169
|
-
end
|
170
107
|
|
171
|
-
describe
|
172
|
-
include OAuthControllerSpecHelper
|
173
|
-
before(:each) do
|
174
|
-
login_as_application_owner
|
175
|
-
@client_application.stub!(:destroy)
|
176
|
-
end
|
177
|
-
|
178
|
-
def do_delete
|
179
|
-
delete :destroy, :id => '3'
|
180
|
-
end
|
108
|
+
describe "create" do
|
181
109
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
110
|
+
def do_valid_post
|
111
|
+
post :create, 'client_application'=>{'name' => 'my site', :url=>"http://test.com"}
|
112
|
+
@client_application = ClientApplication.last
|
113
|
+
end
|
187
114
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
end
|
115
|
+
def do_invalid_post
|
116
|
+
post :create
|
117
|
+
end
|
192
118
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
describe OauthClientsController, "update" do
|
202
|
-
include OAuthControllerSpecHelper
|
203
|
-
|
204
|
-
before(:each) do
|
205
|
-
login_as_application_owner
|
206
|
-
end
|
119
|
+
it "should redirect to new client_application" do
|
120
|
+
do_valid_post
|
121
|
+
response.should be_redirect
|
122
|
+
response.should redirect_to(:action => "show", :id => @client_application.id)
|
123
|
+
end
|
207
124
|
|
208
|
-
|
209
|
-
|
210
|
-
|
125
|
+
it "should render show template" do
|
126
|
+
do_invalid_post
|
127
|
+
response.should render_template('new')
|
128
|
+
end
|
211
129
|
end
|
212
130
|
|
213
|
-
|
214
|
-
@client_application.should_receive(:update_attributes).and_return(false)
|
215
|
-
put :update, :id => '1', 'client_application'=>{'name' => 'my site'}
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should query current_users client applications" do
|
219
|
-
@user.should_receive(:client_applications).and_return(@client_applications)
|
220
|
-
@client_applications.should_receive(:find).with('1').and_return(@client_application)
|
221
|
-
do_valid_update
|
222
|
-
end
|
131
|
+
describe "destroy" do
|
223
132
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
133
|
+
def do_delete
|
134
|
+
delete :destroy, :id => '1'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should destroy client applications" do
|
138
|
+
do_delete
|
139
|
+
ClientApplication.should_not be_exists(1)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should redirect to list" do
|
143
|
+
do_delete
|
144
|
+
response.should be_redirect
|
145
|
+
response.should redirect_to(:action => 'index')
|
146
|
+
end
|
229
147
|
|
230
|
-
it "should assign client_applications" do
|
231
|
-
do_invalid_update
|
232
|
-
assigns[:client_application].should equal(@client_application)
|
233
148
|
end
|
149
|
+
|
150
|
+
describe "update" do
|
234
151
|
|
235
|
-
|
236
|
-
|
237
|
-
|
152
|
+
def do_valid_update
|
153
|
+
put :update, :id => '1', 'client_application'=>{'name' => 'updated site'}
|
154
|
+
end
|
155
|
+
|
156
|
+
def do_invalid_update
|
157
|
+
put :update, :id => '1', 'client_application'=>{'name' => nil}
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should redirect to show client_application" do
|
161
|
+
do_valid_update
|
162
|
+
response.should be_redirect
|
163
|
+
response.should redirect_to(:action => "show", :id => 1)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should assign client_applications" do
|
167
|
+
do_invalid_update
|
168
|
+
assigns[:client_application].should == ClientApplication.find(1)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should render show template" do
|
172
|
+
do_invalid_update
|
173
|
+
response.should render_template('edit')
|
174
|
+
end
|
238
175
|
end
|
239
176
|
end
|
@@ -2,10 +2,22 @@ require 'oauth/controllers/provider_controller'
|
|
2
2
|
class OauthController < ApplicationController
|
3
3
|
include OAuth::Controllers::ProviderController
|
4
4
|
|
5
|
+
protected
|
5
6
|
# Override this to match your authorization page form
|
6
7
|
# It currently expects a checkbox called authorize
|
7
8
|
# def user_authorizes_token?
|
8
9
|
# params[:authorize] == '1'
|
9
10
|
# end
|
10
11
|
|
12
|
+
# should authenticate and return a user if valid password.
|
13
|
+
# This example should work with most Authlogic or Devise. Uncomment it
|
14
|
+
# def authenticate_user(username,password)
|
15
|
+
# user = User.find_by_email params[:username]
|
16
|
+
# if user && user.valid_password?(params[:password])
|
17
|
+
# user
|
18
|
+
# else
|
19
|
+
# nil
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
11
23
|
end
|