songkick-oauth2-provider 0.10.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.rdoc +394 -0
- data/example/README.rdoc +11 -0
- data/example/application.rb +159 -0
- data/example/config.ru +3 -0
- data/example/environment.rb +11 -0
- data/example/models/connection.rb +9 -0
- data/example/models/note.rb +4 -0
- data/example/models/user.rb +6 -0
- data/example/public/style.css +78 -0
- data/example/schema.rb +27 -0
- data/example/views/authorize.erb +28 -0
- data/example/views/create_user.erb +3 -0
- data/example/views/error.erb +6 -0
- data/example/views/home.erb +25 -0
- data/example/views/layout.erb +25 -0
- data/example/views/login.erb +20 -0
- data/example/views/new_client.erb +25 -0
- data/example/views/new_user.erb +22 -0
- data/example/views/show_client.erb +15 -0
- data/lib/songkick/oauth2/model.rb +20 -0
- data/lib/songkick/oauth2/model/authorization.rb +126 -0
- data/lib/songkick/oauth2/model/client.rb +61 -0
- data/lib/songkick/oauth2/model/client_owner.rb +15 -0
- data/lib/songkick/oauth2/model/hashing.rb +29 -0
- data/lib/songkick/oauth2/model/resource_owner.rb +54 -0
- data/lib/songkick/oauth2/provider.rb +122 -0
- data/lib/songkick/oauth2/provider/access_token.rb +68 -0
- data/lib/songkick/oauth2/provider/authorization.rb +190 -0
- data/lib/songkick/oauth2/provider/error.rb +22 -0
- data/lib/songkick/oauth2/provider/exchange.rb +227 -0
- data/lib/songkick/oauth2/router.rb +79 -0
- data/lib/songkick/oauth2/schema.rb +17 -0
- data/lib/songkick/oauth2/schema/20120828112156_songkick_oauth2_schema_original_schema.rb +36 -0
- data/spec/factories.rb +27 -0
- data/spec/request_helpers.rb +52 -0
- data/spec/songkick/oauth2/model/authorization_spec.rb +216 -0
- data/spec/songkick/oauth2/model/client_spec.rb +55 -0
- data/spec/songkick/oauth2/model/resource_owner_spec.rb +88 -0
- data/spec/songkick/oauth2/provider/access_token_spec.rb +125 -0
- data/spec/songkick/oauth2/provider/authorization_spec.rb +346 -0
- data/spec/songkick/oauth2/provider/exchange_spec.rb +353 -0
- data/spec/songkick/oauth2/provider_spec.rb +545 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/test_app/helper.rb +33 -0
- data/spec/test_app/provider/application.rb +68 -0
- data/spec/test_app/provider/views/authorize.erb +19 -0
- metadata +273 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
require File.expand_path('../../lib/songkick/oauth2/provider', __FILE__)
|
6
|
+
|
7
|
+
dbfile = File.expand_path('../test.sqlite3', __FILE__)
|
8
|
+
File.unlink(dbfile) if File.file?(dbfile)
|
9
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => dbfile)
|
10
|
+
|
11
|
+
require 'logger'
|
12
|
+
ActiveRecord::Base.logger = Logger.new(STDERR)
|
13
|
+
ActiveRecord::Base.logger.level = Logger::INFO
|
14
|
+
|
15
|
+
Songkick::OAuth2::Model::Schema.up
|
16
|
+
|
17
|
+
ActiveRecord::Schema.define do |version|
|
18
|
+
create_table :users, :force => true do |t|
|
19
|
+
t.string :name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'test_app/provider/application'
|
24
|
+
require 'request_helpers'
|
25
|
+
require 'factories'
|
26
|
+
|
27
|
+
require 'thin'
|
28
|
+
Thin::Logging.silent = true
|
29
|
+
$VERBOSE = nil
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
# to run only specific specs, add :focus to the spec
|
33
|
+
# describe "foo", :focus do
|
34
|
+
# OR
|
35
|
+
# it "should foo", :focus do
|
36
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true # default in rspec 3
|
37
|
+
config.filter_run :focus => true
|
38
|
+
config.run_all_when_everything_filtered = true
|
39
|
+
|
40
|
+
config.before do
|
41
|
+
Songkick::OAuth2::Provider.enforce_ssl = false
|
42
|
+
time = Time.now
|
43
|
+
Time.stub(:now).and_return time
|
44
|
+
end
|
45
|
+
|
46
|
+
config.after do
|
47
|
+
[ Songkick::OAuth2::Model::Client,
|
48
|
+
Songkick::OAuth2::Model::Authorization,
|
49
|
+
TestApp::User
|
50
|
+
|
51
|
+
].each { |k| k.delete_all }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_authorization(params)
|
56
|
+
Songkick::OAuth2::Model::Authorization.create do |authorization|
|
57
|
+
params.each do |key, value|
|
58
|
+
authorization.__send__ "#{key}=", value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module TestApp
|
2
|
+
|
3
|
+
class User < ActiveRecord::Base
|
4
|
+
self.table_name = :users
|
5
|
+
|
6
|
+
include Songkick::OAuth2::Model::ResourceOwner
|
7
|
+
include Songkick::OAuth2::Model::ClientOwner
|
8
|
+
|
9
|
+
def self.[](name)
|
10
|
+
find_or_create_by_name(name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Helper
|
15
|
+
module RackRunner
|
16
|
+
def start(port)
|
17
|
+
handler = Rack::Handler.get('thin')
|
18
|
+
Thread.new do
|
19
|
+
handler.run(new, :Port => port) { |server| @server = server }
|
20
|
+
end
|
21
|
+
sleep 0.1 until @server
|
22
|
+
end
|
23
|
+
|
24
|
+
def stop
|
25
|
+
@server.stop if @server
|
26
|
+
@server = nil
|
27
|
+
sleep 0.1 while EM.reactor_running?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require File.expand_path('../../helper', __FILE__)
|
3
|
+
|
4
|
+
module TestApp
|
5
|
+
class Provider < Sinatra::Base
|
6
|
+
|
7
|
+
extend Helper::RackRunner
|
8
|
+
|
9
|
+
Songkick::OAuth2::Provider.realm = 'Demo App'
|
10
|
+
|
11
|
+
set :views, File.dirname(__FILE__) + '/views'
|
12
|
+
|
13
|
+
def handle_authorize
|
14
|
+
@oauth2 = Songkick::OAuth2::Provider.parse(User['Bob'], env)
|
15
|
+
redirect(@oauth2.redirect_uri, @oauth2.response_status) if @oauth2.redirect?
|
16
|
+
|
17
|
+
headers @oauth2.response_headers
|
18
|
+
status @oauth2.response_status
|
19
|
+
|
20
|
+
if body = @oauth2.response_body
|
21
|
+
body
|
22
|
+
elsif @oauth2.valid?
|
23
|
+
erb(:authorize)
|
24
|
+
else
|
25
|
+
'WAT'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def protect_resource_for(user = nil, scopes = [])
|
30
|
+
access_token = Songkick::OAuth2::Provider.access_token(user, scopes, env)
|
31
|
+
headers access_token.response_headers
|
32
|
+
status access_token.response_status
|
33
|
+
yield access_token
|
34
|
+
end
|
35
|
+
|
36
|
+
def serve_protected_resource
|
37
|
+
@user = User['Bob']
|
38
|
+
protect_resource_for(@user, ['profile']) do |auth|
|
39
|
+
if auth.valid?
|
40
|
+
JSON.unparse('data' => 'Top secret')
|
41
|
+
else
|
42
|
+
JSON.unparse('data' => 'No soup for you')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
[:get, :post].each do |method|
|
48
|
+
__send__(method, '/authorize') { handle_authorize }
|
49
|
+
end
|
50
|
+
|
51
|
+
post '/allow' do
|
52
|
+
@user = User['bob']
|
53
|
+
@oauth2 = Songkick::OAuth2::Provider::Authorization.new(@user, params)
|
54
|
+
if params['allow'] == '1'
|
55
|
+
@oauth2.grant_access! :duration => 3.hours
|
56
|
+
else
|
57
|
+
@oauth2.deny_access!
|
58
|
+
end
|
59
|
+
redirect @oauth2.redirect_uri, @oauth2.response_status
|
60
|
+
end
|
61
|
+
|
62
|
+
[:get, :post].each do |method|
|
63
|
+
__send__(method, '/user_profile') { serve_protected_resource }
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h1>Authorize OAuth client</h1>
|
2
|
+
|
3
|
+
<p>Do you want to allow <%= @oauth2.client.name %> to act on your behalf?</p>
|
4
|
+
|
5
|
+
<ul>
|
6
|
+
<% @oauth2.scopes.each do |scope| %><%= scope %><% end %>
|
7
|
+
</ul>
|
8
|
+
|
9
|
+
<form method="post" action="/allow">
|
10
|
+
<% @oauth2.params.each do |key, value| %>
|
11
|
+
<input type="hidden" name="<%= key %>" value="<%= value %>">
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<input type="checkbox" name="allow" id="allow" value="1">
|
15
|
+
<label for="allow">Allow this application</label>
|
16
|
+
|
17
|
+
<input type="submit" value="Go!">
|
18
|
+
</form>
|
19
|
+
|
metadata
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: songkick-oauth2-provider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 55
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 10
|
9
|
+
- 0
|
10
|
+
version: 0.10.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- James Coglan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-08-28 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bcrypt-ruby
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: json
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rack
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: appraisal
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 15
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
- 4
|
89
|
+
- 0
|
90
|
+
version: 0.4.0
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: activerecord
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 15
|
102
|
+
segments:
|
103
|
+
- 3
|
104
|
+
- 2
|
105
|
+
- 0
|
106
|
+
version: 3.2.0
|
107
|
+
type: :development
|
108
|
+
version_requirements: *id006
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rspec
|
111
|
+
prerelease: false
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
type: :development
|
122
|
+
version_requirements: *id007
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: sqlite3
|
125
|
+
prerelease: false
|
126
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
type: :development
|
136
|
+
version_requirements: *id008
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: sinatra
|
139
|
+
prerelease: false
|
140
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 27
|
146
|
+
segments:
|
147
|
+
- 1
|
148
|
+
- 3
|
149
|
+
- 0
|
150
|
+
version: 1.3.0
|
151
|
+
type: :development
|
152
|
+
version_requirements: *id009
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: thin
|
155
|
+
prerelease: false
|
156
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
hash: 3
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
version: "0"
|
165
|
+
type: :development
|
166
|
+
version_requirements: *id010
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: factory_girl
|
169
|
+
prerelease: false
|
170
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ~>
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
hash: 3
|
176
|
+
segments:
|
177
|
+
- 2
|
178
|
+
- 0
|
179
|
+
version: "2.0"
|
180
|
+
type: :development
|
181
|
+
version_requirements: *id011
|
182
|
+
description:
|
183
|
+
email: james@songkick.com
|
184
|
+
executables: []
|
185
|
+
|
186
|
+
extensions: []
|
187
|
+
|
188
|
+
extra_rdoc_files:
|
189
|
+
- README.rdoc
|
190
|
+
files:
|
191
|
+
- README.rdoc
|
192
|
+
- example/public/style.css
|
193
|
+
- example/views/login.erb
|
194
|
+
- example/views/home.erb
|
195
|
+
- example/views/new_user.erb
|
196
|
+
- example/views/layout.erb
|
197
|
+
- example/views/create_user.erb
|
198
|
+
- example/views/error.erb
|
199
|
+
- example/views/authorize.erb
|
200
|
+
- example/views/new_client.erb
|
201
|
+
- example/views/show_client.erb
|
202
|
+
- example/models/note.rb
|
203
|
+
- example/models/connection.rb
|
204
|
+
- example/models/user.rb
|
205
|
+
- example/schema.rb
|
206
|
+
- example/environment.rb
|
207
|
+
- example/application.rb
|
208
|
+
- example/README.rdoc
|
209
|
+
- example/config.ru
|
210
|
+
- lib/songkick/oauth2/model/authorization.rb
|
211
|
+
- lib/songkick/oauth2/model/client_owner.rb
|
212
|
+
- lib/songkick/oauth2/model/resource_owner.rb
|
213
|
+
- lib/songkick/oauth2/model/hashing.rb
|
214
|
+
- lib/songkick/oauth2/model/client.rb
|
215
|
+
- lib/songkick/oauth2/provider.rb
|
216
|
+
- lib/songkick/oauth2/provider/authorization.rb
|
217
|
+
- lib/songkick/oauth2/provider/exchange.rb
|
218
|
+
- lib/songkick/oauth2/provider/error.rb
|
219
|
+
- lib/songkick/oauth2/provider/access_token.rb
|
220
|
+
- lib/songkick/oauth2/schema.rb
|
221
|
+
- lib/songkick/oauth2/schema/20120828112156_songkick_oauth2_schema_original_schema.rb
|
222
|
+
- lib/songkick/oauth2/router.rb
|
223
|
+
- lib/songkick/oauth2/model.rb
|
224
|
+
- spec/test_app/provider/views/authorize.erb
|
225
|
+
- spec/factories.rb
|
226
|
+
- spec/request_helpers.rb
|
227
|
+
- spec/test_app/helper.rb
|
228
|
+
- spec/test_app/provider/application.rb
|
229
|
+
- spec/songkick/oauth2/model/authorization_spec.rb
|
230
|
+
- spec/songkick/oauth2/model/client_spec.rb
|
231
|
+
- spec/songkick/oauth2/model/resource_owner_spec.rb
|
232
|
+
- spec/songkick/oauth2/provider/exchange_spec.rb
|
233
|
+
- spec/songkick/oauth2/provider/authorization_spec.rb
|
234
|
+
- spec/songkick/oauth2/provider/access_token_spec.rb
|
235
|
+
- spec/songkick/oauth2/provider_spec.rb
|
236
|
+
- spec/spec_helper.rb
|
237
|
+
has_rdoc: true
|
238
|
+
homepage: http://www.songkick.com
|
239
|
+
licenses: []
|
240
|
+
|
241
|
+
post_install_message:
|
242
|
+
rdoc_options:
|
243
|
+
- --main
|
244
|
+
- README.rdoc
|
245
|
+
require_paths:
|
246
|
+
- lib
|
247
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
248
|
+
none: false
|
249
|
+
requirements:
|
250
|
+
- - ">="
|
251
|
+
- !ruby/object:Gem::Version
|
252
|
+
hash: 3
|
253
|
+
segments:
|
254
|
+
- 0
|
255
|
+
version: "0"
|
256
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
|
+
none: false
|
258
|
+
requirements:
|
259
|
+
- - ">="
|
260
|
+
- !ruby/object:Gem::Version
|
261
|
+
hash: 3
|
262
|
+
segments:
|
263
|
+
- 0
|
264
|
+
version: "0"
|
265
|
+
requirements: []
|
266
|
+
|
267
|
+
rubyforge_project:
|
268
|
+
rubygems_version: 1.6.2
|
269
|
+
signing_key:
|
270
|
+
specification_version: 3
|
271
|
+
summary: Simple OAuth 2.0 provider toolkit
|
272
|
+
test_files: []
|
273
|
+
|