registrar 0.3.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +2 -235
- data/lib/registrar.rb +1 -5
- data/lib/registrar/middleware.rb +1 -73
- data/lib/registrar/{auth_builder/omni_auth.rb → middleware/convert_omniauth_hash_to_registrar_hash.rb} +4 -4
- data/lib/registrar/version.rb +1 -1
- data/spec/{omni_auth_adapter_spec.rb → convert_omniauth_hash_to_registrar_hash_spec.rb} +2 -3
- metadata +8 -16
- data/lib/registrar/auth_builder.rb +0 -6
- data/lib/registrar/debug.rb +0 -38
- data/lib/registrar/mapper.rb +0 -7
- data/lib/registrar/mapper/omni_auth.rb +0 -20
- data/lib/registrar/mapper/params.rb +0 -66
- data/lib/registrar/profile_builder.rb +0 -22
- data/spec/params_mapper_spec.rb +0 -71
- data/spec/profile_builder_spec.rb +0 -106
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d339b2e110854a1c5f09a2ce01bf44c1082bf64e
|
4
|
+
data.tar.gz: 7a8ff97354a6447d70064c801da016b040a881a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4663eca6bc0511a4219ee3f24897ed804ce017641e29f9771b422e9d4627f2777db6aa2c17785bfaeab8f83bd5a7038d6a933f8f0d8308bd6b7eb9b74bbdf889
|
7
|
+
data.tar.gz: e0faf5e3d4bbf9dd9c52defdf71b3512ca46af60dfda41e5de1bf0e627f657706a7f625ac8b444b0b2c7f2cf2d99f14418ba97e1dd507086d8380ca031e7cfb7
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
registrar
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.4
|
data/README.md
CHANGED
@@ -1,236 +1,3 @@
|
|
1
|
-
|
2
|
-
[doc]: http://rubydoc.info/github/JanOwiesniak/registrar/master/file/README.md
|
3
|
-
[gem]: https://rubygems.org/gems/registrar
|
4
|
-
[gem-badge]: https://img.shields.io/gem/v/registrar.svg
|
5
|
-
[rack-playground]: https://github.com/JanOwiesniak/rack-playground/blob/master/lib/app_builder.rb
|
1
|
+
# Registrar
|
6
2
|
|
7
|
-
#
|
8
|
-
|
9
|
-
[![Gem Version][gem-badge]][gem]
|
10
|
-
|
11
|
-
[Gem][gem] |
|
12
|
-
[Source][github] |
|
13
|
-
[Documentation][doc]
|
14
|
-
|
15
|
-
## Introduction
|
16
|
-
|
17
|
-
Registrar standardizes the authentication process through [Rack Middleware](https://github.com/rack/rack#available-middleware) and works well with common authentication mechanisms like [OmniAuth](https://github.com/intridea/omniauth).
|
18
|
-
|
19
|
-
## Description
|
20
|
-
|
21
|
-
You can think of Registrar as a thin wrapper around your sign up / sign in process.
|
22
|
-
|
23
|
-
Registrar already has [build in support](https://github.com/JanOwiesniak/registrar/blob/master/lib/registrar/auth_builder/omni_auth.rb) for the [OmniAuth Auth Hash Schema](https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema).
|
24
|
-
|
25
|
-
If you want to use a different authentication mechanism feel free to implement your own [AuthBuilder](https://github.com/JanOwiesniak/registrar/wiki/AuthBuilder).
|
26
|
-
|
27
|
-
## Getting Started
|
28
|
-
|
29
|
-
Let us start with a short example.
|
30
|
-
|
31
|
-
I'm using a [fork](https://github.com/JanOwiesniak/omniauth-facebook-access-token) (see here why i use a [fork](https://github.com/JanOwiesniak/omniauth-facebook-access-token/commit/6df0d75d5b9a3c866eea63d2495da0376091cbbe)) of the [omniauth-facebook-access-token](https://github.com/JanOwiesniak/omniauth-facebook-access-token) OmniAuth strategy to authenticate my user.
|
32
|
-
|
33
|
-
Add `registrar` and the authenticaton mechanism you want to use to your `Gemfile`
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
gem 'registrar'
|
37
|
-
gem 'omniauth-facebook-access-token' # we are just using one OmniAuth strategy here
|
38
|
-
```
|
39
|
-
|
40
|
-
Add the authentication mechanism of your choice
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
require 'omniauth-facebook-access-token'
|
44
|
-
|
45
|
-
app = Rack::Builder.app do
|
46
|
-
# Store authenticated user in env['omniauth.auth']
|
47
|
-
use OmniAuth::Builder do
|
48
|
-
provider omniauth-facebook-access-token
|
49
|
-
end
|
50
|
-
|
51
|
-
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
|
52
|
-
end
|
53
|
-
|
54
|
-
run app
|
55
|
-
```
|
56
|
-
|
57
|
-
Add a appropriate AuthBuilder to your Middleware Stack to transform the previous authentication result into registrar schema.
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
require 'registrar'
|
61
|
-
require 'omniauth-facebook-access-token'
|
62
|
-
|
63
|
-
app = Rack::Builder.app do
|
64
|
-
# Store authenticated user in env['omniauth.auth']
|
65
|
-
use OmniAuth::Builder do
|
66
|
-
provider omniauth-facebook-access-token
|
67
|
-
end
|
68
|
-
|
69
|
-
# Transform the OmniAuth Schema env['omniauth.auth'] into the Registrar Schema env['registrar.auth']
|
70
|
-
use Registrar::AuthBuilder::OmniAuth
|
71
|
-
|
72
|
-
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
|
73
|
-
end
|
74
|
-
|
75
|
-
run app
|
76
|
-
```
|
77
|
-
|
78
|
-
Go to the [Facebook Graph API Explorer](https://developers.facebook.com/tools/explorer/), generate an access token and copy it to your clipboard.
|
79
|
-
|
80
|
-
Start the application, visit localhost:port/auth/facebook_access_token and paste the access token from your clipboard.
|
81
|
-
Click the submit button.
|
82
|
-
|
83
|
-
`env['omniauth.auth']` returns the schema OmniAuth builds for you
|
84
|
-
|
85
|
-
```bash
|
86
|
-
!ruby/hash:OmniAuth::AuthHash
|
87
|
-
provider: facebook
|
88
|
-
uid: '100000100277322'
|
89
|
-
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
|
90
|
-
email: janowiesniak@gmx.de
|
91
|
-
name: Jan Ow
|
92
|
-
first_name: Jan
|
93
|
-
last_name: Ow
|
94
|
-
image: http://graph.facebook.com/100000100277322/picture
|
95
|
-
urls: !ruby/hash:OmniAuth::AuthHash
|
96
|
-
Facebook: http://www.facebook.com/100000100277322
|
97
|
-
location: Bochum, Germany
|
98
|
-
verified: true
|
99
|
-
credentials: !ruby/hash:OmniAuth::AuthHash
|
100
|
-
token: CAACEdEose0cBABZBEayxJNmeCRdvrwT6RbiEbtYUyAZCY24E5xxCoPQJ0oCVR8XFsUEtTpnMjwrRMwvjliQe2xDRM2c76ONriaNQaMwuAKH1YjQki9lK8evIkN18TqPopB1blbeRuOIkes2l4JQ3Ga7HL9vHXHqhAjcbuZCHKhtOJMulZAN1wfWMlOxF7bBZCW0TdzJz654CW7ErAsIPj
|
101
|
-
expires: false
|
102
|
-
extra: !ruby/hash:OmniAuth::AuthHash
|
103
|
-
raw_info: !ruby/hash:OmniAuth::AuthHash
|
104
|
-
id: '100000100277322'
|
105
|
-
email: janowiesniak@gmx.de
|
106
|
-
first_name: Jan
|
107
|
-
gender: male
|
108
|
-
last_name: Ow
|
109
|
-
link: http://www.facebook.com/100000100277322
|
110
|
-
location: !ruby/hash:OmniAuth::AuthHash
|
111
|
-
id: '106544749381682'
|
112
|
-
name: Bochum, Germany
|
113
|
-
locale: en_US
|
114
|
-
name: Jan Ow
|
115
|
-
timezone: 1
|
116
|
-
updated_time: '2015-01-10T11:52:30+0000'
|
117
|
-
verified: true
|
118
|
-
```
|
119
|
-
|
120
|
-
`env['registrar.auth']` returns the schema which registrar builds (in this case Registrar::AuthBuilder::OmniAuth)
|
121
|
-
|
122
|
-
```bash
|
123
|
-
provider:
|
124
|
-
name: facebook
|
125
|
-
uid: '100000100277322'
|
126
|
-
access_token: CAACEdEose0cBABZBEayxJNmeCRdvrwT6RbiEbtYUyAZCY24E5xxCoPQJ0oCVR8XFsUEtTpnMjwrRMwvjliQe2xDRM2c76ONriaNQaMwuAKH1YjQki9lK8evIkN18TqPopB1blbeRuOIkes2l4JQ3Ga7HL9vHXHqhAjcbuZCHKhtOJMulZAN1wfWMlOxF7bBZCW0TdzJz654CW7ErAsIPj
|
127
|
-
profile:
|
128
|
-
name: Jan Ow
|
129
|
-
email: janowiesniak@gmx.de
|
130
|
-
location: Bochum, Germany
|
131
|
-
image: http://graph.facebook.com/100000100277322/picture
|
132
|
-
trace:
|
133
|
-
ip: 127.0.0.1
|
134
|
-
user_agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
|
135
|
-
Chrome/40.0.2214.91 Safari/537.36
|
136
|
-
timestamp: '1427800292'
|
137
|
-
```
|
138
|
-
|
139
|
-
Currently, the AuthBuilder just transforms the Hash into a different structure.
|
140
|
-
|
141
|
-
To do something with the authenticated user (e.g. sign up or sign in), use the profile builder.
|
142
|
-
|
143
|
-
Open up you Middewarestack again.
|
144
|
-
|
145
|
-
```ruby
|
146
|
-
require 'registrar'
|
147
|
-
require 'omniauth-facebook-access-token'
|
148
|
-
|
149
|
-
app = Rack::Builder.app do
|
150
|
-
# Store authenticated user in env['omniauth.auth']
|
151
|
-
use OmniAuth::Builder do
|
152
|
-
provider omniauth-facebook-access-token
|
153
|
-
end
|
154
|
-
|
155
|
-
# Transform the OmniAuth Schema env['omniauth.auth'] into the Registrar Schema env['registrar.auth']
|
156
|
-
use Registrar::AuthBuilder::OmniAuth
|
157
|
-
|
158
|
-
# Handle Registrar Schema env['registrar.auth'] and store processed result into env['registrar.profile']
|
159
|
-
use Registrar::ProfileBuilder, Proc.new {|schema| #find_or_create_profile_in_persistence }
|
160
|
-
|
161
|
-
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
|
162
|
-
end
|
163
|
-
|
164
|
-
run app
|
165
|
-
```
|
166
|
-
|
167
|
-
In this case I passed the Registrar Schema to an application related service called ProfileRegister which returned me a application specific Profile.
|
168
|
-
|
169
|
-
This profile is stored in `env['registrar.profile']`
|
170
|
-
|
171
|
-
```bash
|
172
|
-
!ruby/object:ProfileRegister::Services::ProfileBoundary::Profile
|
173
|
-
o:
|
174
|
-
t:
|
175
|
-
:profile_uid: '1'
|
176
|
-
:provider: facebook
|
177
|
-
:access_token: a39147c2f57f3797f58a
|
178
|
-
:external_uid: '100000100277322'
|
179
|
-
:display_name: Jan Ow
|
180
|
-
:country_code:
|
181
|
-
:avatar: http://graph.facebook.com/100000100277322/picture
|
182
|
-
:email: janowiesniak@gmx.de
|
183
|
-
:terms_accepted: false
|
184
|
-
:registration_platform:
|
185
|
-
:gender:
|
186
|
-
:language:
|
187
|
-
:birthday:
|
188
|
-
:fresh: true
|
189
|
-
:last_login: &1 !ruby/object:ProfileRegister::Services::ProfileBoundary::LastLogin
|
190
|
-
o:
|
191
|
-
t:
|
192
|
-
:time: 2015-03-31 11:11:32.000000000 Z
|
193
|
-
:address: 127.0.0.1
|
194
|
-
:user_agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
|
195
|
-
Gecko) Chrome/40.0.2214.91 Safari/537.36
|
196
|
-
```
|
197
|
-
|
198
|
-
If your application supports the concept of a session your could store env['registrar.profile'] in your session to log the user in.
|
199
|
-
|
200
|
-
```ruby
|
201
|
-
if env['registrar.profile']
|
202
|
-
@session['current_profile'] = env['registrar.profile']
|
203
|
-
end
|
204
|
-
```
|
205
|
-
|
206
|
-
If you decide to do this you could also add some helper methods.
|
207
|
-
|
208
|
-
```ruby
|
209
|
-
def current_profile
|
210
|
-
@session['current_profile']
|
211
|
-
end
|
212
|
-
|
213
|
-
def logged_in?
|
214
|
-
!!current_profile
|
215
|
-
end
|
216
|
-
|
217
|
-
def logged_out?
|
218
|
-
!logged_in?
|
219
|
-
end
|
220
|
-
```
|
221
|
-
|
222
|
-
If you are using `Rails` you should probably check out [registrar-rails](https://github.com/JanOwiesniak/registrar-rails) which gives you a small interface to configure your middleware as well as some helper methods as suggested above.
|
223
|
-
|
224
|
-
## Contributing
|
225
|
-
|
226
|
-
0. Check out the [Wiki](https://github.com/JanOwiesniak/registrar/wiki)
|
227
|
-
1. Fork it ( https://github.com/JanOwiesniak/registrar/fork )
|
228
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
229
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
230
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
231
|
-
5. Create a new Pull Request
|
232
|
-
|
233
|
-
## Related Projects
|
234
|
-
|
235
|
-
* https://github.com/JanOwiesniak/registrar-rails
|
236
|
-
* https://github.com/JanOwiesniak/omniauth-registrar
|
3
|
+
# TODO
|
data/lib/registrar.rb
CHANGED
data/lib/registrar/middleware.rb
CHANGED
@@ -1,78 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'registrar/middleware/convert_omniauth_hash_to_registrar_hash'
|
2
2
|
|
3
3
|
module Registrar
|
4
4
|
module Middleware
|
5
|
-
def self.configure(&blk)
|
6
|
-
yield config
|
7
|
-
|
8
|
-
convert_params_to_registrar_schema
|
9
|
-
convert_registrar_schema_to_omniauth_schema
|
10
|
-
add_omniauth_strategies
|
11
|
-
convert_omniauth_schema_to_registrar_schema
|
12
|
-
add_registrar_handler
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def self.convert_params_to_registrar_schema
|
18
|
-
config.middleware.use Registrar::Mapper::Params, config.attributes
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.convert_registrar_schema_to_omniauth_schema
|
22
|
-
config.middleware.use Registrar::Mapper::OmniAuth
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.add_omniauth_strategies
|
26
|
-
strategies = config.strategies
|
27
|
-
|
28
|
-
if strategies.respond_to?(:each)
|
29
|
-
strategies.each do |strategy|
|
30
|
-
add_omniauth_strategy(strategy)
|
31
|
-
end
|
32
|
-
else
|
33
|
-
add_omniauth_strategy(strategies)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.add_omniauth_strategy(strategy)
|
38
|
-
filename = "omniauth-#{strategy.gsub('_','-')}"
|
39
|
-
provider_name = strategy.gsub('-','_')
|
40
|
-
|
41
|
-
require filename
|
42
|
-
|
43
|
-
config.middleware.use ::OmniAuth::Builder do
|
44
|
-
provider provider_name
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.convert_omniauth_schema_to_registrar_schema
|
49
|
-
config.middleware.use Registrar::AuthBuilder::OmniAuth
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.add_registrar_handler
|
53
|
-
config.middleware.use Registrar::ProfileBuilder, config.handler
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.config
|
57
|
-
@config ||= Registrar::Middleware::Config.new
|
58
|
-
end
|
59
|
-
|
60
|
-
class Config
|
61
|
-
def strategies(*args)
|
62
|
-
@strategies ||= args
|
63
|
-
end
|
64
|
-
|
65
|
-
def attributes(arg = nil)
|
66
|
-
@attributes ||= arg
|
67
|
-
end
|
68
|
-
|
69
|
-
def handler(arg = nil)
|
70
|
-
@handler ||= arg
|
71
|
-
end
|
72
|
-
|
73
|
-
def middleware(arg = nil)
|
74
|
-
@middleware ||= arg
|
75
|
-
end
|
76
|
-
end
|
77
5
|
end
|
78
6
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Registrar
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Middleware
|
3
|
+
class ConvertOmniAuthHashToRegistrarHash
|
4
4
|
def initialize(app, time = Time)
|
5
5
|
@app = app
|
6
6
|
@time = time
|
@@ -15,11 +15,11 @@ module Registrar
|
|
15
15
|
|
16
16
|
def try_to_normalize_auth(env)
|
17
17
|
if env['omniauth.auth']
|
18
|
-
env['registrar.auth'] =
|
18
|
+
env['registrar.auth'] = RegistrarHash.build(env, @time)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
class
|
22
|
+
class RegistrarHash
|
23
23
|
def self.build(env, time)
|
24
24
|
new(env, time).build
|
25
25
|
end
|
data/lib/registrar/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'omniauth'
|
3
3
|
|
4
|
-
class
|
4
|
+
class ConvertOmniAuthHashToRegistrarHashSpec < Spec
|
5
5
|
let(:passed_env) { Hash.new }
|
6
6
|
|
7
7
|
it 'normalizes OmniAuth Auth Hash Schema 1.0 and later' do
|
@@ -146,8 +146,7 @@ class OmniAuthAuthBuilderSpec < Spec
|
|
146
146
|
def builder
|
147
147
|
Rack::Builder.new do
|
148
148
|
use OmniAuthFacebookStub
|
149
|
-
|
150
|
-
use Registrar::AuthBuilder::OmniAuth, TimeStub.new
|
149
|
+
use Registrar::Middleware::ConvertOmniAuthHashToRegistrarHash, TimeStub.new
|
151
150
|
|
152
151
|
app = Proc.new do |env|
|
153
152
|
['200', {'Content-Type' => 'text/html'}, ['A barebones rack app.']]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: registrar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Owiesniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -117,25 +117,19 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
+
- ".ruby-gemset"
|
121
|
+
- ".ruby-version"
|
120
122
|
- Gemfile
|
121
123
|
- LICENSE.txt
|
122
124
|
- README.md
|
123
125
|
- Rakefile
|
124
126
|
- lib/registrar.rb
|
125
|
-
- lib/registrar/auth_builder.rb
|
126
|
-
- lib/registrar/auth_builder/omni_auth.rb
|
127
|
-
- lib/registrar/debug.rb
|
128
|
-
- lib/registrar/mapper.rb
|
129
|
-
- lib/registrar/mapper/omni_auth.rb
|
130
|
-
- lib/registrar/mapper/params.rb
|
131
127
|
- lib/registrar/middleware.rb
|
132
|
-
- lib/registrar/
|
128
|
+
- lib/registrar/middleware/convert_omniauth_hash_to_registrar_hash.rb
|
133
129
|
- lib/registrar/version.rb
|
134
130
|
- registrar.gemspec
|
131
|
+
- spec/convert_omniauth_hash_to_registrar_hash_spec.rb
|
135
132
|
- spec/fixtures/omniauth_1_0_auth_hash_schema
|
136
|
-
- spec/omni_auth_adapter_spec.rb
|
137
|
-
- spec/params_mapper_spec.rb
|
138
|
-
- spec/profile_builder_spec.rb
|
139
133
|
- spec/spec_helper.rb
|
140
134
|
- vendor/GeoIP.dat
|
141
135
|
homepage: ''
|
@@ -158,13 +152,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
152
|
version: '0'
|
159
153
|
requirements: []
|
160
154
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.4.
|
155
|
+
rubygems_version: 2.4.8
|
162
156
|
signing_key:
|
163
157
|
specification_version: 4
|
164
158
|
summary: 'Registrar: Standardized Multi-Provider Registration'
|
165
159
|
test_files:
|
160
|
+
- spec/convert_omniauth_hash_to_registrar_hash_spec.rb
|
166
161
|
- spec/fixtures/omniauth_1_0_auth_hash_schema
|
167
|
-
- spec/omni_auth_adapter_spec.rb
|
168
|
-
- spec/params_mapper_spec.rb
|
169
|
-
- spec/profile_builder_spec.rb
|
170
162
|
- spec/spec_helper.rb
|
data/lib/registrar/debug.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module Registrar
|
2
|
-
class Debug
|
3
|
-
def initialize(app)
|
4
|
-
@app = app
|
5
|
-
end
|
6
|
-
|
7
|
-
def call(env)
|
8
|
-
add_debug_info(env)
|
9
|
-
@app.call(env)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def add_debug_info(env)
|
15
|
-
debug = {
|
16
|
-
'registrar.auth' => env['registrar.auth'],
|
17
|
-
'registrar.profile' => env['registrar.profile']
|
18
|
-
}
|
19
|
-
|
20
|
-
env['registrar.debug'] = to_html(debug)
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_html(debug)
|
24
|
-
"
|
25
|
-
<!DOCTYPE html>
|
26
|
-
<html>
|
27
|
-
<head>
|
28
|
-
<title>My App</title>
|
29
|
-
</head>
|
30
|
-
|
31
|
-
<body>
|
32
|
-
<pre style='white-space:pre-wrap;'>#{debug}</pre>
|
33
|
-
</body>
|
34
|
-
</html>
|
35
|
-
".gsub(/\s{2,}/,' ')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/registrar/mapper.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'registrar/mapper/params'
|
2
|
-
|
3
|
-
module Registrar
|
4
|
-
module Mapper
|
5
|
-
class OmniAuth < Params
|
6
|
-
def initialize(app)
|
7
|
-
super(app, mapping)
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def mapping
|
13
|
-
{
|
14
|
-
"profile#name" => "name",
|
15
|
-
"profile#email" => "email"
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module Registrar
|
2
|
-
module Mapper
|
3
|
-
class Params
|
4
|
-
def initialize(app, mapping)
|
5
|
-
@app = app
|
6
|
-
@mapping = mapping
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
builder = Builder.new(env, @mapping)
|
11
|
-
builder.build_registrar_params
|
12
|
-
builder.define_params
|
13
|
-
|
14
|
-
@app.call(env)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
class Builder
|
20
|
-
def initialize(env, mapping)
|
21
|
-
@env = env
|
22
|
-
@mapping = mapping
|
23
|
-
end
|
24
|
-
|
25
|
-
def build_registrar_params
|
26
|
-
begin
|
27
|
-
@mapping.each do |from, to|
|
28
|
-
namespace_from, attr_from = from.split('#')
|
29
|
-
value = request.params[namespace_from]
|
30
|
-
|
31
|
-
if value.class != String && attr_from
|
32
|
-
value = request.params[namespace_from][attr_from]
|
33
|
-
end
|
34
|
-
|
35
|
-
namespace_to, attr_to = to.split('#')
|
36
|
-
|
37
|
-
if namespace_to
|
38
|
-
if attr_to
|
39
|
-
params[namespace_to][attr_to] = value
|
40
|
-
else
|
41
|
-
params[namespace_to] = value
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
rescue NoMethodError
|
46
|
-
return
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def define_params
|
51
|
-
params.each do |namespace, values|
|
52
|
-
request.update_param(namespace, values)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def request
|
57
|
-
@request ||= Rack::Request.new(@env)
|
58
|
-
end
|
59
|
-
|
60
|
-
def params
|
61
|
-
@params ||= Hash.new {|h,k| h[k] = {}}
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Registrar
|
2
|
-
class ProfileBuilder
|
3
|
-
def initialize(app, callable)
|
4
|
-
@app = app
|
5
|
-
@callable = callable
|
6
|
-
end
|
7
|
-
|
8
|
-
def call(env)
|
9
|
-
build_profile(env)
|
10
|
-
@app.call(env)
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def build_profile(env)
|
16
|
-
if auth_hash = env['registrar.auth']
|
17
|
-
profile = @callable.call(auth_hash)
|
18
|
-
env['registrar.profile'] = profile
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/params_mapper_spec.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'omniauth'
|
3
|
-
|
4
|
-
class ParamsMapperSpec < Spec
|
5
|
-
it 'normalizes params to registrar schema' do
|
6
|
-
get '/'
|
7
|
-
assert_normalizes_params Rack::Request.new(env).params
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def assert_normalizes_params(params)
|
13
|
-
assert_equal '1', params['uid']
|
14
|
-
assert_equal 'facebook', params['provider']['name']
|
15
|
-
assert_equal 'jan@featurefabrik.de', params['contact']
|
16
|
-
assert_equal '221b Baker Street', params['info']['location']
|
17
|
-
end
|
18
|
-
|
19
|
-
def env
|
20
|
-
last_request.env
|
21
|
-
end
|
22
|
-
|
23
|
-
def response
|
24
|
-
last_response
|
25
|
-
end
|
26
|
-
|
27
|
-
def app
|
28
|
-
@app ||= build_app
|
29
|
-
end
|
30
|
-
|
31
|
-
def build_app
|
32
|
-
builder.to_app
|
33
|
-
end
|
34
|
-
|
35
|
-
class ParamsStub
|
36
|
-
def initialize(app)
|
37
|
-
@app = app
|
38
|
-
end
|
39
|
-
|
40
|
-
def call(env)
|
41
|
-
request = Rack::Request.new(env)
|
42
|
-
request.update_param('id', '1')
|
43
|
-
request.update_param('provider', 'facebook')
|
44
|
-
request.update_param('info', {
|
45
|
-
'email' => 'jan@featurefabrik.de',
|
46
|
-
'address' => '221b Baker Street'
|
47
|
-
}
|
48
|
-
)
|
49
|
-
@app.call(env)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def builder
|
54
|
-
Rack::Builder.new do
|
55
|
-
use ParamsStub
|
56
|
-
|
57
|
-
use Registrar::Mapper::Params, {
|
58
|
-
"id" => "uid",
|
59
|
-
"provider" => "provider#name",
|
60
|
-
"info#email" => "contact",
|
61
|
-
"info#address" => "info#location"
|
62
|
-
}
|
63
|
-
|
64
|
-
app = Proc.new do |env|
|
65
|
-
['200', {'Content-Type' => 'text/html'}, ['A barebones rack app.']]
|
66
|
-
end
|
67
|
-
|
68
|
-
run app
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class ProfileBuilderSpec < Spec
|
4
|
-
it 'passes registrar auth hash to callable and stores return value in the env' do
|
5
|
-
get '/'
|
6
|
-
assert_stores_profile env
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def assert_stores_profile(env)
|
12
|
-
profile = env['registrar.profile']
|
13
|
-
|
14
|
-
assert_kind_of ProfileGatewayStub::Profile, profile
|
15
|
-
assert_equal '1', profile.internal_uid
|
16
|
-
assert_equal 'facebook_123', profile.external_uid
|
17
|
-
assert_equal 'Bob', profile.name
|
18
|
-
end
|
19
|
-
|
20
|
-
def env
|
21
|
-
last_request.env
|
22
|
-
end
|
23
|
-
|
24
|
-
def response
|
25
|
-
last_response
|
26
|
-
end
|
27
|
-
|
28
|
-
def app
|
29
|
-
@app ||= build_app
|
30
|
-
end
|
31
|
-
|
32
|
-
def build_app
|
33
|
-
builder.to_app
|
34
|
-
end
|
35
|
-
|
36
|
-
class RegistrarAuthStub
|
37
|
-
def initialize(app)
|
38
|
-
@app = app
|
39
|
-
end
|
40
|
-
|
41
|
-
def call(env)
|
42
|
-
auth_hash = {
|
43
|
-
'provider' => {
|
44
|
-
'name' => 'facebook',
|
45
|
-
'uid' => '123'
|
46
|
-
},
|
47
|
-
'profile' => {
|
48
|
-
'name' => 'Bob'
|
49
|
-
}
|
50
|
-
}
|
51
|
-
env['registrar.auth'] = auth_hash
|
52
|
-
@app.call(env)
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def stubbed_auth_response
|
58
|
-
Marshal.load(auth_response_file)
|
59
|
-
end
|
60
|
-
|
61
|
-
def auth_response_file
|
62
|
-
File.read(auth_response_path)
|
63
|
-
end
|
64
|
-
|
65
|
-
def auth_response_path
|
66
|
-
"#{current_path}/fixtures/omniauth_1_0_auth_hash_schema"
|
67
|
-
end
|
68
|
-
|
69
|
-
def current_path
|
70
|
-
File.expand_path(File.dirname(__FILE__))
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class ProfileGatewayStub
|
75
|
-
def call(auth_hash)
|
76
|
-
Profile.new(auth_hash)
|
77
|
-
end
|
78
|
-
|
79
|
-
class Profile
|
80
|
-
attr_reader :internal_uid, :external_uid, :name
|
81
|
-
|
82
|
-
def initialize(auth_hash)
|
83
|
-
provider_name = auth_hash['provider']['name']
|
84
|
-
uid = auth_hash['provider']['uid']
|
85
|
-
|
86
|
-
@internal_uid = '1'
|
87
|
-
@external_uid = "#{provider_name}_#{uid}"
|
88
|
-
@name = auth_hash['profile']['name']
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def builder
|
94
|
-
Rack::Builder.new do
|
95
|
-
use RegistrarAuthStub
|
96
|
-
|
97
|
-
use Registrar::ProfileBuilder, ProfileGatewayStub.new
|
98
|
-
|
99
|
-
app = Proc.new do |env|
|
100
|
-
['200', {'Content-Type' => 'text/html'}, ['A barebones rack app.']]
|
101
|
-
end
|
102
|
-
|
103
|
-
run app
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|