pelle-oauth-plugin 0.3.5

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.
Files changed (69) hide show
  1. data/.gitignore +5 -0
  2. data/CHANGELOG +76 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +375 -0
  5. data/Rakefile +38 -0
  6. data/VERSION +1 -0
  7. data/generators/oauth_consumer/USAGE +10 -0
  8. data/generators/oauth_consumer/oauth_consumer_generator.rb +49 -0
  9. data/generators/oauth_consumer/templates/consumer_token.rb +5 -0
  10. data/generators/oauth_consumer/templates/controller.rb +14 -0
  11. data/generators/oauth_consumer/templates/migration.rb +20 -0
  12. data/generators/oauth_consumer/templates/oauth_config.rb +37 -0
  13. data/generators/oauth_consumer/templates/show.html.erb +7 -0
  14. data/generators/oauth_consumer/templates/show.html.haml +8 -0
  15. data/generators/oauth_provider/USAGE +20 -0
  16. data/generators/oauth_provider/lib/insert_routes.rb +67 -0
  17. data/generators/oauth_provider/oauth_provider_generator.rb +124 -0
  18. data/generators/oauth_provider/templates/_form.html.erb +17 -0
  19. data/generators/oauth_provider/templates/_form.html.haml +21 -0
  20. data/generators/oauth_provider/templates/access_token.rb +10 -0
  21. data/generators/oauth_provider/templates/authorize.html.erb +14 -0
  22. data/generators/oauth_provider/templates/authorize.html.haml +16 -0
  23. data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
  24. data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
  25. data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
  26. data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
  27. data/generators/oauth_provider/templates/client_application.rb +55 -0
  28. data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
  29. data/generators/oauth_provider/templates/client_application_test.rb +42 -0
  30. data/generators/oauth_provider/templates/client_applications.yml +23 -0
  31. data/generators/oauth_provider/templates/clients_controller.rb +52 -0
  32. data/generators/oauth_provider/templates/clients_controller_spec.rb +239 -0
  33. data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
  34. data/generators/oauth_provider/templates/controller.rb +5 -0
  35. data/generators/oauth_provider/templates/controller_spec.rb +367 -0
  36. data/generators/oauth_provider/templates/controller_spec_helper.rb +80 -0
  37. data/generators/oauth_provider/templates/controller_test.rb +310 -0
  38. data/generators/oauth_provider/templates/controller_test_helper.rb +115 -0
  39. data/generators/oauth_provider/templates/edit.html.erb +7 -0
  40. data/generators/oauth_provider/templates/edit.html.haml +4 -0
  41. data/generators/oauth_provider/templates/index.html.erb +43 -0
  42. data/generators/oauth_provider/templates/index.html.haml +39 -0
  43. data/generators/oauth_provider/templates/migration.rb +46 -0
  44. data/generators/oauth_provider/templates/new.html.erb +5 -0
  45. data/generators/oauth_provider/templates/new.html.haml +5 -0
  46. data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
  47. data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
  48. data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
  49. data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
  50. data/generators/oauth_provider/templates/oauth_token.rb +31 -0
  51. data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
  52. data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
  53. data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
  54. data/generators/oauth_provider/templates/request_token.rb +40 -0
  55. data/generators/oauth_provider/templates/show.html.erb +27 -0
  56. data/generators/oauth_provider/templates/show.html.haml +30 -0
  57. data/init.rb +7 -0
  58. data/install.rb +2 -0
  59. data/lib/oauth/controllers/application_controller_methods.rb +110 -0
  60. data/lib/oauth/controllers/consumer_controller.rb +69 -0
  61. data/lib/oauth/controllers/provider_controller.rb +78 -0
  62. data/lib/oauth/models/consumers/service_loader.rb +18 -0
  63. data/lib/oauth/models/consumers/services/agree2_token.rb +14 -0
  64. data/lib/oauth/models/consumers/services/twitter_token.rb +19 -0
  65. data/lib/oauth/models/consumers/token.rb +60 -0
  66. data/oauth-plugin.gemspec +104 -0
  67. data/tasks/oauth_tasks.rake +4 -0
  68. data/uninstall.rb +1 -0
  69. metadata +129 -0
