lasso 0.2.0 → 0.3.0
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/README.textile +27 -2
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lasso.gemspec +13 -13
- data/lib/lasso/controller/instance.rb +2 -2
- data/lib/lasso/model/oauth_one.rb +3 -21
- data/spec/db/test.sqlite3 +0 -0
- metadata +23 -10
data/README.textile
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
!{float:right}http://www.jamesdaniels.net/b/lasso-logo.png!
|
|
2
|
+
|
|
1
3
|
h1. Lasso
|
|
2
4
|
|
|
3
5
|
h2. Identity herding with OAuth
|
|
@@ -11,11 +13,20 @@ Lasso works via decorators and attempts to have as few opinions about your setup
|
|
|
11
13
|
* Can handle one-to-many associations with owners/tokens
|
|
12
14
|
* Can handle multiple tokens from the same provider
|
|
13
15
|
* Can handle any provider (OAuth 1 or 2) seamlessly by editing a simple configuration
|
|
16
|
+
* Seamlessly handles the 6 permutations of authentication (see below)
|
|
14
17
|
* Isn't hard coded to work with one authentication library
|
|
15
18
|
* Works well with STI or multiple token classes/controllers
|
|
16
19
|
|
|
17
20
|
Lasso creates OAuth tokens via nested attributes on whichever object you deem to be the owner of those keys (e.g, current_user, current_user.account, User.new) which makes it one-to-many and quite flexible.
|
|
18
21
|
|
|
22
|
+
Cases that Lasso gives you hooks for:
|
|
23
|
+
|
|
24
|
+
# New token + no user logged in = Registration
|
|
25
|
+
# New token + user is logged in = Identity claim
|
|
26
|
+
# Existing token + no user logged in = Log in
|
|
27
|
+
# Existing token + owner logged in = Refresh secret/refresh keys
|
|
28
|
+
# Existing token + someone else logged in = Pass to conflict handler
|
|
29
|
+
|
|
19
30
|
h3. Gettings started
|
|
20
31
|
|
|
21
32
|
I haven't made generators for anything, yet. Feel free to skim this README in addition to checking out the "Lasso/Authlogic example application that I've built.":http://github.com/jamesdaniels/lasso-example
|
|
@@ -32,6 +43,7 @@ h3. Schema
|
|
|
32
43
|
|
|
33
44
|
You are going to want a model with a schema that at least looks like this, you can call it what you wish:
|
|
34
45
|
|
|
46
|
+
<pre>
|
|
35
47
|
create_table :access_keys, :force => true do |t|
|
|
36
48
|
t.string "token_a", "token_b", :limit => 999
|
|
37
49
|
t.string "service", "type", :null => false
|
|
@@ -39,11 +51,13 @@ You are going to want a model with a schema that at least looks like this, you c
|
|
|
39
51
|
t.integer "owner_id"
|
|
40
52
|
t.datetime "created_at", "updated_at", :null => false
|
|
41
53
|
end
|
|
54
|
+
</pre>
|
|
42
55
|
|
|
43
56
|
h3. Model
|
|
44
57
|
|
|
45
58
|
Go ahead and add your provider details to the model, like so:
|
|
46
59
|
|
|
60
|
+
<pre>
|
|
47
61
|
class AccessKey < ActiveRecord::Base
|
|
48
62
|
oauth do
|
|
49
63
|
provider '37signals' do
|
|
@@ -63,18 +77,22 @@ Go ahead and add your provider details to the model, like so:
|
|
|
63
77
|
end
|
|
64
78
|
end
|
|
65
79
|
end
|
|
66
|
-
|
|
80
|
+
</pre>
|
|
81
|
+
|
|
67
82
|
You'll want to setup the association to your owner model too:
|
|
68
83
|
|
|
84
|
+
<pre>
|
|
69
85
|
class User < ActiveRecord::Base
|
|
70
86
|
has_many :access_keys, :dependent => :destroy, :as => :owner
|
|
71
87
|
accepts_nested_attributes_for :access_keys
|
|
72
88
|
end
|
|
73
|
-
|
|
89
|
+
</pre>
|
|
90
|
+
|
|
74
91
|
h3. Controller
|
|
75
92
|
|
|
76
93
|
You are going to want a controller that is able to handle the requests:
|
|
77
94
|
|
|
95
|
+
<pre>
|
|
78
96
|
class OauthController < ApplicationController
|
|
79
97
|
processes_oauth_transactions_for :access_keys,
|
|
80
98
|
:through => lambda { current_user || User.new },
|
|
@@ -90,9 +108,11 @@ You are going to want a controller that is able to handle the requests:
|
|
|
90
108
|
# TODO: Merge accounts or display an error
|
|
91
109
|
end
|
|
92
110
|
end
|
|
111
|
+
</pre>
|
|
93
112
|
|
|
94
113
|
And a controller to show the user their AccessKeys:
|
|
95
114
|
|
|
115
|
+
<pre>
|
|
96
116
|
class AccessKeysController < ApplicationController
|
|
97
117
|
|
|
98
118
|
def index
|
|
@@ -110,21 +130,26 @@ And a controller to show the user their AccessKeys:
|
|
|
110
130
|
end
|
|
111
131
|
|
|
112
132
|
end
|
|
133
|
+
</pre>
|
|
113
134
|
|
|
114
135
|
h3. Routes
|
|
115
136
|
|
|
116
137
|
And maybe some routes:
|
|
117
138
|
|
|
139
|
+
<pre>
|
|
118
140
|
map.resources :access_keys, :only => [:index, :show, :destroy]
|
|
119
141
|
|
|
120
142
|
map.oauth_authorize '/:service/oauth/start', :controller => 'oauth', :action => 'new'
|
|
121
143
|
map.oauth_callback '/:service/oauth/callback', :controller => 'oauth', :action => 'create'
|
|
144
|
+
</pre>
|
|
122
145
|
|
|
123
146
|
h3. Usage
|
|
124
147
|
|
|
125
148
|
Now OAuth is as simple as adding a link:
|
|
126
149
|
|
|
150
|
+
<pre>
|
|
127
151
|
<%= link_to 'Integrate your account with your 37signals account', oauth_authorize_path(:service => '37signals') %>
|
|
152
|
+
</pre>
|
|
128
153
|
|
|
129
154
|
h3. Note on Patches/Pull Requests
|
|
130
155
|
|
data/Rakefile
CHANGED
|
@@ -10,9 +10,9 @@ begin
|
|
|
10
10
|
gem.email = "james@marginleft.com"
|
|
11
11
|
gem.homepage = "http://github.com/jamesdaniels/lasso"
|
|
12
12
|
gem.authors = ["James Daniels"]
|
|
13
|
-
gem.add_development_dependency "rspec", "
|
|
14
|
-
gem.add_dependency "oauth2", "
|
|
15
|
-
gem.add_dependency "oauth"
|
|
13
|
+
gem.add_development_dependency "rspec", "~> 1.2.9"
|
|
14
|
+
gem.add_dependency "oauth2", "~> 0.1.0"
|
|
15
|
+
gem.add_dependency "oauth", "~> 0.4.4"
|
|
16
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
17
17
|
end
|
|
18
18
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.3.0
|
data/lasso.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{lasso}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.3.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["James Daniels"]
|
|
12
|
-
s.date = %q{2010-
|
|
12
|
+
s.date = %q{2010-11-12}
|
|
13
13
|
s.description = %q{Identity herding with OAuth}
|
|
14
14
|
s.email = %q{james@marginleft.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
|
|
|
45
45
|
s.homepage = %q{http://github.com/jamesdaniels/lasso}
|
|
46
46
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
47
47
|
s.require_paths = ["lib"]
|
|
48
|
-
s.rubygems_version = %q{1.3.
|
|
48
|
+
s.rubygems_version = %q{1.3.7}
|
|
49
49
|
s.summary = %q{Identity herding with OAuth}
|
|
50
50
|
s.test_files = [
|
|
51
51
|
"spec/controllers.rb",
|
|
@@ -59,19 +59,19 @@ Gem::Specification.new do |s|
|
|
|
59
59
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
60
60
|
s.specification_version = 3
|
|
61
61
|
|
|
62
|
-
if Gem::Version.new(Gem::
|
|
63
|
-
s.add_development_dependency(%q<rspec>, ["
|
|
64
|
-
s.add_runtime_dependency(%q<oauth2>, ["
|
|
65
|
-
s.add_runtime_dependency(%q<oauth>, ["
|
|
62
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
63
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.2.9"])
|
|
64
|
+
s.add_runtime_dependency(%q<oauth2>, ["~> 0.1.0"])
|
|
65
|
+
s.add_runtime_dependency(%q<oauth>, ["~> 0.4.4"])
|
|
66
66
|
else
|
|
67
|
-
s.add_dependency(%q<rspec>, ["
|
|
68
|
-
s.add_dependency(%q<oauth2>, ["
|
|
69
|
-
s.add_dependency(%q<oauth>, ["
|
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
|
68
|
+
s.add_dependency(%q<oauth2>, ["~> 0.1.0"])
|
|
69
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.4"])
|
|
70
70
|
end
|
|
71
71
|
else
|
|
72
|
-
s.add_dependency(%q<rspec>, ["
|
|
73
|
-
s.add_dependency(%q<oauth2>, ["
|
|
74
|
-
s.add_dependency(%q<oauth>, ["
|
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
|
73
|
+
s.add_dependency(%q<oauth2>, ["~> 0.1.0"])
|
|
74
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.4"])
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
@@ -57,7 +57,7 @@ module Lasso
|
|
|
57
57
|
|
|
58
58
|
def redirect
|
|
59
59
|
if version_one?
|
|
60
|
-
@request_token = @oauth.
|
|
60
|
+
@request_token = @oauth.client.get_request_token(:oauth_callback => oauth_settings[:callback].bind(self).call)
|
|
61
61
|
session[:request_token] = @request_token
|
|
62
62
|
redirect_to @request_token.authorize_url
|
|
63
63
|
else
|
|
@@ -66,4 +66,4 @@ module Lasso
|
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
|
-
end
|
|
69
|
+
end
|
|
@@ -7,32 +7,14 @@ def define_oauth_one(parent)
|
|
|
7
7
|
|
|
8
8
|
validates_presence_of :oauth_token, :oauth_token_secret
|
|
9
9
|
|
|
10
|
-
def consumer
|
|
11
|
-
@consumer ||= OAuth::Consumer.new(config(:key), config(:secret), :site => config(:site), :request_token_path => config(:request_token_path), :authorize_path => config(:authorize_path), :access_token_path => config(:access_token_path))
|
|
12
|
-
end
|
|
13
|
-
|
|
14
10
|
def client
|
|
15
|
-
@client ||=
|
|
16
|
-
when 'linkedin'
|
|
17
|
-
LinkedIn::Client.new(config(:key), config(:secret))
|
|
18
|
-
when 'twitter'
|
|
19
|
-
Twitter::OAuth.new(config(:key), config(:secret))
|
|
20
|
-
end
|
|
11
|
+
@client ||= OAuth::Consumer.new(config(:key), config(:secret), :site => config(:site), :request_token_path => config(:request_token_path), :authorize_path => config(:authorize_path), :access_token_path => config(:access_token_path))
|
|
21
12
|
end
|
|
22
13
|
|
|
23
14
|
def access
|
|
24
|
-
|
|
25
|
-
client.authorize_from_access(oauth_token, oauth_token_secret)
|
|
26
|
-
@access ||= case service
|
|
27
|
-
when 'linkedin'
|
|
28
|
-
client
|
|
29
|
-
when 'twitter'
|
|
30
|
-
Twitter::Base.new(client)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
@access
|
|
15
|
+
@access ||= OAuth::AccessToken.new(client, oauth_token, oauth_token_secret)
|
|
34
16
|
end
|
|
35
17
|
|
|
36
18
|
end
|
|
37
19
|
OAUTHONE
|
|
38
|
-
end
|
|
20
|
+
end
|
data/spec/db/test.sqlite3
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lasso
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 19
|
|
4
5
|
prerelease: false
|
|
5
6
|
segments:
|
|
6
7
|
- 0
|
|
7
|
-
-
|
|
8
|
+
- 3
|
|
8
9
|
- 0
|
|
9
|
-
version: 0.
|
|
10
|
+
version: 0.3.0
|
|
10
11
|
platform: ruby
|
|
11
12
|
authors:
|
|
12
13
|
- James Daniels
|
|
@@ -14,16 +15,18 @@ autorequire:
|
|
|
14
15
|
bindir: bin
|
|
15
16
|
cert_chain: []
|
|
16
17
|
|
|
17
|
-
date: 2010-
|
|
18
|
+
date: 2010-11-12 00:00:00 -06:00
|
|
18
19
|
default_executable:
|
|
19
20
|
dependencies:
|
|
20
21
|
- !ruby/object:Gem::Dependency
|
|
21
22
|
name: rspec
|
|
22
23
|
prerelease: false
|
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
24
26
|
requirements:
|
|
25
|
-
- -
|
|
27
|
+
- - ~>
|
|
26
28
|
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 13
|
|
27
30
|
segments:
|
|
28
31
|
- 1
|
|
29
32
|
- 2
|
|
@@ -35,26 +38,32 @@ dependencies:
|
|
|
35
38
|
name: oauth2
|
|
36
39
|
prerelease: false
|
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
38
42
|
requirements:
|
|
39
|
-
- -
|
|
43
|
+
- - ~>
|
|
40
44
|
- !ruby/object:Gem::Version
|
|
45
|
+
hash: 27
|
|
41
46
|
segments:
|
|
42
47
|
- 0
|
|
48
|
+
- 1
|
|
43
49
|
- 0
|
|
44
|
-
|
|
45
|
-
version: 0.0.10
|
|
50
|
+
version: 0.1.0
|
|
46
51
|
type: :runtime
|
|
47
52
|
version_requirements: *id002
|
|
48
53
|
- !ruby/object:Gem::Dependency
|
|
49
54
|
name: oauth
|
|
50
55
|
prerelease: false
|
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
52
58
|
requirements:
|
|
53
|
-
- -
|
|
59
|
+
- - ~>
|
|
54
60
|
- !ruby/object:Gem::Version
|
|
61
|
+
hash: 7
|
|
55
62
|
segments:
|
|
56
63
|
- 0
|
|
57
|
-
|
|
64
|
+
- 4
|
|
65
|
+
- 4
|
|
66
|
+
version: 0.4.4
|
|
58
67
|
type: :runtime
|
|
59
68
|
version_requirements: *id003
|
|
60
69
|
description: Identity herding with OAuth
|
|
@@ -101,23 +110,27 @@ rdoc_options:
|
|
|
101
110
|
require_paths:
|
|
102
111
|
- lib
|
|
103
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
|
+
none: false
|
|
104
114
|
requirements:
|
|
105
115
|
- - ">="
|
|
106
116
|
- !ruby/object:Gem::Version
|
|
117
|
+
hash: 3
|
|
107
118
|
segments:
|
|
108
119
|
- 0
|
|
109
120
|
version: "0"
|
|
110
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
|
+
none: false
|
|
111
123
|
requirements:
|
|
112
124
|
- - ">="
|
|
113
125
|
- !ruby/object:Gem::Version
|
|
126
|
+
hash: 3
|
|
114
127
|
segments:
|
|
115
128
|
- 0
|
|
116
129
|
version: "0"
|
|
117
130
|
requirements: []
|
|
118
131
|
|
|
119
132
|
rubyforge_project:
|
|
120
|
-
rubygems_version: 1.3.
|
|
133
|
+
rubygems_version: 1.3.7
|
|
121
134
|
signing_key:
|
|
122
135
|
specification_version: 3
|
|
123
136
|
summary: Identity herding with OAuth
|