oauth-plugin 0.3.8 → 0.3.9
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.
- data/CHANGELOG +11 -0
- data/VERSION +1 -1
- data/generators/oauth_consumer/oauth_consumer_generator.rb +1 -0
- data/generators/oauth_consumer/templates/controller.rb +5 -0
- data/generators/oauth_consumer/templates/index.html.erb +27 -0
- data/generators/oauth_consumer/templates/index.html.haml +18 -0
- data/generators/oauth_provider/oauth_provider_generator.rb +1 -0
- data/generators/oauth_provider/templates/access_token.rb +6 -0
- data/generators/oauth_provider/templates/controller.rb +6 -0
- data/lib/oauth/controllers/consumer_controller.rb +10 -3
- data/lib/oauth/controllers/provider_controller.rb +31 -3
- data/oauth-plugin.gemspec +4 -2
- metadata +4 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
7/25/2009
|
2
|
+
0.3.9
|
3
|
+
- Added an Index to oauth consumers controller. Rerun generator to create index template
|
4
|
+
- Added invalidate action to provider, which allows a token to invalidate itself /oauth/invalidate
|
5
|
+
- Added capabilities action to provider. Lets you expand to allow auto discovery of permissions and services that token provides.
|
6
|
+
- Can override how authorize form indicates an authorization. To get around ugly checkbox
|
7
|
+
|
8
|
+
def user_authorizes_token?
|
9
|
+
params[:commit] == 'Authorize'
|
10
|
+
end
|
11
|
+
|
1
12
|
7/23/2009
|
2
13
|
0.3.8
|
3
14
|
- Fixed Gem Plugins Loading
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.9
|
@@ -22,6 +22,7 @@ class OauthConsumerGenerator < Rails::Generator::Base
|
|
22
22
|
@template_extension= options[:haml] ? "haml" : "erb"
|
23
23
|
|
24
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}")
|
25
26
|
|
26
27
|
unless options[:skip_migration]
|
27
28
|
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
@@ -2,6 +2,11 @@ require 'oauth/controllers/consumer_controller'
|
|
2
2
|
class OauthConsumersController < ApplicationController
|
3
3
|
include Oauth::Controllers::ConsumerController
|
4
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
|
+
|
5
10
|
protected
|
6
11
|
|
7
12
|
# Change this to decide where you want to redirect user to after callback is finished.
|
@@ -0,0 +1,27 @@
|
|
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
|
+
|
19
|
+
<%% unless @services.empty? %>
|
20
|
+
<h3>You can connect to the following services:</h3>
|
21
|
+
<ul>
|
22
|
+
<%% @services.each do |service| %>
|
23
|
+
<li>
|
24
|
+
<%%= link_to service.to_s.humanize, oauth_consumer_path(service) %>
|
25
|
+
</li>
|
26
|
+
<%% end %>
|
27
|
+
</ul>
|
@@ -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)
|
@@ -53,6 +53,7 @@ class OauthProviderGenerator < Rails::Generator::Base
|
|
53
53
|
m.route_name 'request_token', '/oauth/request_token',:controller=>'oauth',:action=>'request_token'
|
54
54
|
m.route_name 'access_token', '/oauth/access_token',:controller=>'oauth',:action=>'access_token'
|
55
55
|
m.route_name 'test_request', '/oauth/test_request',:controller=>'oauth',:action=>'test_request'
|
56
|
+
|
56
57
|
m.route_resources "#{controller_file_name}_clients".to_sym
|
57
58
|
|
58
59
|
if !options[:test_unit]
|
@@ -2,6 +2,12 @@ class AccessToken < OauthToken
|
|
2
2
|
validates_presence_of :user
|
3
3
|
before_create :set_authorized_at
|
4
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
|
+
|
5
11
|
protected
|
6
12
|
|
7
13
|
def set_authorized_at
|
@@ -2,4 +2,10 @@ require 'oauth/controllers/provider_controller'
|
|
2
2
|
class OauthController < ApplicationController
|
3
3
|
include OAuth::Controllers::ProviderController
|
4
4
|
|
5
|
+
# Override this to match your authorization page form
|
6
|
+
# It currently expects a checkbox called authorize
|
7
|
+
# def user_authorizes_token?
|
8
|
+
# params[:authorize] == '1'
|
9
|
+
# end
|
10
|
+
|
5
11
|
end
|
@@ -4,11 +4,18 @@ module Oauth
|
|
4
4
|
def self.included(controller)
|
5
5
|
controller.class_eval do
|
6
6
|
before_filter :login_required
|
7
|
-
before_filter :load_consumer
|
8
|
-
skip_before_filter :verify_authenticity_token
|
7
|
+
before_filter :load_consumer, :except=>:index
|
8
|
+
skip_before_filter :verify_authenticity_token,:only=>:callback
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
def index
|
13
|
+
@consumer_tokens=ConsumerToken.all :conditions=>{:user_id=>current_user.id}
|
14
|
+
# The services the user hasn't already connected to
|
15
|
+
@services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
|
16
|
+
end
|
17
|
+
|
18
|
+
|
12
19
|
# creates request token and redirects on to oauth provider's auth page
|
13
20
|
# If user is already connected it displays a page with an option to disconnect and redo
|
14
21
|
def show
|
@@ -41,7 +48,7 @@ module Oauth
|
|
41
48
|
def destroy
|
42
49
|
throw RecordNotFound unless @token
|
43
50
|
@token.destroy
|
44
|
-
if params[:Reconnect
|
51
|
+
if params[:commit]=="Reconnect"
|
45
52
|
redirect_to oauth_consumer_url(params[:id])
|
46
53
|
else
|
47
54
|
flash[:notice] = "#{params[:id].humanize} was successfully disconnected from your account"
|
@@ -4,8 +4,9 @@ module OAuth
|
|
4
4
|
module ProviderController
|
5
5
|
def self.included(controller)
|
6
6
|
controller.class_eval do
|
7
|
-
before_filter :login_required, :
|
7
|
+
before_filter :login_required, :only => [:authorize,:revoke]
|
8
8
|
before_filter :login_or_oauth_required, :only => [:test_request]
|
9
|
+
before_filter :oauth_required, :only => [:invalidate,:capabilities]
|
9
10
|
before_filter :verify_oauth_consumer_signature, :only => [:request_token]
|
10
11
|
before_filter :verify_oauth_request_token, :only => [:access_token]
|
11
12
|
skip_before_filter :verify_authenticity_token
|
@@ -38,7 +39,7 @@ module OAuth
|
|
38
39
|
@token = ::RequestToken.find_by_token params[:oauth_token]
|
39
40
|
unless @token.invalidated?
|
40
41
|
if request.post?
|
41
|
-
if
|
42
|
+
if user_authorizes_token?
|
42
43
|
@token.authorize!(current_user)
|
43
44
|
if @token.oauth10?
|
44
45
|
@redirect_url = params[:oauth_callback] || @token.client_application.callback_url
|
@@ -55,7 +56,7 @@ module OAuth
|
|
55
56
|
else
|
56
57
|
render :action => "authorize_success"
|
57
58
|
end
|
58
|
-
|
59
|
+
else
|
59
60
|
@token.invalidate!
|
60
61
|
render :action => "authorize_failure"
|
61
62
|
end
|
@@ -73,6 +74,33 @@ module OAuth
|
|
73
74
|
end
|
74
75
|
redirect_to oauth_clients_url
|
75
76
|
end
|
77
|
+
|
78
|
+
# Invalidate current token
|
79
|
+
def invalidate
|
80
|
+
current_token.invalidate!
|
81
|
+
head :status=>410
|
82
|
+
end
|
83
|
+
|
84
|
+
# Capabilities of current_token
|
85
|
+
def capabilities
|
86
|
+
if current_token.respond_to?(:capabilities)
|
87
|
+
@capabilities=current_token.capabilities
|
88
|
+
else
|
89
|
+
@capabilities={:invalidate=>url_for(:action=>:invalidate)}
|
90
|
+
end
|
91
|
+
|
92
|
+
respond_to do |format|
|
93
|
+
format.json {render :json=>@capabilities}
|
94
|
+
format.xml {render :xml=>@capabilities}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
# Override this to match your authorization page form
|
101
|
+
def user_authorizes_token?
|
102
|
+
params[:authorize] == '1'
|
103
|
+
end
|
76
104
|
end
|
77
105
|
end
|
78
106
|
end
|
data/oauth-plugin.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{oauth-plugin}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Pelle Braendgaard"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-26}
|
10
10
|
s.description = %q{Rails plugin for implementing an OAuth Provider or Consumer}
|
11
11
|
s.email = %q{oauth-ruby@googlegroups.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
"generators/oauth_consumer/oauth_consumer_generator.rb",
|
24
24
|
"generators/oauth_consumer/templates/consumer_token.rb",
|
25
25
|
"generators/oauth_consumer/templates/controller.rb",
|
26
|
+
"generators/oauth_consumer/templates/index.html.erb",
|
27
|
+
"generators/oauth_consumer/templates/index.html.haml",
|
26
28
|
"generators/oauth_consumer/templates/migration.rb",
|
27
29
|
"generators/oauth_consumer/templates/oauth_config.rb",
|
28
30
|
"generators/oauth_consumer/templates/show.html.erb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pelle Braendgaard
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,8 @@ files:
|
|
41
41
|
- generators/oauth_consumer/oauth_consumer_generator.rb
|
42
42
|
- generators/oauth_consumer/templates/consumer_token.rb
|
43
43
|
- generators/oauth_consumer/templates/controller.rb
|
44
|
+
- generators/oauth_consumer/templates/index.html.erb
|
45
|
+
- generators/oauth_consumer/templates/index.html.haml
|
44
46
|
- generators/oauth_consumer/templates/migration.rb
|
45
47
|
- generators/oauth_consumer/templates/oauth_config.rb
|
46
48
|
- generators/oauth_consumer/templates/show.html.erb
|