@@ -0,0 +1,20 @@
1
+ ./script/generate oauth_provider
2
+
3
+ This creates an OAuth Provider controller as well as the requisite models.
4
+
5
+ It requires an authentication framework such as acts_as_authenticated, restful_authentication or restful_open_id_authentication.
6
+
7
+ If you generated the migration file (true by default), make sure you run
8
+
9
+ rake db:migrate
10
+
11
+ include the following in your user.rb
12
+
13
+ has_many :client_applications
14
+ has_many :tokens, :class_name=>"OauthToken",:order=>"authorized_at desc",:include=>[:client_application]
15
+
16
+ For legacy OAUTH 1.0 support add the following constant in your environment.rb
17
+
18
+ OAUTH_10_SUPPORT = true
19
+
20
+ 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,67 @@
1
+ # Stolen from http://github.com/technoweenie/restful-authentication
2
+
3
+ Rails::Generator::Commands::Create.class_eval do
4
+ def route_entry(raw)
5
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
6
+
7
+ logger.route raw
8
+ unless options[:pretend]
9
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
10
+ "#{match}\n #{raw}\n"
11
+ end
12
+ end
13
+ end
14
+
15
+ def route_resource(*resources)
16
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
17
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
18
+
19
+ logger.route "map.resource #{resource_list}"
20
+ unless options[:pretend]
21
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
22
+ "#{match}\n map.resource #{resource_list}\n"
23
+ end
24
+ end
25
+ end
26
+
27
+ def route_name(name, path, route_options = {})
28
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
29
+
30
+ logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
31
+ unless options[:pretend]
32
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
33
+ "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ Rails::Generator::Commands::Destroy.class_eval do
40
+ def route_resource(*resources)
41
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
42
+ look_for = "\n map.resource #{resource_list}\n"
43
+ logger.route "map.resource #{resource_list}"
44
+ unless options[:pretend]
45
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
46
+ end
47
+ end
48
+
49
+ def route_name(name, path, route_options = {})
50
+ look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
51
+ logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
52
+ unless options[:pretend]
53
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
54
+ end
55
+ end
56
+ end
57
+
58
+ Rails::Generator::Commands::List.class_eval do
59
+ def route_resource(*resources)
60
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
61
+ logger.route "map.resource #{resource_list}"
62
+ end
63
+
64
+ def route_name(name, path, options = {})
65
+ logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
66
+ end
67
+ end
@@ -0,0 +1,124 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_routes.rb")
2
+ class OauthProviderGenerator < Rails::Generator::Base
3
+ default_options :skip_migration => false
4
+ attr_reader :class_path,
5
+ :controller_name,
6
+ :controller_class_path,
7
+ :controller_file_path,
8
+ :controller_class_name,
9
+ :controller_singular_name,
10
+ :controller_plural_name
11
+ alias_method :controller_file_name, :controller_singular_name
12
+
13
+ def initialize(runtime_args, runtime_options = {})
14
+ super
15
+
16
+ @controller_name = args.shift || 'oauth'
17
+ @controller_singular_name = 'oauth'
18
+ @controller_plural_name = 'oauth'
19
+ @controller_file_name = 'oauth'
20
+ @controller_class_name="Oauth"
21
+ @class_path=''
22
+ @controller_class_path=''
23
+ end
24
+
25
+ def manifest
26
+ record do |m|
27
+
28
+ # Check for class naming collisions.
29
+ # Check for class naming collisions.
30
+ m.class_collisions controller_class_path, "#{controller_class_name}Controller", # Oauth Controller
31
+ "#{controller_class_name}Helper",
32
+ "#{controller_class_name}ClientsController",
33
+ "#{controller_class_name}ClientsHelper"
34
+ m.class_collisions class_path, "ClientApplication","OauthNonce","RequestToken","AccessToken","OauthToken"
35
+
36
+ # Controller, model, views, and test directories.
37
+ m.directory File.join('app/models', class_path)
38
+ m.directory File.join('app/controllers', controller_class_path)
39
+ m.directory File.join('app/views', controller_class_path, controller_file_name)
40
+ m.directory File.join('app/views', controller_class_path, 'oauth_clients')
41
+
42
+ m.template 'client_application.rb',File.join('app/models',"client_application.rb")
43
+ m.template 'oauth_token.rb', File.join('app/models',"oauth_token.rb")
44
+ m.template 'request_token.rb', File.join('app/models',"request_token.rb")
45
+ m.template 'access_token.rb', File.join('app/models',"access_token.rb")
46
+ m.template 'oauth_nonce.rb', File.join('app/models',"oauth_nonce.rb")
47
+
48
+ m.template 'controller.rb',File.join('app/controllers',controller_class_path,"#{controller_file_name}_controller.rb")
49
+
50
+ m.template 'clients_controller.rb',File.join('app/controllers',controller_class_path,"#{controller_file_name}_clients_controller.rb")
51
+ m.route_name 'oauth', '/oauth',:controller=>'oauth',:action=>'index'
52
+ m.route_name 'authorize', '/oauth/authorize',:controller=>'oauth',:action=>'authorize'
53
+ m.route_name 'request_token', '/oauth/request_token',:controller=>'oauth',:action=>'request_token'
54
+ m.route_name 'access_token', '/oauth/access_token',:controller=>'oauth',:action=>'access_token'
55
+ m.route_name 'test_request', '/oauth/test_request',:controller=>'oauth',:action=>'test_request'
56
+ m.route_resources "#{controller_file_name}_clients".to_sym
57
+
58
+ if !options[:test_unit]
59
+ m.directory File.join('spec')
60
+ m.directory File.join('spec/models')
61
+ m.directory File.join('spec/fixtures', class_path)
62
+ m.directory File.join('spec/controllers', controller_class_path)
63
+
64
+ m.template 'client_application_spec.rb',File.join('spec/models',"client_application_spec.rb")
65
+ m.template 'oauth_token_spec.rb', File.join('spec/models',"oauth_token_spec.rb")
66
+ m.template 'oauth_nonce_spec.rb', File.join('spec/models',"oauth_nonce_spec.rb")
67
+ m.template 'client_applications.yml',File.join('spec/fixtures',"client_applications.yml")
68
+ m.template 'oauth_tokens.yml', File.join('spec/fixtures',"oauth_tokens.yml")
69
+ m.template 'oauth_nonces.yml', File.join('spec/fixtures',"oauth_nonces.yml")
70
+ m.template 'controller_spec_helper.rb', File.join('spec/controllers', controller_class_path,"#{controller_file_name}_controller_spec_helper.rb")
71
+ m.template 'controller_spec.rb',File.join('spec/controllers',controller_class_path,"#{controller_file_name}_controller_spec.rb")
72
+ m.template 'clients_controller_spec.rb',File.join('spec/controllers',controller_class_path,"#{controller_file_name}_clients_controller_spec.rb")
73
+ else
74
+ m.directory File.join('test')
75
+ m.directory File.join('test/unit')
76
+ m.directory File.join('test/fixtures', class_path)
77
+ m.directory File.join('test/functional', controller_class_path)
78
+ m.template 'client_application_test.rb',File.join('test/unit',"client_application_test.rb")
79
+ m.template 'oauth_token_test.rb', File.join('test/unit',"oauth_token_test.rb")
80
+ m.template 'oauth_nonce_test.rb', File.join('test/unit',"oauth_nonce_test.rb")
81
+ m.template 'client_applications.yml',File.join('test/fixtures',"client_applications.yml")
82
+ m.template 'oauth_tokens.yml', File.join('test/fixtures',"oauth_tokens.yml")
83
+ m.template 'oauth_nonces.yml', File.join('test/fixtures',"oauth_nonces.yml")
84
+ m.template 'controller_test_helper.rb', File.join('test', controller_class_path,"#{controller_file_name}_controller_test_helper.rb")
85
+ m.template 'controller_test.rb',File.join('test/functional',controller_class_path,"#{controller_file_name}_controller_test.rb")
86
+ m.template 'clients_controller_test.rb',File.join('test/functional',controller_class_path,"#{controller_file_name}_clients_controller_test.rb")
87
+ end
88
+
89
+
90
+ @template_extension= options[:haml] ? "haml" : "erb"
91
+
92
+ m.template "_form.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "_form.html.#{@template_extension}")
93
+ m.template "new.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "new.html.#{@template_extension}")
94
+ m.template "index.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "index.html.#{@template_extension}")
95
+ m.template "show.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "show.html.#{@template_extension}")
96
+ m.template "edit.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "edit.html.#{@template_extension}")
97
+ m.template "authorize.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize.html.#{@template_extension}")
98
+ m.template "authorize_success.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_success.html.#{@template_extension}")
99
+ m.template "authorize_failure.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_failure.html.#{@template_extension}")
100
+
101
+ unless options[:skip_migration]
102
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => {
103
+ :migration_name => "CreateOauthTables"
104
+ }, :migration_file_name => "create_oauth_tables"
105
+ end
106
+ end
107
+ end
108
+
109
+ protected
110
+ def banner
111
+ "Usage: #{$0} #{spec.name}"
112
+ end
113
+
114
+ def add_options!(opt)
115
+ opt.separator ''
116
+ opt.separator 'Options:'
117
+ opt.on("--skip-migration",
118
+ "Don't generate a migration file") { |v| options[:skip_migration] = v }
119
+ opt.on("--test-unit",
120
+ "Generate the Test::Unit compatible tests instead of RSpec") { |v| options[:test_unit] = v }
121
+ opt.on("--haml",
122
+ "Templates use haml") { |v| options[:haml] = v }
123
+ end
124
+ end
@@ -0,0 +1,17 @@
1
+ <%%= error_messages_for :client_application %>
2
+ <div class="field">
3
+ <label for="client_application_name">Name*</label><br/>
4
+ <%%= f.text_field :name %>
5
+ </div>
6
+ <div class="field">
7
+ <label for="client_application_url">Main Application URL*</label><br/>
8
+ <%%= f.text_field :url %>
9
+ </div>
10
+ <div class="field">
11
+ <label for="client_application_callback_url">Callback URL*</label><br/>
12
+ <%%= f.text_field :callback_url %>
13
+ </div>
14
+ <div class="field">
15
+ <label for="client_application_support_url">Support URL</label><br/>
16
+ <%%= f.text_field :support_url %>
17
+ </div>
@@ -0,0 +1,21 @@
1
+ =error_messages_for :client_application
2
+ .field
3
+ %label{:for=>"client_application_name"} Name*
4
+ %br
5
+ = f.text_field :name
6
+
7
+ .field
8
+ %label{:for=>"client_application_url"} Main Application URL*
9
+ %br
10
+ = f.text_field :url
11
+
12
+ .field
13
+ %label{:for=>"client_application_callback_url"} Callback URL*
14
+ %br
15
+ = f.text_field :callback_url
16
+
17
+ .field
18
+ %label{:for=>"client_application_support_url"} Support URL
19
+ %br
20
+ = f.text_field :support_url
21
+
@@ -0,0 +1,10 @@
1
+ class AccessToken < OauthToken
2
+ validates_presence_of :user
3
+ before_create :set_authorized_at
4
+
5
+ protected
6
+
7
+ def set_authorized_at
8
+ self.authorized_at = Time.now
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ <h1>Authorize access to your account</h1>
2
+ <p>Would you like to authorize <%%= link_to @token.client_application.name,@token.client_application.url %> (<%%= link_to @token.client_application.url,@token.client_application.url %>) to access your account?</p>
3
+ <%% form_tag authorize_url do %>
4
+ <%%= hidden_field_tag "oauth_token", @token.token %>
5
+ <%%- if params[:oauth_callback] -%>
6
+ <%%= hidden_field_tag "oauth_callback", params[:oauth_callback] %>
7
+ <%%- end -%>
8
+ <p>
9
+ <%%= check_box_tag 'authorize' %> authorize access
10
+ </p>
11
+ <p>
12
+ <%%= submit_tag %>
13
+ </p>
14
+ <%% end %>
@@ -0,0 +1,16 @@
1
+ %h1 Authorize access to your account
2
+ %p
3
+ Would you like to authorize
4
+ = link_to @token.client_application.name,@token.client_application.url
5
+ (
6
+ = link_to @token.client_application.url,@token.client_application.url
7
+ ) to access your account?
8
+ - form_tag authorize_url do
9
+ = hidden_field_tag "oauth_token", @token.token
10
+ - if params[:oauth_callback]
11
+ = hidden_field_tag "oauth_callback", params[:oauth_callback]
12
+ %p
13
+ = check_box_tag 'authorize'
14
+ authorize access
15
+ %p
16
+ = submit_tag
@@ -0,0 +1 @@
1
+ <h1>You have disallowed this request</h1>
@@ -0,0 +1 @@
1
+ %h1 You have disallowed this request
@@ -0,0 +1 @@
1
+ <h1>You have allowed this request</h1>
@@ -0,0 +1 @@
1
+ %h1 You have allowed this request
@@ -0,0 +1,55 @@
1
+ require 'oauth'
2
+ class ClientApplication < ActiveRecord::Base
3
+ belongs_to :user
4
+ has_many :tokens, :class_name => "OauthToken"
5
+ validates_presence_of :name, :url, :key, :secret
6
+ validates_uniqueness_of :key
7
+ before_validation_on_create :generate_keys
8
+
9
+ validates_format_of :url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
10
+ validates_format_of :support_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
11
+ validates_format_of :callback_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
12
+
13
+ attr_accessor :token_callback_url
14
+
15
+ def self.find_token(token_key)
16
+ token = OauthToken.find_by_token(token_key, :include => :client_application)
17
+ if token && token.authorized?
18
+ token
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ def self.verify_request(request, options = {}, &block)
25
+ begin
26
+ signature = OAuth::Signature.build(request, options, &block)
27
+ return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
28
+ value = signature.verify
29
+ value
30
+ rescue OAuth::Signature::UnknownSignatureMethod => e
31
+ logger.info "ERROR"+e.to_s
32
+ false
33
+ end
34
+ end
35
+
36
+ def oauth_server
37
+ @oauth_server ||= OAuth::Server.new("http://your.site")
38
+ end
39
+
40
+ def credentials
41
+ @oauth_client ||= OAuth::Consumer.new(key, secret)
42
+ end
43
+
44
+ def create_request_token
45
+ RequestToken.create :client_application => self,:callback_url=>self.token_callback_url
46
+ end
47
+
48
+ protected
49
+
50
+ def generate_keys
51
+ oauth_client = oauth_server.generate_consumer_credentials
52
+ self.key = oauth_client.key[0,20]
53
+ self.secret = oauth_client.secret[0,40]
54
+ end
55
+ 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,42 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ module OAuthHelpers
3
+
4
+ def create_consumer
5
+ @consumer=OAuth::Consumer.new(@application.key,@application.secret,
6
+ {
7
+ :site=>@application.oauth_server.base_url
8
+ })
9
+ end
10
+
11
+ end
12
+
13
+ class ClientApplicationTest < ActiveSupport::TestCase
14
+ include OAuthHelpers
15
+ fixtures :users,:client_applications,:oauth_tokens
16
+
17
+ def setup
18
+ @application = ClientApplication.create :name=>"Agree2",:url=>"http://agree2.com",:user=>users(:quentin)
19
+ create_consumer
20
+ end
21
+
22
+ def test_should_be_valid
23
+ assert @application.valid?
24
+ end
25
+
26
+
27
+ def test_should_not_have_errors
28
+ assert_equal [], @application.errors.full_messages
29
+ end
30
+
31
+ def test_should_have_key_and_secret
32
+ assert_not_nil @application.key
33
+ assert_not_nil @application.secret
34
+ end
35
+
36
+ def test_should_have_credentials
37
+ assert_not_nil @application.credentials
38
+ assert_equal @application.key, @application.credentials.key
39
+ assert_equal @application.secret, @application.credentials.secret
40
+ end
41
+
42
+ end
@@ -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: MyString
6
+ support_url: MyString
7
+ callback_url: MyString
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: MyString
17
+ support_url: MyString
18
+ callback_url: MyString
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,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