houston-oauth-plugin 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/CHANGELOG +187 -0
  4. data/Gemfile +27 -0
  5. data/Guardfile +8 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +542 -0
  8. data/Rakefile +1 -0
  9. data/UPGRADE.rdoc +21 -0
  10. data/generators/oauth_consumer/USAGE +10 -0
  11. data/generators/oauth_consumer/oauth_consumer_generator.rb +52 -0
  12. data/generators/oauth_consumer/templates/consumer_token.rb +11 -0
  13. data/generators/oauth_consumer/templates/controller.rb +27 -0
  14. data/generators/oauth_consumer/templates/index.html.erb +29 -0
  15. data/generators/oauth_consumer/templates/index.html.haml +18 -0
  16. data/generators/oauth_consumer/templates/index.html.slim +15 -0
  17. data/generators/oauth_consumer/templates/migration.rb +23 -0
  18. data/generators/oauth_consumer/templates/oauth_config.rb +73 -0
  19. data/generators/oauth_consumer/templates/show.html.erb +7 -0
  20. data/generators/oauth_consumer/templates/show.html.haml +8 -0
  21. data/generators/oauth_consumer/templates/show.html.slim +8 -0
  22. data/generators/oauth_provider/USAGE +20 -0
  23. data/generators/oauth_provider/lib/insert_routes.rb +67 -0
  24. data/generators/oauth_provider/oauth_provider_generator.rb +127 -0
  25. data/generators/oauth_provider/templates/_form.html.erb +17 -0
  26. data/generators/oauth_provider/templates/_form.html.haml +21 -0
  27. data/generators/oauth_provider/templates/access_token.rb +16 -0
  28. data/generators/oauth_provider/templates/authorize.html.erb +14 -0
  29. data/generators/oauth_provider/templates/authorize.html.haml +16 -0
  30. data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
  31. data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
  32. data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
  33. data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
  34. data/generators/oauth_provider/templates/client_application.rb +57 -0
  35. data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
  36. data/generators/oauth_provider/templates/client_application_test.rb +42 -0
  37. data/generators/oauth_provider/templates/client_applications.yml +23 -0
  38. data/generators/oauth_provider/templates/clients_controller.rb +52 -0
  39. data/generators/oauth_provider/templates/clients_controller_spec.rb +176 -0
  40. data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
  41. data/generators/oauth_provider/templates/controller.rb +23 -0
  42. data/generators/oauth_provider/templates/edit.html.erb +7 -0
  43. data/generators/oauth_provider/templates/edit.html.haml +4 -0
  44. data/generators/oauth_provider/templates/index.html.erb +43 -0
  45. data/generators/oauth_provider/templates/index.html.haml +39 -0
  46. data/generators/oauth_provider/templates/migration.rb +47 -0
  47. data/generators/oauth_provider/templates/new.html.erb +5 -0
  48. data/generators/oauth_provider/templates/new.html.haml +5 -0
  49. data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
  50. data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
  51. data/generators/oauth_provider/templates/oauth2_token.rb +20 -0
  52. data/generators/oauth_provider/templates/oauth2_token_spec.rb +52 -0
  53. data/generators/oauth_provider/templates/oauth2_verifier.rb +35 -0
  54. data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +44 -0
  55. data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
  56. data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
  57. data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
  58. data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
  59. data/generators/oauth_provider/templates/oauth_token.rb +30 -0
  60. data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
  61. data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
  62. data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
  63. data/generators/oauth_provider/templates/request_token.rb +40 -0
  64. data/generators/oauth_provider/templates/show.html.erb +27 -0
  65. data/generators/oauth_provider/templates/show.html.haml +30 -0
  66. data/init.rb +1 -0
  67. data/install.rb +2 -0
  68. data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
  69. data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +11 -0
  70. data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
  71. data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
  72. data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
  73. data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
  74. data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
  75. data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +20 -0
  76. data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +35 -0
  77. data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
  78. data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
  79. data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
  80. data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
  81. data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
  82. data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
  83. data/lib/generators/erb/oauth_provider_generator.rb +23 -0
  84. data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
  85. data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
  86. data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
  87. data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
  88. data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
  89. data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
  90. data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
  91. data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
  92. data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
  93. data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
  94. data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
  95. data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
  96. data/lib/generators/haml/oauth_provider_generator.rb +28 -0
  97. data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
  98. data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
  99. data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
  100. data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
  101. data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
  102. data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
  103. data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
  104. data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
  105. data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
  106. data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
  107. data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +41 -0
  108. data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
  109. data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
  110. data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
  111. data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +20 -0
  112. data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +35 -0
  113. data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
  114. data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
  115. data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
  116. data/lib/generators/oauth_consumer/USAGE +11 -0
  117. data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +31 -0
  118. data/lib/generators/oauth_consumer/templates/controller.rb +59 -0
  119. data/lib/generators/oauth_consumer/templates/oauth_config.rb +68 -0
  120. data/lib/generators/oauth_inflections.rb +6 -0
  121. data/lib/generators/oauth_plugin.rb +0 -0
  122. data/lib/generators/oauth_provider/USAGE +18 -0
  123. data/lib/generators/oauth_provider/oauth_provider_generator.rb +37 -0
  124. data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
  125. data/lib/generators/oauth_provider/templates/controller.rb +23 -0
  126. data/lib/generators/rspec/oauth_provider_generator.rb +35 -0
  127. data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
  128. data/lib/generators/rspec/templates/client_applications.yml +23 -0
  129. data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
  130. data/lib/generators/rspec/templates/oauth2_token_spec.rb +52 -0
  131. data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +44 -0
  132. data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
  133. data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
  134. data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
  135. data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
  136. data/lib/generators/slim/oauth_consumer_generator.rb +21 -0
  137. data/lib/generators/slim/oauth_consumer_templates/index.html.slim +15 -0
  138. data/lib/generators/slim/oauth_consumer_templates/show.html.slim +8 -0
  139. data/lib/generators/test_unit/oauth_provider_generator.rb +33 -0
  140. data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
  141. data/lib/generators/test_unit/templates/client_applications.yml +23 -0
  142. data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
  143. data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
  144. data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
  145. data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
  146. data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
  147. data/lib/oauth-plugin.rb +24 -0
  148. data/lib/oauth-plugin/version.rb +5 -0
  149. data/lib/oauth/controllers/application_controller_methods.rb +140 -0
  150. data/lib/oauth/controllers/consumer_controller.rb +153 -0
  151. data/lib/oauth/controllers/provider_controller.rb +181 -0
  152. data/lib/oauth/models/consumers/service_loader.rb +28 -0
  153. data/lib/oauth/models/consumers/services/agree2_token.rb +15 -0
  154. data/lib/oauth/models/consumers/services/fireeagle_token.rb +39 -0
  155. data/lib/oauth/models/consumers/services/google_token.rb +21 -0
  156. data/lib/oauth/models/consumers/services/oauth2_token.rb +49 -0
  157. data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
  158. data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
  159. data/lib/oauth/models/consumers/services/twitter_token.rb +24 -0
  160. data/lib/oauth/models/consumers/simple_client.rb +50 -0
  161. data/lib/oauth/models/consumers/token.rb +121 -0
  162. data/lib/oauth/provider/authorizer.rb +83 -0
  163. data/lib/oauth/rack/oauth_filter.rb +97 -0
  164. data/oauth-plugin.gemspec +40 -0
  165. data/rails/init.rb +1 -0
  166. data/spec/dummy_provider_models.rb +53 -0
  167. data/spec/oauth/provider/authorizer_spec.rb +202 -0
  168. data/spec/rack/oauth_filter_spec.rb +244 -0
  169. data/spec/spec_helper.rb +3 -0
  170. data/tasks/oauth_tasks.rake +4 -0
  171. data/uninstall.rb +1 -0
  172. metadata +373 -0
