panjiva-oauth-plugin 0.4.1
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.
- checksums.yaml +15 -0
- data/.gitignore +12 -0
- data/CHANGELOG +178 -0
- data/Gemfile +27 -0
- data/Guardfile +8 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +531 -0
- data/Rakefile +2 -0
- data/UPGRADE.rdoc +21 -0
- data/generators/oauth_consumer/USAGE +10 -0
- data/generators/oauth_consumer/oauth_consumer_generator.rb +50 -0
- data/generators/oauth_consumer/templates/consumer_token.rb +11 -0
- data/generators/oauth_consumer/templates/controller.rb +27 -0
- data/generators/oauth_consumer/templates/index.html.erb +29 -0
- data/generators/oauth_consumer/templates/index.html.haml +18 -0
- data/generators/oauth_consumer/templates/migration.rb +20 -0
- data/generators/oauth_consumer/templates/oauth_config.rb +73 -0
- data/generators/oauth_consumer/templates/show.html.erb +7 -0
- data/generators/oauth_consumer/templates/show.html.haml +8 -0
- data/generators/oauth_provider/USAGE +20 -0
- data/generators/oauth_provider/lib/insert_routes.rb +67 -0
- data/generators/oauth_provider/oauth_provider_generator.rb +127 -0
- data/generators/oauth_provider/templates/_form.html.erb +17 -0
- data/generators/oauth_provider/templates/_form.html.haml +21 -0
- data/generators/oauth_provider/templates/access_token.rb +16 -0
- data/generators/oauth_provider/templates/authorize.html.erb +14 -0
- data/generators/oauth_provider/templates/authorize.html.haml +16 -0
- data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
- data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
- data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
- data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
- data/generators/oauth_provider/templates/client_application.rb +57 -0
- data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
- data/generators/oauth_provider/templates/client_application_test.rb +42 -0
- data/generators/oauth_provider/templates/client_applications.yml +23 -0
- data/generators/oauth_provider/templates/clients_controller.rb +52 -0
- data/generators/oauth_provider/templates/clients_controller_spec.rb +176 -0
- data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
- data/generators/oauth_provider/templates/controller.rb +23 -0
- data/generators/oauth_provider/templates/edit.html.erb +7 -0
- data/generators/oauth_provider/templates/edit.html.haml +4 -0
- data/generators/oauth_provider/templates/index.html.erb +43 -0
- data/generators/oauth_provider/templates/index.html.haml +39 -0
- data/generators/oauth_provider/templates/migration.rb +47 -0
- data/generators/oauth_provider/templates/new.html.erb +5 -0
- data/generators/oauth_provider/templates/new.html.haml +5 -0
- 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 +20 -0
- data/generators/oauth_provider/templates/oauth2_token_spec.rb +52 -0
- data/generators/oauth_provider/templates/oauth2_verifier.rb +35 -0
- data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +44 -0
- data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
- data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
- data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
- data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
- data/generators/oauth_provider/templates/oauth_token.rb +30 -0
- data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
- data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
- data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
- data/generators/oauth_provider/templates/request_token.rb +40 -0
- data/generators/oauth_provider/templates/show.html.erb +27 -0
- data/generators/oauth_provider/templates/show.html.haml +30 -0
- data/init.rb +1 -0
- data/install.rb +2 -0
- 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 +20 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +35 -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 +23 -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 +41 -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 +20 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +35 -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 +31 -0
- data/lib/generators/oauth_consumer/templates/controller.rb +59 -0
- data/lib/generators/oauth_consumer/templates/oauth_config.rb +68 -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 +37 -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 +35 -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/oauth2_token_spec.rb +52 -0
- data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +44 -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 +33 -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/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 +24 -0
- data/lib/oauth-plugin/version.rb +5 -0
- data/lib/oauth/controllers/application_controller_methods.rb +136 -0
- data/lib/oauth/controllers/consumer_controller.rb +150 -0
- data/lib/oauth/controllers/provider_controller.rb +181 -0
- data/lib/oauth/models/consumers/service_loader.rb +28 -0
- data/lib/oauth/models/consumers/services/agree2_token.rb +15 -0
- data/lib/oauth/models/consumers/services/fireeagle_token.rb +39 -0
- data/lib/oauth/models/consumers/services/google_token.rb +21 -0
- data/lib/oauth/models/consumers/services/oauth2_token.rb +27 -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/services/twitter_token.rb +24 -0
- data/lib/oauth/models/consumers/simple_client.rb +50 -0
- data/lib/oauth/models/consumers/token.rb +93 -0
- data/lib/oauth/provider/authorizer.rb +83 -0
- data/lib/oauth/rack/oauth_filter.rb +93 -0
- data/oauth-plugin.gemspec +39 -0
- data/rails/init.rb +1 -0
- data/spec/dummy_provider_models.rb +53 -0
- data/spec/oauth/provider/authorizer_spec.rb +202 -0
- data/spec/rack/oauth_filter_spec.rb +244 -0
- data/spec/spec_helper.rb +3 -0
- data/tasks/oauth_tasks.rake +4 -0
- data/uninstall.rb +1 -0
- metadata +362 -0
data/Rakefile
ADDED
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
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
./script/generate oauth_consumer
|
|
2
|
+
|
|
3
|
+
This creates an OAuth Provider controller as well as requisite models.
|
|
4
|
+
|
|
5
|
+
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".
|
|
6
|
+
|
|
7
|
+
If you generated the migration file (true by default), make sure you run
|
|
8
|
+
rake db:migrate
|
|
9
|
+
|
|
10
|
+
See README.rdoc for more.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../oauth_provider/lib/insert_routes.rb")
|
|
2
|
+
|
|
3
|
+
class OauthConsumerGenerator < Rails::Generator::Base
|
|
4
|
+
default_options :skip_migration => false
|
|
5
|
+
|
|
6
|
+
def manifest
|
|
7
|
+
record do |m|
|
|
8
|
+
|
|
9
|
+
# Controller, helper, views, and test directories.
|
|
10
|
+
m.directory File.join('app/models')
|
|
11
|
+
m.directory File.join('app/controllers')
|
|
12
|
+
m.directory File.join('app/helpers')
|
|
13
|
+
m.directory File.join('app/views', 'oauth_consumers')
|
|
14
|
+
m.directory File.join('config/initializers')
|
|
15
|
+
|
|
16
|
+
m.template 'oauth_config.rb',File.join('config/initializers', "oauth_consumers.rb")
|
|
17
|
+
m.template 'consumer_token.rb',File.join('app/models',"consumer_token.rb")
|
|
18
|
+
|
|
19
|
+
m.template 'controller.rb',File.join('app/controllers',"oauth_consumers_controller.rb")
|
|
20
|
+
m.route_entry "map.resources :oauth_consumers,:member=>{:callback=>:get}"
|
|
21
|
+
|
|
22
|
+
@template_extension= options[:haml] ? "haml" : "erb"
|
|
23
|
+
|
|
24
|
+
m.template "show.html.#{@template_extension}", File.join('app/views', 'oauth_consumers', "show.html.#{@template_extension}")
|
|
25
|
+
m.template "index.html.#{@template_extension}", File.join('app/views', 'oauth_consumers', "index.html.#{@template_extension}")
|
|
26
|
+
|
|
27
|
+
unless options[:skip_migration]
|
|
28
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
|
29
|
+
:migration_name => "CreateOauthConsumerTokens"
|
|
30
|
+
}, :migration_file_name => "create_oauth_consumer_tokens"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
protected
|
|
36
|
+
def banner
|
|
37
|
+
"Usage: #{$0} #{spec.name}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_options!(opt)
|
|
41
|
+
opt.separator ''
|
|
42
|
+
opt.separator 'Options:'
|
|
43
|
+
opt.on("--skip-migration",
|
|
44
|
+
"Don't generate a migration file") { |v| options[:skip_migration] = v }
|
|
45
|
+
# opt.on("--test-unit",
|
|
46
|
+
# "Generate the Test::Unit compatible tests instead of RSpec") { |v| options[:test_unit] = v }
|
|
47
|
+
opt.on("--haml",
|
|
48
|
+
"Templates use haml") { |v| options[:haml] = v }
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'oauth/models/consumers/token'
|
|
2
|
+
class ConsumerToken < ActiveRecord::Base
|
|
3
|
+
include Oauth::Models::Consumers::Token
|
|
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
|
+
|
|
11
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'oauth/controllers/consumer_controller'
|
|
2
|
+
class OauthConsumersController < ApplicationController
|
|
3
|
+
include Oauth::Controllers::ConsumerController
|
|
4
|
+
|
|
5
|
+
def index
|
|
6
|
+
@consumer_tokens=ConsumerToken.all :conditions => {:user_id => current_user.id}
|
|
7
|
+
@services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def callback
|
|
11
|
+
super
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def client
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
# Change this to decide where you want to redirect user to after callback is finished.
|
|
21
|
+
# params[:id] holds the service name so you could use this to redirect to various parts
|
|
22
|
+
# of your application depending on what service you're connecting to.
|
|
23
|
+
def go_back
|
|
24
|
+
redirect_to root_url
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<h1>Services</h1>
|
|
2
|
+
|
|
3
|
+
<%% if @consumer_tokens.empty? %>
|
|
4
|
+
<p>
|
|
5
|
+
You are currently not connected to any external services.
|
|
6
|
+
</p>
|
|
7
|
+
<%% else %>
|
|
8
|
+
<p>
|
|
9
|
+
You are connected to the following services:
|
|
10
|
+
</p>
|
|
11
|
+
<ul>
|
|
12
|
+
<%% @consumer_tokens.each do |token| %>
|
|
13
|
+
<li>
|
|
14
|
+
<%%= link_to token.class.service_name.to_s.humanize, oauth_consumer_path(token.class.service_name) %>
|
|
15
|
+
</li>
|
|
16
|
+
<%% end %>
|
|
17
|
+
</ul>
|
|
18
|
+
<%% end %>
|
|
19
|
+
|
|
20
|
+
<%% unless @services.empty? %>
|
|
21
|
+
<h3>You can connect to the following services:</h3>
|
|
22
|
+
<ul>
|
|
23
|
+
<%% @services.each do |service| %>
|
|
24
|
+
<li>
|
|
25
|
+
<%%= link_to service.to_s.humanize, oauth_consumer_path(service) %>
|
|
26
|
+
</li>
|
|
27
|
+
<%% end %>
|
|
28
|
+
</ul>
|
|
29
|
+
<%% end %>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
%h1 Services
|
|
2
|
+
|
|
3
|
+
-if @consumer_tokens.empty?
|
|
4
|
+
%p
|
|
5
|
+
You are currently not connected to any external services.
|
|
6
|
+
-else
|
|
7
|
+
%p You are connected to the following services:
|
|
8
|
+
%ul
|
|
9
|
+
-@consumer_tokens.each do |token|
|
|
10
|
+
%li
|
|
11
|
+
=link_to token.class.service_name.to_s.humanize, oauth_consumer_path(token.class.service_name)
|
|
12
|
+
|
|
13
|
+
-unless @services.empty?
|
|
14
|
+
%h3 You can connect to the following services:
|
|
15
|
+
%ul
|
|
16
|
+
-@services.each do |service|
|
|
17
|
+
%li
|
|
18
|
+
=link_to service.to_s.humanize,oauth_consumer_path(service)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class CreateOauthConsumerTokens < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
|
|
4
|
+
create_table :consumer_tokens do |t|
|
|
5
|
+
t.integer :user_id
|
|
6
|
+
t.string :type, :limit => 30
|
|
7
|
+
t.string :token, :limit => 1024 # This has to be huge because of Yahoo's excessively large tokens
|
|
8
|
+
t.string :secret
|
|
9
|
+
t.timestamps
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
add_index :consumer_tokens, :token, :unique => true, :length => 100
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.down
|
|
17
|
+
drop_table :consumer_tokens
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
# :oauth_version => 2,
|
|
30
|
+
# :super_class => 'Oauth2Token' # unnecessary if you have an explicit "class FacebookToken < Oauth2Token",
|
|
31
|
+
# :options => {
|
|
32
|
+
# :site => "https://graph.facebook.com"
|
|
33
|
+
# }
|
|
34
|
+
# },
|
|
35
|
+
# :agree2 => {
|
|
36
|
+
# :key => "",
|
|
37
|
+
# :secret => ""
|
|
38
|
+
# },
|
|
39
|
+
# :fireeagle => {
|
|
40
|
+
# :key => "",
|
|
41
|
+
# :secret => ""
|
|
42
|
+
# },
|
|
43
|
+
# :oauth2_server => {
|
|
44
|
+
# :key => "",
|
|
45
|
+
# :secret => "",
|
|
46
|
+
# :oauth_version => 2
|
|
47
|
+
# :options => { # OAuth::Consumer options
|
|
48
|
+
# :site => "http://hourfeed.com" # Remember to add a site for a generic OAuth site
|
|
49
|
+
# }
|
|
50
|
+
# },
|
|
51
|
+
# :hour_feed => {
|
|
52
|
+
# :key => "",
|
|
53
|
+
# :secret => "",
|
|
54
|
+
# :options => { # OAuth::Consumer options
|
|
55
|
+
# :site => "http://hourfeed.com" # Remember to add a site for a generic OAuth site
|
|
56
|
+
# }
|
|
57
|
+
# },
|
|
58
|
+
# :nu_bux => {
|
|
59
|
+
# :key => "",
|
|
60
|
+
# :secret => "",
|
|
61
|
+
# :super_class => "OpenTransactToken", # if a OAuth service follows a particular standard
|
|
62
|
+
# # with a token implementation you can set the superclass
|
|
63
|
+
# # to use
|
|
64
|
+
# :options => { # OAuth::Consumer options
|
|
65
|
+
# :site => "http://nubux.heroku.com"
|
|
66
|
+
# }
|
|
67
|
+
# }
|
|
68
|
+
# }
|
|
69
|
+
#
|
|
70
|
+
OAUTH_CREDENTIALS = {
|
|
71
|
+
} unless defined? OAUTH_CREDENTIALS
|
|
72
|
+
|
|
73
|
+
load 'oauth/models/consumers/service_loader.rb'
|
|
@@ -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,127 @@
|
|
|
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 'oauth2_token.rb', File.join('app/models',"oauth2_token.rb")
|
|
47
|
+
m.template 'oauth2_verifier.rb', File.join('app/models',"oauth2_verifier.rb")
|
|
48
|
+
m.template 'oauth_nonce.rb', File.join('app/models',"oauth_nonce.rb")
|
|
49
|
+
|
|
50
|
+
m.template 'controller.rb',File.join('app/controllers',controller_class_path,"#{controller_file_name}_controller.rb")
|
|
51
|
+
|
|
52
|
+
m.template 'clients_controller.rb',File.join('app/controllers',controller_class_path,"#{controller_file_name}_clients_controller.rb")
|
|
53
|
+
m.route_name 'oauth', '/oauth',:controller=>'oauth',:action=>'index'
|
|
54
|
+
m.route_name 'authorize', '/oauth/authorize',:controller=>'oauth',:action=>'authorize'
|
|
55
|
+
m.route_name 'request_token', '/oauth/request_token',:controller=>'oauth',:action=>'request_token'
|
|
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'
|
|
58
|
+
m.route_name 'test_request', '/oauth/test_request',:controller=>'oauth',:action=>'test_request'
|
|
59
|
+
|
|
60
|
+
m.route_resources "#{controller_file_name}_clients".to_sym
|
|
61
|
+
|
|
62
|
+
if !options[:test_unit]
|
|
63
|
+
m.directory File.join('spec')
|
|
64
|
+
m.directory File.join('spec/models')
|
|
65
|
+
m.directory File.join('spec/fixtures', class_path)
|
|
66
|
+
m.directory File.join('spec/controllers', controller_class_path)
|
|
67
|
+
|
|
68
|
+
m.template 'client_application_spec.rb',File.join('spec/models',"client_application_spec.rb")
|
|
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")
|
|
72
|
+
m.template 'oauth_nonce_spec.rb', File.join('spec/models',"oauth_nonce_spec.rb")
|
|
73
|
+
m.template 'client_applications.yml',File.join('spec/fixtures',"client_applications.yml")
|
|
74
|
+
m.template 'oauth_tokens.yml', File.join('spec/fixtures',"oauth_tokens.yml")
|
|
75
|
+
m.template 'oauth_nonces.yml', File.join('spec/fixtures',"oauth_nonces.yml")
|
|
76
|
+
m.template 'clients_controller_spec.rb',File.join('spec/controllers',controller_class_path,"#{controller_file_name}_clients_controller_spec.rb")
|
|
77
|
+
else
|
|
78
|
+
m.directory File.join('test')
|
|
79
|
+
m.directory File.join('test/unit')
|
|
80
|
+
m.directory File.join('test/fixtures', class_path)
|
|
81
|
+
m.directory File.join('test/functional', controller_class_path)
|
|
82
|
+
m.template 'client_application_test.rb',File.join('test/unit',"client_application_test.rb")
|
|
83
|
+
m.template 'oauth_token_test.rb', File.join('test/unit',"oauth_token_test.rb")
|
|
84
|
+
m.template 'oauth_nonce_test.rb', File.join('test/unit',"oauth_nonce_test.rb")
|
|
85
|
+
m.template 'client_applications.yml',File.join('test/fixtures',"client_applications.yml")
|
|
86
|
+
m.template 'oauth_tokens.yml', File.join('test/fixtures',"oauth_tokens.yml")
|
|
87
|
+
m.template 'oauth_nonces.yml', File.join('test/fixtures',"oauth_nonces.yml")
|
|
88
|
+
m.template 'clients_controller_test.rb',File.join('test/functional',controller_class_path,"#{controller_file_name}_clients_controller_test.rb")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@template_extension= options[:haml] ? "haml" : "erb"
|
|
93
|
+
|
|
94
|
+
m.template "_form.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "_form.html.#{@template_extension}")
|
|
95
|
+
m.template "new.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "new.html.#{@template_extension}")
|
|
96
|
+
m.template "index.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "index.html.#{@template_extension}")
|
|
97
|
+
m.template "show.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "show.html.#{@template_extension}")
|
|
98
|
+
m.template "edit.html.#{@template_extension}", File.join('app/views', controller_class_path, 'oauth_clients', "edit.html.#{@template_extension}")
|
|
99
|
+
m.template "authorize.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize.html.#{@template_extension}")
|
|
100
|
+
m.template "oauth2_authorize.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "oauth2_authorize.html.#{@template_extension}")
|
|
101
|
+
m.template "authorize_success.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_success.html.#{@template_extension}")
|
|
102
|
+
m.template "authorize_failure.html.#{@template_extension}", File.join('app/views', controller_class_path, controller_file_name, "authorize_failure.html.#{@template_extension}")
|
|
103
|
+
|
|
104
|
+
unless options[:skip_migration]
|
|
105
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
|
106
|
+
:migration_name => "CreateOauthTables"
|
|
107
|
+
}, :migration_file_name => "create_oauth_tables"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
protected
|
|
113
|
+
def banner
|
|
114
|
+
"Usage: #{$0} #{spec.name}"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def add_options!(opt)
|
|
118
|
+
opt.separator ''
|
|
119
|
+
opt.separator 'Options:'
|
|
120
|
+
opt.on("--skip-migration",
|
|
121
|
+
"Don't generate a migration file") { |v| options[:skip_migration] = v }
|
|
122
|
+
opt.on("--test-unit",
|
|
123
|
+
"Generate the Test::Unit compatible tests instead of RSpec") { |v| options[:test_unit] = v }
|
|
124
|
+
opt.on("--haml",
|
|
125
|
+
"Templates use haml") { |v| options[:haml] = v }
|
|
126
|
+
end
|
|
127
|
+
end
|