registrar 0.0.6.alpha → 0.0.7.alpha
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.
- checksums.yaml +4 -4
- data/README.md +195 -19
- data/lib/registrar/mapper/params.rb +16 -12
- data/lib/registrar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e0846eb286e5dde2da78b35d401a5b12b799752e
|
|
4
|
+
data.tar.gz: a4f0585126ca74ef7691b024b343a71cacca09a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0caf9d2c2ddd141625bb46ab37cba7c185f03a141a81148bd2da9e38ac209cc640f3ecef331e7373373a16e84b13b5da26f487378d15febd3997d8c7d7af6f1
|
|
7
|
+
data.tar.gz: 65bd17e37f1accc74d8b81c3f3e146e5cda6726e045646a68fb0097593baadec87fe1be011416f94ad39922ada4fc7a4ff70a7cb28acbe5641412c918b2db770
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[gem-badge]: https://img.shields.io/gem/v/registrar.svg
|
|
5
5
|
[rack-playground]: https://github.com/JanOwiesniak/rack-playground/blob/master/lib/app_builder.rb
|
|
6
6
|
|
|
7
|
-
# Registrar
|
|
7
|
+
# Registrar: Standardized Multi-Provider Registration
|
|
8
8
|
|
|
9
9
|
[![Gem Version][gem-badge]][gem]
|
|
10
10
|
|
|
@@ -12,49 +12,225 @@
|
|
|
12
12
|
[Source][github] |
|
|
13
13
|
[Documentation][doc]
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## Introduction
|
|
16
16
|
|
|
17
|
-
Registrar standardizes
|
|
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
18
|
|
|
19
|
-
##
|
|
19
|
+
## Description
|
|
20
20
|
|
|
21
|
-
|
|
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`
|
|
22
34
|
|
|
23
35
|
```ruby
|
|
24
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
|
|
25
76
|
```
|
|
26
77
|
|
|
27
|
-
|
|
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
|
+
```
|
|
28
138
|
|
|
29
|
-
|
|
139
|
+
Currently, the AuthBuilder just transforms the Hash into a different structure.
|
|
30
140
|
|
|
31
|
-
|
|
141
|
+
To do something with the authenticated user (e.g. sign up or sign in), use the profile builder.
|
|
32
142
|
|
|
33
|
-
|
|
143
|
+
Open up you Middewarestack again.
|
|
34
144
|
|
|
35
|
-
|
|
145
|
+
```ruby
|
|
146
|
+
require 'registrar'
|
|
147
|
+
require 'omniauth-facebook-access-token'
|
|
36
148
|
|
|
37
|
-
|
|
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
|
|
38
154
|
|
|
39
|
-
|
|
155
|
+
# Transform the OmniAuth Schema env['omniauth.auth'] into the Registrar Schema env['registrar.auth']
|
|
156
|
+
use Registrar::AuthBuilder::OmniAuth
|
|
40
157
|
|
|
41
|
-
|
|
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 }
|
|
42
160
|
|
|
43
|
-
|
|
161
|
+
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] }
|
|
162
|
+
end
|
|
44
163
|
|
|
45
|
-
|
|
164
|
+
run app
|
|
165
|
+
```
|
|
46
166
|
|
|
47
|
-
|
|
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
|
+
```
|
|
48
197
|
|
|
49
|
-
|
|
198
|
+
If your application supports the concept of a session your could store env['registrar.profile'] in your session to log the user in.
|
|
50
199
|
|
|
51
|
-
|
|
52
|
-
|
|
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.
|
|
53
223
|
|
|
54
224
|
## Contributing
|
|
55
225
|
|
|
226
|
+
0. Check out the [Wiki](https://github.com/JanOwiesniak/registrar/wiki)
|
|
56
227
|
1. Fork it ( https://github.com/JanOwiesniak/registrar/fork )
|
|
57
228
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
58
229
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
59
230
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
60
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
|
|
@@ -23,23 +23,27 @@ module Registrar
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def build_registrar_params
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
begin
|
|
27
|
+
@mapping.each do |from, to|
|
|
28
|
+
namespace_from, attr_from = from.split('#')
|
|
29
|
+
value = request.params[namespace_from]
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
if value.class != String && attr_from
|
|
32
|
+
value = request.params[namespace_from][attr_from]
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
namespace_to, attr_to = to.split('#')
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
if namespace_to
|
|
38
|
+
if attr_to
|
|
39
|
+
params[namespace_to][attr_to] = value
|
|
40
|
+
else
|
|
41
|
+
params[namespace_to] = value
|
|
42
|
+
end
|
|
41
43
|
end
|
|
42
44
|
end
|
|
45
|
+
rescue NoMethodError
|
|
46
|
+
return
|
|
43
47
|
end
|
|
44
48
|
end
|
|
45
49
|
|
data/lib/registrar/version.rb
CHANGED
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.0.
|
|
4
|
+
version: 0.0.7.alpha
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jan Owiesniak
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: omniauth
|