@@ -0,0 +1,11 @@
1
+ This creates an OAuth Consumer controller as well as requisite models.
2
+
3
+ It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication that provides the methods "login_required" and "current_user".
4
+
5
+ See comments in generated controller for more info about overriding these.
6
+
7
+ If you generated the migration file (true by default), make sure you run
8
+
9
+ rake db:migrate
10
+
11
+ See README.rdoc for more.
@@ -0,0 +1,31 @@
1
+ require 'rails/generators/migration'
2
+ require 'rails/generators/active_record'
3
+
4
+ class OauthConsumerGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ hook_for :orm
8
+
9
+ def copy_models
10
+ template 'oauth_config.rb', File.join('config', 'initializers', 'oauth_consumers.rb')
11
+ end
12
+
13
+ def copy_controller
14
+ template 'controller.rb', File.join('app', 'controllers', 'oauth_consumers_controller.rb')
15
+ end
16
+
17
+ hook_for :template_engine
18
+
19
+ def add_route
20
+ route <<-ROUTE.strip
21
+ resources :oauth_consumers do
22
+ member do
23
+ get :callback
24
+ get :callback2
25
+ match 'client/*endpoint' => 'oauth_consumers#client', :via => [:get, :post, :put, :delete]
26
+ end
27
+ end
28
+ ROUTE
29
+ end
30
+
31
+ end
@@ -0,0 +1,59 @@
1
+ require 'oauth/controllers/consumer_controller'
2
+ class OauthConsumersController < ApplicationController
3
+ include Oauth::Controllers::ConsumerController
4
+ # Replace this with the equivalent for your authentication framework
5
+ # Eg. for devise
6
+ #
7
+ # before_filter :authenticate_user!, :only=>:index
8
+ before_filter :login_required, :only=>:index
9
+
10
+ def index
11
+ @consumer_tokens=ConsumerToken.all :conditions=>{:user_id=>current_user.id}
12
+ @services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
13
+ end
14
+
15
+ def callback
16
+ super
17
+ end
18
+
19
+ def client
20
+ super
21
+ end
22
+
23
+
24
+ protected
25
+
26
+ # Change this to decide where you want to redirect user to after callback is finished.
27
+ # params[:id] holds the service name so you could use this to redirect to various parts
28
+ # of your application depending on what service you're connecting to.
29
+ def go_back
30
+ redirect_to root_url
31
+ end
32
+
33
+ # The plugin requires logged_in? to return true or false if the user is logged in. Uncomment and
34
+ # call your auth frameworks equivalent below if different. eg. for devise:
35
+ #
36
+ # def logged_in?
37
+ # user_signed_in?
38
+ # end
39
+
40
+ # The plugin requires current_user to return the current logged in user. Uncomment and
41
+ # call your auth frameworks equivalent below if different.
42
+ # def current_user
43
+ # current_person
44
+ # end
45
+
46
+ # The plugin requires a way to log a user in. Call your auth frameworks equivalent below
47
+ # if different. eg. for devise:
48
+ #
49
+ # def current_user=(user)
50
+ # sign_in(user)
51
+ # end
52
+
53
+ # Override this to deny the user or redirect to a login screen depending on your framework and app
54
+ # if different. eg. for devise:
55
+ #
56
+ # def deny_access!
57
+ # raise Acl9::AccessDenied
58
+ # end
59
+ end
@@ -0,0 +1,68 @@
1
+ # edit this file to contain credentials for the OAuth services you support.
2
+ # each entry needs a corresponding token model.
3
+ #
4
+ # eg. :twitter => TwitterToken, :hour_feed => HourFeedToken etc.
5
+ #
6
+ # OAUTH_CREDENTIALS={
7
+ # :twitter=>{
8
+ # :key=>"",
9
+ # :secret=>"",
10
+ # :client=>:twitter_gem, # :twitter_gem or :oauth_gem (defaults to :twitter_gem)
11
+ # :expose => false, # expose client at /oauth_consumers/twitter/client see docs
12
+ # :allow_login => true # Use :allow_login => true to allow user to login to account
13
+ # },
14
+ # :google=>{
15
+ # :key=>"",
16
+ # :secret=>"",
17
+ # :expose => false, # expose client at /oauth_consumers/google/client see docs
18
+ # :scope=>"" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
19
+ # },
20
+ # :github=>{
21
+ # :key => "",
22
+ # :secret => "",
23
+ # :expose => false, # expose client at /oauth_consumers/twitter/client see docs
24
+ #
25
+ # },
26
+ # :facebook=>{
27
+ # :key => "",
28
+ # :secret => ""
29
+ # },
30
+ # :agree2=>{
31
+ # :key=>"",
32
+ # :secret=>""
33
+ # },
34
+ # :fireeagle=>{
35
+ # :key=>"",
36
+ # :secret=>""
37
+ # },
38
+ # :oauth2_server => {
39
+ # :key=>"",
40
+ # :secret=>"",
41
+ # :oauth_version => 2
42
+ # :options=>{ # OAuth::Consumer options
43
+ # :site=>"http://hourfeed.com" # Remember to add a site for a generic OAuth site
44
+ # }
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
51
+ # }
52
+ # },
53
+ # :nu_bux=>{
54
+ # :key=>"",
55
+ # :secret=>"",
56
+ # :super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
57
+ # # with a token implementation you can set the superclass
58
+ # # to use
59
+ # :options=>{ # OAuth::Consumer options
60
+ # :site=>"http://nubux.heroku.com"
61
+ # }
62
+ # }
63
+ # }
64
+ #
65
+ OAUTH_CREDENTIALS={
66
+ } unless defined? OAUTH_CREDENTIALS
67
+
68
+ load 'oauth/models/consumers/service_loader.rb'
@@ -0,0 +1,6 @@
1
+ require 'active_support'
2
+ require 'active_support/inflector'
3
+
4
+ ActiveSupport::Inflector.inflections do |inflect|
5
+ inflect.uncountable %w(oauth)
6
+ end
File without changes
@@ -0,0 +1,18 @@
1
+ This creates an OAuth Provider controller as well as the requisite models.
2
+
3
+ It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication.
4
+
5
+ If you generated the migration file (true by default), make sure you run
6
+
7
+ rake db:migrate
8
+
9
+ include the following in your user.rb
10
+
11
+ has_many :client_applications
12
+ has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
13
+
14
+ For legacy OAUTH 1.0 support add the following constant in your environment.rb
15
+
16
+ OAUTH_10_SUPPORT = true
17
+
18
+ Note, you should only do this if you really positively require to support old OAuth1.0 clients. There is a serious security issue with this.
@@ -0,0 +1,37 @@
1
+ require 'generators/oauth_inflections'
2
+
3
+ class OauthProviderGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ argument :name, :type => :string, :default => 'Oauth'
7
+
8
+ desc 'This creates an OAuth Provider controller as well as the requisite models.'
9
+
10
+ hook_for :orm
11
+
12
+ def check_class_collisions
13
+ # Check for class naming collisions.
14
+ class_collisions class_path, "#{class_name}Controller", # Oauth Controller
15
+ "#{class_name}Helper",
16
+ "#{class_name}ClientsController",
17
+ "#{class_name}ClientsHelper"
18
+ end
19
+
20
+ def copy_controller_files
21
+ template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb")
22
+ template 'clients_controller.rb', File.join('app/controllers', class_path, "#{file_name}_clients_controller.rb")
23
+ end
24
+
25
+ hook_for :test_framework, :template_engine
26
+
27
+ def add_routes
28
+ route "match '/oauth', :to => 'oauth#index', :as => :oauth"
29
+ route "match '/oauth/authorize', :to => 'oauth#authorize', :as => :authorize"
30
+ route "match '/oauth/request_token', :to => 'oauth#request_token', :as => :request_token"
31
+ route "match '/oauth/access_token', :to => 'oauth#access_token', :as => :access_token"
32
+ route "match '/oauth/token', :to => 'oauth#token', :as => :token"
33
+ route "match '/oauth/test_request', :to => 'oauth#test_request', :as => :test_request"
34
+
35
+ route "resources :#{file_name}_clients"
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ class OauthClientsController < ApplicationController
2
+ before_filter :login_required
3
+ before_filter :get_client_application, :only => [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @client_applications = current_user.client_applications
7
+ @tokens = current_user.tokens.find :all, :conditions => 'oauth_tokens.invalidated_at is null and oauth_tokens.authorized_at is not null'
8
+ end
9
+
10
+ def new
11
+ @client_application = ClientApplication.new
12
+ end
13
+
14
+ def create
15
+ @client_application = current_user.client_applications.build(params[:client_application])
16
+ if @client_application.save
17
+ flash[:notice] = "Registered the information successfully"
18
+ redirect_to :action => "show", :id => @client_application.id
19
+ else
20
+ render :action => "new"
21
+ end
22
+ end
23
+
24
+ def show
25
+ end
26
+
27
+ def edit
28
+ end
29
+
30
+ def update
31
+ if @client_application.update_attributes(params[:client_application])
32
+ flash[:notice] = "Updated the client information successfully"
33
+ redirect_to :action => "show", :id => @client_application.id
34
+ else
35
+ render :action => "edit"
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ @client_application.destroy
41
+ flash[:notice] = "Destroyed the client application registration"
42
+ redirect_to :action => "index"
43
+ end
44
+
45
+ private
46
+ def get_client_application
47
+ unless @client_application = current_user.client_applications.find(params[:id])
48
+ flash.now[:error] = "Wrong application id"
49
+ raise ActiveRecord::RecordNotFound
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ require 'oauth/controllers/provider_controller'
2
+ class OauthController < ApplicationController
3
+ include OAuth::Controllers::ProviderController
4
+
5
+ protected
6
+ # Override this to match your authorization page form
7
+ # It currently expects a checkbox called authorize
8
+ # def user_authorizes_token?
9
+ # params[:authorize] == '1'
10
+ # end
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
+
23
+ end
@@ -0,0 +1,35 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ class OauthProviderGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ argument :name, :type => :string, :default => 'Oauth'
9
+ class_option :fixture, :type => :boolean
10
+
11
+ def copy_controller_spec_files
12
+ template 'clients_controller_spec.rb',
13
+ File.join('spec/controllers', class_path, "#{file_name}_clients_controller_spec.rb")
14
+ end
15
+
16
+ def copy_models_spec_files
17
+ template 'client_application_spec.rb', File.join('spec/models', 'client_application_spec.rb')
18
+ template 'oauth_token_spec.rb', File.join('spec/models', 'oauth_token_spec.rb')
19
+ template 'oauth2_token_spec.rb', File.join('spec/models', 'oauth2_token_spec.rb')
20
+ template 'oauth2_verifier_spec.rb', File.join('spec/models', 'oauth2_verifier_spec.rb')
21
+ template 'oauth_nonce_spec.rb', File.join('spec/models', 'oauth_nonce_spec.rb')
22
+ end
23
+
24
+ hook_for :fixture_replacement
25
+
26
+ def create_fixture_file
27
+ if options[:fixtures] && options[:fixture_replacement].nil?
28
+ template 'client_applications.yml', File.join('test/fixtures', 'client_applications.yml')
29
+ template 'oauth_tokens.yml', File.join('test/fixtures', 'oauth_tokens.yml')
30
+ template 'oauth_nonces.yml', File.join('test/fixtures', 'oauth_nonces.yml')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ describe ClientApplication do
3
+ fixtures :users, :client_applications, :oauth_tokens
4
+ before(:each) do
5
+ @application = ClientApplication.create :name => "Agree2", :url => "http://agree2.com", :user => users(:quentin)
6
+ end
7
+
8
+ it "should be valid" do
9
+ @application.should be_valid
10
+ end
11
+
12
+
13
+ it "should not have errors" do
14
+ @application.errors.full_messages.should == []
15
+ end
16
+
17
+ it "should have key and secret" do
18
+ @application.key.should_not be_nil
19
+ @application.secret.should_not be_nil
20
+ end
21
+
22
+ it "should have credentials" do
23
+ @application.credentials.should_not be_nil
24
+ @application.credentials.key.should == @application.key
25
+ @application.credentials.secret.should == @application.secret
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,23 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ name: MyString
5
+ url: http://test.com
6
+ support_url: http://test.com/support
7
+ callback_url: http://test.com/callback
8
+ key: one_key
9
+ secret: MyString
10
+ user_id: 1
11
+ created_at: 2007-11-17 16:56:51
12
+ updated_at: 2007-11-17 16:56:51
13
+ two:
14
+ id: 2
15
+ name: MyString
16
+ url: http://test.com
17
+ support_url: http://test.com/support
18
+ callback_url: http://test.com/callback
19
+ key: two_key
20
+ secret: MyString
21
+ user_id: 1
22
+ created_at: 2007-11-17 16:56:51
23
+ updated_at: 2007-11-17 16:56:51
@@ -0,0 +1,176 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/oauth_controller_spec_helper'
3
+ require 'oauth/client/action_controller_request'
4
+
5
+ describe OauthClientsController do
6
+ if defined?(Devise)
7
+ include Devise::TestHelpers
8
+ end
9
+ include OAuthControllerSpecHelper
10
+ fixtures :client_applications, :oauth_tokens, :users
11
+ before(:each) do
12
+ login_as_application_owner
13
+ end
14
+
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
23
+
24
+ it "should be successful" do
25
+ do_get
26
+ response.should be_success
27
+ end
28
+
29
+ it "should assign client_applications" do
30
+ do_get
31
+ assigns[:client_applications].should==@client_applications
32
+ end
33
+
34
+ it "should render index template" do
35
+ do_get
36
+ response.should render_template('index')
37
+ end
38
+ end
39
+
40
+ describe "show" do
41
+
42
+ def do_get
43
+ get :show, :id => '1'
44
+ end
45
+
46
+ it "should be successful" do
47
+ do_get
48
+ response.should be_success
49
+ end
50
+
51
+ it "should assign client_applications" do
52
+ do_get
53
+ assigns[:client_application].should==current_client_application
54
+ end
55
+
56
+ it "should render show template" do
57
+ do_get
58
+ response.should render_template('show')
59
+ end
60
+
61
+ end
62
+
63
+ describe "new" do
64
+
65
+ def do_get
66
+ get :new
67
+ end
68
+
69
+ it "should be successful" do
70
+ do_get
71
+ response.should be_success
72
+ end
73
+
74
+ it "should assign client_applications" do
75
+ do_get
76
+ assigns[:client_application].class.should==ClientApplication
77
+ end
78
+
79
+ it "should render show template" do
80
+ do_get
81
+ response.should render_template('new')
82
+ end
83
+
84
+ end
85
+
86
+ describe "edit" do
87
+ def do_get
88
+ get :edit, :id => '1'
89
+ end
90
+
91
+ it "should be successful" do
92
+ do_get
93
+ response.should be_success
94
+ end
95
+
96
+ it "should assign client_applications" do
97
+ do_get
98
+ assigns[:client_application].should==current_client_application
99
+ end
100
+
101
+ it "should render edit template" do
102
+ do_get
103
+ response.should render_template('edit')
104
+ end
105
+
106
+ end
107
+
108
+ describe "create" do
109
+
110
+ def do_valid_post
111
+ post :create, 'client_application'=>{'name' => 'my site', :url=>"http://test.com"}
112
+ @client_application = ClientApplication.last
113
+ end
114
+
115
+ def do_invalid_post
116
+ post :create
117
+ end
118
+
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
124
+
125
+ it "should render show template" do
126
+ do_invalid_post
127
+ response.should render_template('new')
128
+ end
129
+ end
130
+
131
+ describe "destroy" do
132
+
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
147
+
148
+ end
149
+
150
+ describe "update" do
151
+
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
175
+ end
176
+ end