houston-oauth-plugin 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/CHANGELOG +187 -0
- data/Gemfile +27 -0
- data/Guardfile +8 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +542 -0
- data/Rakefile +1 -0
- data/UPGRADE.rdoc +21 -0
- data/generators/oauth_consumer/USAGE +10 -0
- data/generators/oauth_consumer/oauth_consumer_generator.rb +52 -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/index.html.slim +15 -0
- data/generators/oauth_consumer/templates/migration.rb +23 -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_consumer/templates/show.html.slim +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/slim/oauth_consumer_generator.rb +21 -0
- data/lib/generators/slim/oauth_consumer_templates/index.html.slim +15 -0
- data/lib/generators/slim/oauth_consumer_templates/show.html.slim +8 -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 +140 -0
- data/lib/oauth/controllers/consumer_controller.rb +153 -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 +49 -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 +121 -0
- data/lib/oauth/provider/authorizer.rb +83 -0
- data/lib/oauth/rack/oauth_filter.rb +97 -0
- data/oauth-plugin.gemspec +40 -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 +373 -0
@@ -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,16 @@
|
|
1
|
+
class AccessToken < OauthToken
|
2
|
+
validates_presence_of :user, :secret
|
3
|
+
before_create :set_authorized_at
|
4
|
+
|
5
|
+
# Implement this to return a hash or array of the capabilities the access token has
|
6
|
+
# This is particularly useful if you have implemented user defined permissions.
|
7
|
+
# def capabilities
|
8
|
+
# {:invalidate=>"/oauth/invalidate",:capabilities=>"/oauth/capabilities"}
|
9
|
+
# end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def set_authorized_at
|
14
|
+
self.authorized_at = Time.now
|
15
|
+
end
|
16
|
+
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,57 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
class ClientApplication < ActiveRecord::Base
|
3
|
+
belongs_to :user
|
4
|
+
has_many :tokens, :class_name => "OauthToken"
|
5
|
+
has_many :access_tokens
|
6
|
+
has_many :oauth2_verifiers
|
7
|
+
has_many :oauth_tokens
|
8
|
+
validates_presence_of :name, :url, :key, :secret
|
9
|
+
validates_uniqueness_of :key
|
10
|
+
before_validation_on_create :generate_keys
|
11
|
+
|
12
|
+
validates_format_of :url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
|
13
|
+
validates_format_of :support_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
|
14
|
+
validates_format_of :callback_url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i, :allow_blank=>true
|
15
|
+
|
16
|
+
attr_accessor :token_callback_url
|
17
|
+
|
18
|
+
def self.find_token(token_key)
|
19
|
+
token = OauthToken.find_by_token(token_key, :include => :client_application)
|
20
|
+
if token && token.authorized?
|
21
|
+
token
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.verify_request(request, options = {}, &block)
|
28
|
+
begin
|
29
|
+
signature = OAuth::Signature.build(request, options, &block)
|
30
|
+
return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
|
31
|
+
value = signature.verify
|
32
|
+
value
|
33
|
+
rescue OAuth::Signature::UnknownSignatureMethod => e
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def oauth_server
|
39
|
+
@oauth_server ||= OAuth::Server.new("http://your.site")
|
40
|
+
end
|
41
|
+
|
42
|
+
def credentials
|
43
|
+
@oauth_client ||= OAuth::Consumer.new(key, secret)
|
44
|
+
end
|
45
|
+
|
46
|
+
# If your application requires passing in extra parameters handle it here
|
47
|
+
def create_request_token(params={})
|
48
|
+
RequestToken.create :client_application => self, :callback_url=>self.token_callback_url
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def generate_keys
|
54
|
+
self.key = OAuth::Helper.generate_key(40)[0,40]
|
55
|
+
self.secret = OAuth::Helper.generate_key(40)[0,40]
|
56
|
+
end
|
57
|
+
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: http://test.com
|
6
|
+
support_url: http://test.com/support
|
7
|
+
callback_url: http://test.com/callback
|
8
|
+
key: one_key
|
9
|
+
secret: MyString
|
10
|
+
user_id: 1
|
11
|
+
created_at: 2007-11-17 16:56:51
|
12
|
+
updated_at: 2007-11-17 16:56:51
|
13
|
+
two:
|
14
|
+
id: 2
|
15
|
+
name: MyString
|
16
|
+
url: http://test.com
|
17
|
+
support_url: http://test.com/support
|
18
|
+
callback_url: http://test.com/callback
|
19
|
+
key: two_key
|
20
|
+
secret: MyString
|
21
|
+
user_id: 1
|
22
|
+
created_at: 2007-11-17 16:56:51
|
23
|
+
updated_at: 2007-11-17 16:56:51
|
@@ -0,0 +1,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,176 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/oauth_controller_spec_helper'
|
3
|
+
require 'oauth/client/action_controller_request'
|
4
|
+
|
5
|
+
describe OauthClientsController do
|
6
|
+
if defined?(Devise)
|
7
|
+
include Devise::TestHelpers
|
8
|
+
end
|
9
|
+
include OAuthControllerSpecHelper
|
10
|
+
fixtures :client_applications, :oauth_tokens, :users
|
11
|
+
before(:each) do
|
12
|
+
login_as_application_owner
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "index" do
|
16
|
+
before do
|
17
|
+
@client_applications = @user.client_applications
|
18
|
+
end
|
19
|
+
|
20
|
+
def do_get
|
21
|
+
get :index
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be successful" do
|
25
|
+
do_get
|
26
|
+
response.should be_success
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should assign client_applications" do
|
30
|
+
do_get
|
31
|
+
assigns[:client_applications].should==@client_applications
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should render index template" do
|
35
|
+
do_get
|
36
|
+
response.should render_template('index')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "show" do
|
41
|
+
|
42
|
+
def do_get
|
43
|
+
get :show, :id => '1'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be successful" do
|
47
|
+
do_get
|
48
|
+
response.should be_success
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should assign client_applications" do
|
52
|
+
do_get
|
53
|
+
assigns[:client_application].should == current_client_application
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should render show template" do
|
57
|
+
do_get
|
58
|
+
response.should render_template('show')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "new" do
|
64
|
+
|
65
|
+
def do_get
|
66
|
+
get :new
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be successful" do
|
70
|
+
do_get
|
71
|
+
response.should be_success
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should assign client_applications" do
|
75
|
+
do_get
|
76
|
+
assigns[:client_application].class.should == ClientApplication
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should render show template" do
|
80
|
+
do_get
|
81
|
+
response.should render_template('new')
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "edit" do
|
87
|
+
def do_get
|
88
|
+
get :edit, :id => '1'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should be successful" do
|
92
|
+
do_get
|
93
|
+
response.should be_success
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should assign client_applications" do
|
97
|
+
do_get
|
98
|
+
assigns[:client_application].should == current_client_application
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should render edit template" do
|
102
|
+
do_get
|
103
|
+
response.should render_template('edit')
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "create" do
|
109
|
+
|
110
|
+
def do_valid_post
|
111
|
+
post :create, 'client_application' => {'name' => 'my site', :url => "http://test.com"}
|
112
|
+
@client_application = ClientApplication.last
|
113
|
+
end
|
114
|
+
|
115
|
+
def do_invalid_post
|
116
|
+
post :create
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should redirect to new client_application" do
|
120
|
+
do_valid_post
|
121
|
+
response.should be_redirect
|
122
|
+
response.should redirect_to(:action => "show", :id => @client_application.id)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should render show template" do
|
126
|
+
do_invalid_post
|
127
|
+
response.should render_template('new')
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "destroy" do
|
132
|
+
|
133
|
+
def do_delete
|
134
|
+
delete :destroy, :id => '1'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should destroy client applications" do
|
138
|
+
do_delete
|
139
|
+
ClientApplication.should_not be_exists(1)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should redirect to list" do
|
143
|
+
do_delete
|
144
|
+
response.should be_redirect
|
145
|
+
response.should redirect_to(:action => 'index')
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "update" do
|
151
|
+
|
152
|
+
def do_valid_update
|
153
|
+
put :update, :id => '1', 'client_application' => {'name' => 'updated site'}
|
154
|
+
end
|
155
|
+
|
156
|
+
def do_invalid_update
|
157
|
+
put :update, :id => '1', 'client_application' => {'name' => nil}
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should redirect to show client_application" do
|
161
|
+
do_valid_update
|
162
|
+
response.should be_redirect
|
163
|
+
response.should redirect_to(:action => "show", :id => 1)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should assign client_applications" do
|
167
|
+
do_invalid_update
|
168
|
+
assigns[:client_application].should == ClientApplication.find(1)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should render show template" do
|
172
|
+
do_invalid_update
|
173
|
+
response.should render_template('edit')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|