le1t0-oauth-plugin 0.3.14.001 → 0.4.0.pre4.001
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG +20 -0
- data/Gemfile +4 -0
- data/README.rdoc +57 -12
- data/Rakefile +2 -43
- data/UPGRADE.rdoc +21 -0
- data/generators/oauth_consumer/templates/consumer_token.rb +6 -0
- data/generators/oauth_consumer/templates/controller.rb +4 -0
- data/generators/oauth_consumer/templates/migration.rb +1 -1
- data/generators/oauth_provider/oauth_provider_generator.rb +6 -0
- data/generators/oauth_provider/templates/access_token.rb +2 -2
- data/generators/oauth_provider/templates/client_application.rb +8 -6
- data/generators/oauth_provider/templates/client_applications.yml +6 -6
- data/generators/oauth_provider/templates/clients_controller_spec.rb +130 -193
- data/generators/oauth_provider/templates/controller.rb +12 -0
- data/generators/oauth_provider/templates/controller_spec.rb +762 -291
- data/generators/oauth_provider/templates/controller_spec_helper.rb +49 -63
- data/generators/oauth_provider/templates/migration.rb +6 -5
- data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
- data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
- data/generators/oauth_provider/templates/oauth2_token.rb +6 -0
- data/generators/oauth_provider/templates/oauth2_token_spec.rb +29 -0
- data/generators/oauth_provider/templates/oauth2_verifier.rb +28 -0
- data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +54 -0
- data/generators/oauth_provider/templates/oauth_token.rb +3 -4
- data/generators/oauth_provider/templates/request_token.rb +1 -1
- data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
- data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +11 -0
- data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
- data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
- data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
- data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
- data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +5 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +28 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
- data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
- data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
- data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
- data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
- data/lib/generators/erb/oauth_provider_generator.rb +21 -0
- data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
- data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
- data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
- data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
- data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
- data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
- data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
- data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
- data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
- data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
- data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
- data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
- data/lib/generators/haml/oauth_provider_generator.rb +28 -0
- data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
- data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
- data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
- data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
- data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
- data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
- data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
- data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
- data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
- data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
- data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +40 -0
- data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
- data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
- data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +5 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +25 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
- data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
- data/lib/generators/oauth_consumer/USAGE +11 -0
- data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +27 -0
- data/lib/generators/oauth_consumer/templates/controller.rb +50 -0
- data/lib/generators/oauth_consumer/templates/oauth_config.rb +47 -0
- data/lib/generators/oauth_inflections.rb +6 -0
- data/lib/generators/oauth_plugin.rb +0 -0
- data/lib/generators/oauth_provider/USAGE +18 -0
- data/lib/generators/oauth_provider/oauth_provider_generator.rb +47 -0
- data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
- data/lib/generators/oauth_provider/templates/controller.rb +23 -0
- data/lib/generators/rspec/oauth_provider_generator.rb +39 -0
- data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
- data/lib/generators/rspec/templates/client_applications.yml +23 -0
- data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
- data/lib/generators/rspec/templates/controller_spec.rb +838 -0
- data/lib/generators/rspec/templates/controller_spec_helper.rb +66 -0
- data/lib/generators/rspec/templates/oauth2_token_spec.rb +29 -0
- data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +54 -0
- data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
- data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
- data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
- data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
- data/lib/generators/test_unit/oauth_provider_generator.rb +37 -0
- data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
- data/lib/generators/test_unit/templates/client_applications.yml +23 -0
- data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
- data/lib/generators/test_unit/templates/controller_test.rb +310 -0
- data/lib/generators/test_unit/templates/controller_test_helper.rb +115 -0
- data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
- data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
- data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
- data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
- data/lib/oauth-plugin.rb +22 -1
- data/lib/oauth-plugin/version.rb +5 -0
- data/lib/oauth/controllers/application_controller_methods.rb +195 -66
- data/lib/oauth/controllers/consumer_controller.rb +18 -6
- data/lib/oauth/controllers/provider_controller.rb +153 -43
- data/lib/oauth/models/consumers/service_loader.rb +3 -0
- data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
- data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
- data/lib/oauth/models/consumers/token.rb +29 -5
- data/lib/oauth/rack/oauth_filter.rb +50 -0
- data/oauth-plugin.gemspec +13 -96
- data/rails/init.rb +1 -7
- metadata +123 -10
- data/VERSION +0 -1
@@ -0,0 +1,24 @@
|
|
1
|
+
# Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
|
2
|
+
# Thus you can use the same nonce with a different timestamp and viceversa.
|
3
|
+
class OauthNonce
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Timestamps
|
6
|
+
|
7
|
+
field :nonce, :type => String
|
8
|
+
field :timestamp, :type => Integer
|
9
|
+
|
10
|
+
index [
|
11
|
+
[:nonce, Mongo::ASCENDING],
|
12
|
+
[:timestamp, Mongo::ASCENDING]
|
13
|
+
], :unique => true
|
14
|
+
|
15
|
+
validates_presence_of :nonce, :timestamp
|
16
|
+
validates_uniqueness_of :nonce, :scope => :timestamp
|
17
|
+
|
18
|
+
# Remembers a nonce and it's associated timestamp. It returns false if it has already been used
|
19
|
+
def self.remember(nonce, timestamp)
|
20
|
+
oauth_nonce = OauthNonce.create(:nonce => nonce, :timestamp => timestamp)
|
21
|
+
return false if oauth_nonce.new_record?
|
22
|
+
oauth_nonce
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class OauthToken
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
|
5
|
+
field :token, :type => String
|
6
|
+
field :secret, :type => String
|
7
|
+
field :callback_url, :type => String
|
8
|
+
field :verifier, :type => String
|
9
|
+
field :scope, :type => String
|
10
|
+
field :authorized_at, :type => Time
|
11
|
+
field :invalidated_at, :type => Time
|
12
|
+
field :valid_to, :type => Time
|
13
|
+
|
14
|
+
index :token, :unique => true
|
15
|
+
|
16
|
+
referenced_in :user
|
17
|
+
referenced_in :client_application
|
18
|
+
|
19
|
+
validates_uniqueness_of :token
|
20
|
+
validates_presence_of :client_application, :token
|
21
|
+
before_validation :generate_keys, :on => :create
|
22
|
+
|
23
|
+
def invalidated?
|
24
|
+
!invalidated_at.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def invalidate!
|
28
|
+
update_attribute(:invalidated_at, Time.now)
|
29
|
+
end
|
30
|
+
|
31
|
+
def authorized?
|
32
|
+
!authorized_at.nil? && !invalidated?
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_query
|
36
|
+
"oauth_token=#{token}&oauth_token_secret=#{secret}"
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def generate_keys
|
41
|
+
self.token = OAuth::Helper.generate_key(40)[0,40]
|
42
|
+
self.secret = OAuth::Helper.generate_key(40)[0,40]
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class RequestToken < OauthToken
|
2
|
+
attr_accessor :provided_oauth_verifier
|
3
|
+
|
4
|
+
def authorize!(user)
|
5
|
+
return false if authorized?
|
6
|
+
self.user = user
|
7
|
+
self.authorized_at = Time.now
|
8
|
+
self.verifier = OAuth::Helper.generate_key(20)[0,20] unless oauth10?
|
9
|
+
self.save
|
10
|
+
end
|
11
|
+
|
12
|
+
def exchange!
|
13
|
+
return false unless authorized?
|
14
|
+
return false unless oauth10? || verifier == provided_oauth_verifier
|
15
|
+
|
16
|
+
AccessToken.create(:user => user, :client_application => client_application).tap do
|
17
|
+
invalidate!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_query
|
22
|
+
if oauth10?
|
23
|
+
super
|
24
|
+
else
|
25
|
+
"#{super}&oauth_callback_confirmed=true"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def oob?
|
30
|
+
self.callback_url == 'oob'
|
31
|
+
end
|
32
|
+
|
33
|
+
def oauth10?
|
34
|
+
(defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank?
|
35
|
+
end
|
36
|
+
end
|
@@ -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,27 @@
|
|
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
|
+
get :callback, :on => :member
|
23
|
+
end
|
24
|
+
ROUTE
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
protected
|
16
|
+
|
17
|
+
# Change this to decide where you want to redirect user to after callback is finished.
|
18
|
+
# params[:id] holds the service name so you could use this to redirect to various parts
|
19
|
+
# of your application depending on what service you're connecting to.
|
20
|
+
def go_back
|
21
|
+
redirect_to root_url
|
22
|
+
end
|
23
|
+
|
24
|
+
# The plugin requires logged_in? to return true or false if the user is logged in. Uncomment and
|
25
|
+
# call your auth frameworks equivalent below if different. eg. for devise:
|
26
|
+
#
|
27
|
+
# def logged_in?
|
28
|
+
# user_signed_in?
|
29
|
+
# end
|
30
|
+
|
31
|
+
# The plugin requires current_user to return the current logged in user. Uncomment and
|
32
|
+
# call your auth frameworks equivalent below if different.
|
33
|
+
# def current_user
|
34
|
+
# current_person
|
35
|
+
# end
|
36
|
+
|
37
|
+
# The plugin requires a way to log a user in. Call your auth frameworks equivalent below
|
38
|
+
# if different. eg. for devise:
|
39
|
+
#
|
40
|
+
# def current_user=(user)
|
41
|
+
# sign_in(user)
|
42
|
+
# end
|
43
|
+
|
44
|
+
# Override this to deny the user or redirect to a login screen depending on your framework and app
|
45
|
+
# if different. eg. for devise:
|
46
|
+
#
|
47
|
+
# def deny_access!
|
48
|
+
# raise Acl9::AccessDenied
|
49
|
+
# end
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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
|
+
# :allow_login => true # Use :allow_login => true to allow user to login to account
|
11
|
+
# },
|
12
|
+
# :google=>{
|
13
|
+
# :key=>"",
|
14
|
+
# :secret=>"",
|
15
|
+
# :scope=>"" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
|
16
|
+
# },
|
17
|
+
# :agree2=>{
|
18
|
+
# :key=>"",
|
19
|
+
# :secret=>""
|
20
|
+
# },
|
21
|
+
# :fireeagle=>{
|
22
|
+
# :key=>"",
|
23
|
+
# :secret=>""
|
24
|
+
# },
|
25
|
+
# :hour_feed=>{
|
26
|
+
# :key=>"",
|
27
|
+
# :secret=>"",
|
28
|
+
# :options=>{ # OAuth::Consumer options
|
29
|
+
# :site=>"http://hourfeed.com" # Remember to add a site for a generic OAuth site
|
30
|
+
# }
|
31
|
+
# },
|
32
|
+
# :nu_bux=>{
|
33
|
+
# :key=>"",
|
34
|
+
# :secret=>"",
|
35
|
+
# :super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
|
36
|
+
# # with a token implementation you can set the superclass
|
37
|
+
# # to use
|
38
|
+
# :options=>{ # OAuth::Consumer options
|
39
|
+
# :site=>"http://nubux.heroku.com"
|
40
|
+
# }
|
41
|
+
# }
|
42
|
+
# }
|
43
|
+
#
|
44
|
+
OAUTH_CREDENTIALS={
|
45
|
+
} unless defined? OAUTH_CREDENTIALS
|
46
|
+
|
47
|
+
load 'oauth/models/consumers/service_loader.rb'
|
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,47 @@
|
|
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
|
+
def add_routes
|
38
|
+
route "match '/oauth', :to => 'oauth#index', :as => :oauth"
|
39
|
+
route "match '/oauth/authorize', :to => 'oauth#authorize', :as => :authorize"
|
40
|
+
route "match '/oauth/request_token', :to => 'oauth#request_token', :as => :request_token"
|
41
|
+
route "match '/oauth/access_token', :to => 'oauth#access_token', :as => :access_token"
|
42
|
+
route "match '/oauth/token', :to => 'oauth#token', :as => :token"
|
43
|
+
route "match '/oauth/test_request', :to => 'oauth#test_request', :as => :test_request"
|
44
|
+
|
45
|
+
route "resources :#{file_name}_clients"
|
46
|
+
end
|
47
|
+
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,39 @@
|
|
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 'controller_spec_helper.rb',
|
13
|
+
File.join('spec/controllers', class_path, "#{file_name}_controller_spec_helper.rb")
|
14
|
+
template 'controller_spec.rb',
|
15
|
+
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
|
16
|
+
template 'clients_controller_spec.rb',
|
17
|
+
File.join('spec/controllers', class_path, "#{file_name}_clients_controller_spec.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
def copy_models_spec_files
|
21
|
+
template 'client_application_spec.rb', File.join('spec/models', 'client_application_spec.rb')
|
22
|
+
template 'oauth_token_spec.rb', File.join('spec/models', 'oauth_token_spec.rb')
|
23
|
+
template 'oauth2_token_spec.rb', File.join('spec/models', 'oauth2_token_spec.rb')
|
24
|
+
template 'oauth2_verifier_spec.rb', File.join('spec/models', 'oauth2_verifier_spec.rb')
|
25
|
+
template 'oauth_nonce_spec.rb', File.join('spec/models', 'oauth_nonce_spec.rb')
|
26
|
+
end
|
27
|
+
|
28
|
+
hook_for :fixture_replacement
|
29
|
+
|
30
|
+
def create_fixture_file
|
31
|
+
if options[:fixtures] && options[:fixture_replacement].nil?
|
32
|
+
template 'client_applications.yml', File.join('test/fixtures', 'client_applications.yml')
|
33
|
+
template 'oauth_tokens.yml', File.join('test/fixtures', 'oauth_tokens.yml')
|
34
|
+
template 'oauth_nonces.yml', File.join('test/fixtures', 'oauth_nonces.yml')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|