le1t0-oauth-plugin 0.3.14.001 → 0.4.0.pre4.001
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG +20 -0
- data/Gemfile +4 -0
- data/README.rdoc +57 -12
- data/Rakefile +2 -43
- data/UPGRADE.rdoc +21 -0
- data/generators/oauth_consumer/templates/consumer_token.rb +6 -0
- data/generators/oauth_consumer/templates/controller.rb +4 -0
- 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_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 +11 -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 +40 -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 +11 -0
- data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +27 -0
- data/lib/generators/oauth_consumer/templates/controller.rb +50 -0
- data/lib/generators/oauth_consumer/templates/oauth_config.rb +47 -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-plugin.rb +22 -1
- data/lib/oauth-plugin/version.rb +5 -0
- data/lib/oauth/controllers/application_controller_methods.rb +195 -66
- data/lib/oauth/controllers/consumer_controller.rb +18 -6
- data/lib/oauth/controllers/provider_controller.rb +153 -43
- data/lib/oauth/models/consumers/service_loader.rb +3 -0
- data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
- data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
- data/lib/oauth/models/consumers/token.rb +29 -5
- data/lib/oauth/rack/oauth_filter.rb +50 -0
- data/oauth-plugin.gemspec +13 -96
- data/rails/init.rb +1 -7
- metadata +123 -10
- data/VERSION +0 -1
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
0.4.0-pre4
|
2
|
+
- Fixed bug when creating a new user from a new consumer token
|
3
|
+
- Fix typo in consumer token [krasio]
|
4
|
+
- Fix issue with mongoid not supporting find_by_x style queries. [3en]
|
5
|
+
0.4.0-pre3
|
6
|
+
- Experimental rack filter for OAuth 1.0a:
|
7
|
+
see lib/oauth/rack/oauth_filter.rb for details
|
8
|
+
0.4.0-pre2
|
9
|
+
- mongoid defaults to being embedded
|
10
|
+
- new :auto_login option in oauth_config.rb which lets you use eg. twitter as a primary authentication method
|
11
|
+
0.4.0-pre1
|
12
|
+
- mongoid support in rails 3 [Alexander Semyonov]
|
13
|
+
- OAUTH 2.0 authorization_code and password grant types
|
14
|
+
- Supports OAuth 2.0 draft 10 (Note this is incompatible with previous drafts)
|
15
|
+
- Refactored application_controller_methods to be a lot less intrusive
|
16
|
+
- Increased default token and key size in anticipation of OAuth2 support
|
17
|
+
- Rails 3 support
|
18
|
+
- Rails 3 generators [Paul Rosiana] and patches by [Alexander Flatter]
|
19
|
+
- Modularized Rails 3 generators [Alexander Semyonov]
|
20
|
+
- Callback urls now allow query parameters. Multiple patches but I used [Unk]'s.
|
1
21
|
10/08/2009
|
2
22
|
0.3.14
|
3
23
|
- Fixed the class generation when you have a custom token defined. [Brian Morearty]
|
data/Gemfile
ADDED
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,15 +20,25 @@ 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.4) which is the core OAuth ruby library. It will likely NOT work on any previous version of the gem.
|
20
24
|
|
21
|
-
|
25
|
+
gem install oauth
|
26
|
+
|
27
|
+
== Installation (Rails 3.0)
|
28
|
+
|
29
|
+
Add the plugin to your Gemfile:
|
22
30
|
|
23
|
-
|
31
|
+
gem "oauth-plugin", ">=0.4.0.pre1"
|
32
|
+
|
33
|
+
And install it:
|
34
|
+
|
35
|
+
bundle install
|
36
|
+
|
37
|
+
== Installation (Rails 2.x)
|
24
38
|
|
25
39
|
The plugin can now be installed as an gem from github, which is the easiest way to keep it up to date.
|
26
40
|
|
27
|
-
|
41
|
+
gem install oauth-plugin --pre
|
28
42
|
|
29
43
|
You should add the following in the gem dependency section of environment.rb
|
30
44
|
|
@@ -35,7 +49,7 @@ Alternatively you can install it in vendors/plugin:
|
|
35
49
|
|
36
50
|
script/plugin install git://github.com/pelle/oauth-plugin.git
|
37
51
|
|
38
|
-
The Generator currently creates code (in particular views) that only work in Rails 2.
|
52
|
+
The Generator currently creates code (in particular views) that only work in Rails 2 and 3.
|
39
53
|
|
40
54
|
It should not be difficult to manually modify the code to work on Rails 1.2.x
|
41
55
|
|
@@ -43,7 +57,34 @@ I think the only real issue is that the views have .html.erb extensions. So thes
|
|
43
57
|
|
44
58
|
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
59
|
|
46
|
-
== OAuth Provider generator
|
60
|
+
== OAuth Provider generator (Rails 3)
|
61
|
+
|
62
|
+
This currently supports rspec, test_unit, haml, erb, active_record and mongoid:
|
63
|
+
|
64
|
+
rails g oauth_provider
|
65
|
+
|
66
|
+
This generates OAuth and OAuth client controllers as well as the required models.
|
67
|
+
|
68
|
+
It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication. It also requires Rails 2.0.
|
69
|
+
|
70
|
+
=== Generator Options
|
71
|
+
|
72
|
+
The generator supports the defaults you have created in your application.rb file. eg:
|
73
|
+
|
74
|
+
config.generators do |g|
|
75
|
+
g.orm :mongoid
|
76
|
+
g.template_engine :haml
|
77
|
+
g.test_framework :rspec
|
78
|
+
end
|
79
|
+
|
80
|
+
=== User Model
|
81
|
+
|
82
|
+
Add the following lines to your user model:
|
83
|
+
|
84
|
+
has_many :client_applications
|
85
|
+
has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
|
86
|
+
|
87
|
+
== OAuth Provider generator (Rails 2)
|
47
88
|
|
48
89
|
While it isn't very flexible at the moment there is an oauth_provider generator which you can use like this:
|
49
90
|
|
@@ -255,18 +296,24 @@ You could add application specific information to the OauthToken and ClientAppli
|
|
255
296
|
|
256
297
|
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
298
|
|
258
|
-
To run it simply run:
|
299
|
+
To run it in Rails 3 simply run:
|
300
|
+
|
301
|
+
rails g oauth_consumer
|
302
|
+
|
303
|
+
In previous versions:
|
259
304
|
|
260
305
|
./script/generate oauth_consumer
|
261
306
|
|
262
307
|
This generates the OauthConsumerController as well as the ConsumerToken model.
|
263
308
|
|
264
|
-
=== Generator Options
|
309
|
+
=== Generator Options (Rails 2)
|
265
310
|
|
266
311
|
By default the generator generates ERB templates. The generator can instead create HAML templates. To do this use the following options:
|
267
312
|
|
268
313
|
./script/generate oauth_consumer --haml
|
269
314
|
|
315
|
+
Rails 3 respects your application defaults, see the oauth provider generator section above for more info.
|
316
|
+
|
270
317
|
=== Configuration
|
271
318
|
|
272
319
|
All configuration of applications is done in
|
@@ -315,7 +362,7 @@ eg. If you connect to Yahoo's FireEagle you would add the :fire_eagle entry to O
|
|
315
362
|
|
316
363
|
This allows you to add a has_one association in your user model:
|
317
364
|
|
318
|
-
has_one :fire_eagle
|
365
|
+
has_one :fire_eagle, :class_name=>"FireEagleToken", :dependent=>:destroy
|
319
366
|
|
320
367
|
And you could do:
|
321
368
|
|
@@ -359,8 +406,6 @@ Run them as any other normal migration in rails with:
|
|
359
406
|
|
360
407
|
== More
|
361
408
|
|
362
|
-
The Google Code project is http://code.google.com/p/oauth-plugin/
|
363
|
-
|
364
409
|
The Mailing List for all things OAuth in Ruby is:
|
365
410
|
|
366
411
|
http://groups.google.com/group/oauth-ruby
|
@@ -373,4 +418,4 @@ The OAuth Ruby Gem home page is http://oauth.rubyforge.org
|
|
373
418
|
|
374
419
|
Please help documentation, patches and testing.
|
375
420
|
|
376
|
-
Copyright (c) 2007-
|
421
|
+
Copyright (c) 2007-2010 Pelle Braendgaard and contributors, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,43 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the oauth plugin.'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
t.verbose = true
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Generate documentation for the oauth plugin.'
|
16
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
-
rdoc.rdoc_dir = 'rdoc'
|
18
|
-
rdoc.title = 'Oauth'
|
19
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README')
|
21
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
-
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
require 'jeweler'
|
26
|
-
Jeweler::Tasks.new do |gemspec|
|
27
|
-
gemspec.name = "oauth-plugin"
|
28
|
-
gemspec.summary = "Ruby on Rails Plugin for OAuth Provider and Consumer"
|
29
|
-
gemspec.description = "Rails plugin for implementing an OAuth Provider or Consumer"
|
30
|
-
gemspec.email = "oauth-ruby@googlegroups.com"
|
31
|
-
gemspec.homepage = "http://github.com/pelle/oauth-plugin"
|
32
|
-
gemspec.authors = ["Pelle Braendgaard"]
|
33
|
-
gemspec.add_dependency('oauth', '>= 0.3.5')
|
34
|
-
gemspec.rubyforge_project = 'oauth'
|
35
|
-
end
|
36
|
-
|
37
|
-
Jeweler::RubyforgeTasks.new do |rubyforge|
|
38
|
-
rubyforge.doc_task = "rdoc"
|
39
|
-
end
|
40
|
-
|
41
|
-
rescue LoadError
|
42
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
43
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
data/UPGRADE.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
A few non backwards compatible changes have been made that are really easy to fix.
|
2
|
+
|
3
|
+
If you are upgrading a oauth_consumer from 0.3.x to 0.4.x add the following line to your consumer_token model:
|
4
|
+
|
5
|
+
belongs_to :user
|
6
|
+
|
7
|
+
So it looks like this:
|
8
|
+
|
9
|
+
require 'oauth/models/consumers/token'
|
10
|
+
class ConsumerToken < ActiveRecord::Base
|
11
|
+
include Oauth::Models::Consumers::Token
|
12
|
+
belongs_to :user
|
13
|
+
end
|
14
|
+
|
15
|
+
You should also upgrade your oauth_consumer_controller as we no longer call login_required in the library. This should make it easier for implementing it with other authentication frameworks:
|
16
|
+
|
17
|
+
require 'oauth/controllers/consumer_controller'
|
18
|
+
class OauthConsumersController < ApplicationController
|
19
|
+
include Oauth::Controllers::ConsumerController
|
20
|
+
# Replace this with the equivalent for your authentication framework
|
21
|
+
before_filter :login_required, :only=>:index
|
@@ -2,4 +2,10 @@ require 'oauth/models/consumers/token'
|
|
2
2
|
class ConsumerToken < ActiveRecord::Base
|
3
3
|
include Oauth::Models::Consumers::Token
|
4
4
|
|
5
|
+
# You can safely remove this callback if you don't allow login from any of your services
|
6
|
+
before_create :create_user
|
7
|
+
|
8
|
+
# Modify this with class_name etc to match your application
|
9
|
+
belongs_to :user
|
10
|
+
|
5
11
|
end
|
@@ -7,6 +7,10 @@ class OauthConsumersController < ApplicationController
|
|
7
7
|
@services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
|
8
8
|
end
|
9
9
|
|
10
|
+
def callback
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
10
14
|
protected
|
11
15
|
|
12
16
|
# Change this to decide where you want to redirect user to after callback is finished.
|
@@ -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
|