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 +131 -0
@@ -0,0 +1,18 @@
1
+ # Goes through the entries in your OAUTH_CREDENTIALS and either loads the class required
2
+ # or subclasses ConsumerToken with the name.
3
+ #
4
+ # So an entry called "my_service" will create a class MyServiceToken which you can
5
+ # connect with has_one to your user model.
6
+ if defined? ConsumerToken && defined? OAUTH_CREDENTIALS
7
+ OAUTH_CREDENTIALS.each do |key, value|
8
+ class_name=value[:class_name]||"#{key.to_s.classify}Token"
9
+ unless Object.const_defined?(class_name.to_sym)
10
+ if File.exists?(File.join(File.dirname(__FILE__), "services","#{key.to_s}_token.rb"))
11
+ require File.join(File.dirname(__FILE__), "services","#{key.to_s}_token")
12
+ else
13
+ super_class = value[:super_class]||"ConsumerToken"
14
+ eval "class #{class_name} < #{super_class} ;end"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'agree2'
2
+ class Agree2Token < ConsumerToken
3
+ def self.agree2_client
4
+ @agree2_client||=Agree2::Client.new OAUTH_CREDENTIALS[:agree2][:key],OAUTH_CREDENTIALS[:agree2][:secret]
5
+ end
6
+
7
+ def self.consumer
8
+ agree2_client.consumer
9
+ end
10
+
11
+ def client
12
+ @client||=Agree2Token.agree2_client.user(:token=>token,:secret=>secret)
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require 'twitter'
2
+ class TwitterToken < ConsumerToken
3
+ def self.twitter
4
+ @twitter||=Twitter::OAuth.new( OAUTH_CREDENTIALS[:twitter][:key],OAUTH_CREDENTIALS[:twitter][:secret]).consumer
5
+ end
6
+
7
+ def self.consumer
8
+ @twitter.consumer
9
+ end
10
+
11
+ def client
12
+ unless @client
13
+ @client=TwitterToken.twitter.clone
14
+ @client.authorize_from_access token,secret
15
+ end
16
+
17
+ @client
18
+ end
19
+ end
@@ -0,0 +1,60 @@
1
+ require 'oauth/consumer'
2
+ module Oauth
3
+ module Models
4
+ module Consumers
5
+ module Token
6
+ def self.included(model)
7
+ model.class_eval do
8
+ belongs_to :user
9
+ validates_presence_of :user, :token, :secret
10
+ end
11
+
12
+ model.send(:include, InstanceMethods)
13
+ model.send(:extend, ClassMethods)
14
+
15
+ end
16
+
17
+ module ClassMethods
18
+
19
+ def service_name
20
+ @service_name||=self.to_s.underscore.scan(/^(.*?)(_token)?$/)[0][0].to_sym
21
+ end
22
+
23
+ def consumer
24
+ @consumer||=OAuth::Consumer.new credentials[:key],credentials[:secret],credentials[:options]
25
+ end
26
+
27
+ def get_request_token(callback_url)
28
+ consumer.get_request_token(:oauth_callback=>callback_url)
29
+ end
30
+
31
+ def create_from_request_token(user,token,secret,oauth_verifier)
32
+ logger.info "create_from_request_token"
33
+ request_token=OAuth::RequestToken.new consumer,token,secret
34
+ access_token=request_token.get_access_token :oauth_verifier=>oauth_verifier
35
+ logger.info self.inspect
36
+ logger.info user.inspect
37
+ create :user_id=>user.id,:token=>access_token.token,:secret=>access_token.secret
38
+ end
39
+
40
+ private
41
+
42
+ def credentials
43
+ @credentials||=OAUTH_CREDENTIALS[service_name]
44
+ end
45
+
46
+ end
47
+
48
+ module InstanceMethods
49
+
50
+ # Main client for interfacing with remote service. Override this to use
51
+ # preexisting library eg. Twitter gem.
52
+ def client
53
+ @client||=OAuth::AccessToken.new self.class.consumer,token,secret
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,104 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{oauth-plugin}
5
+ s.version = "0.3.5"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Pelle Braendgaard"]
9
+ s.date = %q{2009-07-21}
10
+ s.description = %q{Rails plugin for implementing an OAuth Provider or Consumer}
11
+ s.email = %q{oauth-ruby@googlegroups.com}
12
+ s.extra_rdoc_files = [
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".gitignore",
17
+ "CHANGELOG",
18
+ "MIT-LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "generators/oauth_consumer/USAGE",
23
+ "generators/oauth_consumer/oauth_consumer_generator.rb",
24
+ "generators/oauth_consumer/templates/consumer_token.rb",
25
+ "generators/oauth_consumer/templates/controller.rb",
26
+ "generators/oauth_consumer/templates/migration.rb",
27
+ "generators/oauth_consumer/templates/oauth_config.rb",
28
+ "generators/oauth_consumer/templates/show.html.erb",
29
+ "generators/oauth_consumer/templates/show.html.haml",
30
+ "generators/oauth_provider/USAGE",
31
+ "generators/oauth_provider/lib/insert_routes.rb",
32
+ "generators/oauth_provider/oauth_provider_generator.rb",
33
+ "generators/oauth_provider/templates/_form.html.erb",
34
+ "generators/oauth_provider/templates/_form.html.haml",
35
+ "generators/oauth_provider/templates/access_token.rb",
36
+ "generators/oauth_provider/templates/authorize.html.erb",
37
+ "generators/oauth_provider/templates/authorize.html.haml",
38
+ "generators/oauth_provider/templates/authorize_failure.html.erb",
39
+ "generators/oauth_provider/templates/authorize_failure.html.haml",
40
+ "generators/oauth_provider/templates/authorize_success.html.erb",
41
+ "generators/oauth_provider/templates/authorize_success.html.haml",
42
+ "generators/oauth_provider/templates/client_application.rb",
43
+ "generators/oauth_provider/templates/client_application_spec.rb",
44
+ "generators/oauth_provider/templates/client_application_test.rb",
45
+ "generators/oauth_provider/templates/client_applications.yml",
46
+ "generators/oauth_provider/templates/clients_controller.rb",
47
+ "generators/oauth_provider/templates/clients_controller_spec.rb",
48
+ "generators/oauth_provider/templates/clients_controller_test.rb",
49
+ "generators/oauth_provider/templates/controller.rb",
50
+ "generators/oauth_provider/templates/controller_spec.rb",
51
+ "generators/oauth_provider/templates/controller_spec_helper.rb",
52
+ "generators/oauth_provider/templates/controller_test.rb",
53
+ "generators/oauth_provider/templates/controller_test_helper.rb",
54
+ "generators/oauth_provider/templates/edit.html.erb",
55
+ "generators/oauth_provider/templates/edit.html.haml",
56
+ "generators/oauth_provider/templates/index.html.erb",
57
+ "generators/oauth_provider/templates/index.html.haml",
58
+ "generators/oauth_provider/templates/migration.rb",
59
+ "generators/oauth_provider/templates/new.html.erb",
60
+ "generators/oauth_provider/templates/new.html.haml",
61
+ "generators/oauth_provider/templates/oauth_nonce.rb",
62
+ "generators/oauth_provider/templates/oauth_nonce_spec.rb",
63
+ "generators/oauth_provider/templates/oauth_nonce_test.rb",
64
+ "generators/oauth_provider/templates/oauth_nonces.yml",
65
+ "generators/oauth_provider/templates/oauth_token.rb",
66
+ "generators/oauth_provider/templates/oauth_token_spec.rb",
67
+ "generators/oauth_provider/templates/oauth_token_test.rb",
68
+ "generators/oauth_provider/templates/oauth_tokens.yml",
69
+ "generators/oauth_provider/templates/request_token.rb",
70
+ "generators/oauth_provider/templates/show.html.erb",
71
+ "generators/oauth_provider/templates/show.html.haml",
72
+ "init.rb",
73
+ "install.rb",
74
+ "lib/oauth/controllers/application_controller_methods.rb",
75
+ "lib/oauth/controllers/consumer_controller.rb",
76
+ "lib/oauth/controllers/provider_controller.rb",
77
+ "lib/oauth/models/consumers/service_loader.rb",
78
+ "lib/oauth/models/consumers/services/agree2_token.rb",
79
+ "lib/oauth/models/consumers/services/twitter_token.rb",
80
+ "lib/oauth/models/consumers/token.rb",
81
+ "oauth-plugin.gemspec",
82
+ "tasks/oauth_tasks.rake",
83
+ "uninstall.rb"
84
+ ]
85
+ s.homepage = %q{http://github.com/pelle/oauth-plugin/tree/master}
86
+ s.rdoc_options = ["--charset=UTF-8"]
87
+ s.require_paths = ["lib"]
88
+ s.rubyforge_project = %q{oauth}
89
+ s.rubygems_version = %q{1.3.4}
90
+ s.summary = %q{Ruby on Rails Plugin for OAuth Provider and Consumer}
91
+
92
+ if s.respond_to? :specification_version then
93
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
94
+ s.specification_version = 3
95
+
96
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
97
+ s.add_runtime_dependency(%q<oauth>, [">= 0.3.5"])
98
+ else
99
+ s.add_dependency(%q<oauth>, [">= 0.3.5"])
100
+ end
101
+ else
102
+ s.add_dependency(%q<oauth>, [">= 0.3.5"])
103
+ end
104
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :oauth do
3
+ # # Task goes here
4
+ # end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth-plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.5
5
+ platform: ruby
6
+ authors:
7
+ - Pelle Braendgaard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-21 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oauth
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.5
24
+ version:
25
+ description: Rails plugin for implementing an OAuth Provider or Consumer
26
+ email: oauth-ruby@googlegroups.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - .gitignore
35
+ - CHANGELOG
36
+ - MIT-LICENSE
37
+ - README.rdoc
38
+ - Rakefile
39
+ - VERSION
40
+ - generators/oauth_consumer/USAGE
41
+ - generators/oauth_consumer/oauth_consumer_generator.rb
42
+ - generators/oauth_consumer/templates/consumer_token.rb
43
+ - generators/oauth_consumer/templates/controller.rb
44
+ - generators/oauth_consumer/templates/migration.rb
45
+ - generators/oauth_consumer/templates/oauth_config.rb
46
+ - generators/oauth_consumer/templates/show.html.erb
47
+ - generators/oauth_consumer/templates/show.html.haml
48
+ - generators/oauth_provider/USAGE
49
+ - generators/oauth_provider/lib/insert_routes.rb
50
+ - generators/oauth_provider/oauth_provider_generator.rb
51
+ - generators/oauth_provider/templates/_form.html.erb
52
+ - generators/oauth_provider/templates/_form.html.haml
53
+ - generators/oauth_provider/templates/access_token.rb
54
+ - generators/oauth_provider/templates/authorize.html.erb
55
+ - generators/oauth_provider/templates/authorize.html.haml
56
+ - generators/oauth_provider/templates/authorize_failure.html.erb
57
+ - generators/oauth_provider/templates/authorize_failure.html.haml
58
+ - generators/oauth_provider/templates/authorize_success.html.erb
59
+ - generators/oauth_provider/templates/authorize_success.html.haml
60
+ - generators/oauth_provider/templates/client_application.rb
61
+ - generators/oauth_provider/templates/client_application_spec.rb
62
+ - generators/oauth_provider/templates/client_application_test.rb
63
+ - generators/oauth_provider/templates/client_applications.yml
64
+ - generators/oauth_provider/templates/clients_controller.rb
65
+ - generators/oauth_provider/templates/clients_controller_spec.rb
66
+ - generators/oauth_provider/templates/clients_controller_test.rb
67
+ - generators/oauth_provider/templates/controller.rb
68
+ - generators/oauth_provider/templates/controller_spec.rb
69
+ - generators/oauth_provider/templates/controller_spec_helper.rb
70
+ - generators/oauth_provider/templates/controller_test.rb
71
+ - generators/oauth_provider/templates/controller_test_helper.rb
72
+ - generators/oauth_provider/templates/edit.html.erb
73
+ - generators/oauth_provider/templates/edit.html.haml
74
+ - generators/oauth_provider/templates/index.html.erb
75
+ - generators/oauth_provider/templates/index.html.haml
76
+ - generators/oauth_provider/templates/migration.rb
77
+ - generators/oauth_provider/templates/new.html.erb
78
+ - generators/oauth_provider/templates/new.html.haml
79
+ - generators/oauth_provider/templates/oauth_nonce.rb
80
+ - generators/oauth_provider/templates/oauth_nonce_spec.rb
81
+ - generators/oauth_provider/templates/oauth_nonce_test.rb
82
+ - generators/oauth_provider/templates/oauth_nonces.yml
83
+ - generators/oauth_provider/templates/oauth_token.rb
84
+ - generators/oauth_provider/templates/oauth_token_spec.rb
85
+ - generators/oauth_provider/templates/oauth_token_test.rb
86
+ - generators/oauth_provider/templates/oauth_tokens.yml
87
+ - generators/oauth_provider/templates/request_token.rb
88
+ - generators/oauth_provider/templates/show.html.erb
89
+ - generators/oauth_provider/templates/show.html.haml
90
+ - init.rb
91
+ - install.rb
92
+ - lib/oauth/controllers/application_controller_methods.rb
93
+ - lib/oauth/controllers/consumer_controller.rb
94
+ - lib/oauth/controllers/provider_controller.rb
95
+ - lib/oauth/models/consumers/service_loader.rb
96
+ - lib/oauth/models/consumers/services/agree2_token.rb
97
+ - lib/oauth/models/consumers/services/twitter_token.rb
98
+ - lib/oauth/models/consumers/token.rb
99
+ - oauth-plugin.gemspec
100
+ - tasks/oauth_tasks.rake
101
+ - uninstall.rb
102
+ has_rdoc: true
103
+ homepage: http://github.com/pelle/oauth-plugin/tree/master
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --charset=UTF-8
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "0"
116
+ version:
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: "0"
122
+ version:
123
+ requirements: []
124
+
125
+ rubyforge_project: oauth
126
+ rubygems_version: 1.3.4
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Ruby on Rails Plugin for OAuth Provider and Consumer
130
+ test_files: []
131
+