omniauth-mojeid 0.0.1
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 +15 -0
- data/.gemtest +0 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.yardopts +4 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE +19 -0
- data/README.md +164 -0
- data/Rakefile +8 -0
- data/lib/attributes.rb +81 -0
- data/lib/omniauth-mojeid.rb +2 -0
- data/lib/omniauth-mojeid/version.rb +10 -0
- data/lib/omniauth/strategies/mojeid.rb +82 -0
- data/omniauth-mojeid.gemspec +39 -0
- data/spec/omniauth/strategies/mojeid_spec.rb +73 -0
- data/spec/spec_helper.rb +14 -0
- metadata +230 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTMyYzcwNjgyNGVmOGIyYjQyZjFkMTRiMDM3NDFmZjYyM2E1ODg2Zg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTJmMTAzYzUxYWMzZjVjYTExZWY5NzE4NDBkMTM0ZjAzZTJlMzAyOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmYxNmI4MDJlY2ZhYTM4NDVhYzA2NDZkMzEwMmQyODI2MzA0NTkwYjNhMDhj
|
10
|
+
YTk5NmY0MzBlMzc0MWYxNjAxMDJmZmQ3ZmIzYWM3ODcwMWMzOGFkNzA5YWE3
|
11
|
+
NjQwMWI3MGE2NWE2MDRmMWIxYjk3MjMwNWM4NzYxNTAzZjczMzg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2NhZTA4NGZlNTg5ZTAyOTQ1YjVkZjZlODM5NmU1Y2E3NzA2MzI3NWNmZWNm
|
14
|
+
Nzg3MzkwNjE5YjBhMTVkZmVmOGJkYjIzNTQyODRiMjI1MzFmYjA4MjJhOTIx
|
15
|
+
MDM4YWY1YWMxYjIxNzIyN2U5MmJlYjg0YzdjZGI1MWUyMjY0Njc=
|
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# OmniAuth::MojeID
|
2
|
+
|
3
|
+
> [MojeID](http://www.mojeid.cz) authentication strategy.
|
4
|
+
|
5
|
+
OmniAuth::MojeID is an extension to [OmniAuth::OpenID](https://github.com/intridea/omniauth-openid) with some useful defaults and added attributes.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install omniauth-mojeid
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
### Rails 3 + Devise + OmniAuthable
|
14
|
+
|
15
|
+
Inside `devise.rb`, add a simple line:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
config.omniauth :mojeid
|
19
|
+
```
|
20
|
+
|
21
|
+
This will prompt the user for the default attributes. If you want to configure which attributes to obtain from the user, specify them in the `required` and `optional` fields.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
config.omniauth :mojeid, :required => [:name, :email], :optional => [:city]
|
25
|
+
```
|
26
|
+
|
27
|
+
See full list of [profile attributes](#profile-attributes).
|
28
|
+
|
29
|
+
### Stand-Alone Example
|
30
|
+
|
31
|
+
Use the strategy as a middleware in your application:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'omniauth-mojeid'
|
35
|
+
|
36
|
+
use Rack::Session::Cookie
|
37
|
+
use OmniAuth::Strategies::MojeID
|
38
|
+
```
|
39
|
+
|
40
|
+
### OmniAuth Builder
|
41
|
+
|
42
|
+
If MojeID is one of several authentication strategies, use the OmniAuth Builder:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'omniauth-mojeid'
|
46
|
+
|
47
|
+
use OmniAuth::Builder do
|
48
|
+
provider :mojeid
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
By default, the omniauth information during the response handling is stored in ruby-openid's Memory Store. To change this, override the `store` option:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'omniauth-openid'
|
56
|
+
require 'openid/store/filesystem'
|
57
|
+
|
58
|
+
use OmniAuth::Builder do
|
59
|
+
provider :mojeid, :store => OpenID::Store::Filesystem.new('/tmp')
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
Simply point users to `/auth/mojeid` which will redirect them to MojeID.cz website to prompt them for their profile information.
|
66
|
+
|
67
|
+
In the response callback at `/auth/mojeid/callback`, the attributes will become available in the `["omniauth.auth"]["info"]` hash. So, to print out user's email, use `["omniauth.auth"]["info"][:email]`.
|
68
|
+
|
69
|
+
To learn about the internals please read [the specification](https://www.mojeid.cz/files/mojeid/mojeid_technicky.pdf) (in Czech).
|
70
|
+
|
71
|
+
|
72
|
+
## Profile attributes
|
73
|
+
|
74
|
+
By default, mojeid asks user for the following profile attributes:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
:required => [:email, :name, :first_name, :last_name]
|
78
|
+
:optional => [:nickname, :street, :city, :postal_code, :country]
|
79
|
+
```
|
80
|
+
|
81
|
+
If you want to customize the information, use the attributes listed in the table below.
|
82
|
+
|
83
|
+
You can also use the [Simple Reg](http://openid.net/specs/openid-simple-registration-extension-1_0.html) name (as a string) to name the attributes. (Though in my experience the mapping doesn't seem to be working well.)
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
:required => ['email', 'fullname', :first_name, :last_name, 'dob']
|
87
|
+
```
|
88
|
+
|
89
|
+
Note that the user can decide if they share the information with you, so even if you request certain fields, they may be empty (`nil`).
|
90
|
+
|
91
|
+
Also note that you **may not** request the same attribute both in the `required` and `optional` fields, otherwise an error will be raised.
|
92
|
+
|
93
|
+
|
94
|
+
<table>
|
95
|
+
<tr><th>Attribute</th><th>Identifier</th></tr>
|
96
|
+
<tr><td>:name</td><td>http://axschema.org/namePerson</td></tr>
|
97
|
+
<tr><td>:nickname</td><td>http://axschema.org/namePerson/friendly</td></tr>
|
98
|
+
<tr><td>:first_name</td><td>http://axschema.org/namePerson/first</td></tr>
|
99
|
+
<tr><td>:last_name</td><td>http://axschema.org/namePerson/last</td></tr>
|
100
|
+
<tr><td>:company_name</td><td>http://axschema.org/company/name</td></tr>
|
101
|
+
<tr><td>:street</td><td>http://axschema.org/contact/postalAddress/home</td></tr>
|
102
|
+
<tr><td>:street2</td><td>http://axschema.org/contact/postalAddressAdditional/home</td></tr>
|
103
|
+
<tr><td>:street3</td><td>http://specs.nic.cz/attr/addr/main/street3</td></tr>
|
104
|
+
<tr><td>:city</td><td>http://axschema.org/contact/city/home</td></tr>
|
105
|
+
<tr><td>:state</td><td>http://axschema.org/contact/state/home</td></tr>
|
106
|
+
<tr><td>:country</td><td>http://axschema.org/contact/country/home</td></tr>
|
107
|
+
<tr><td>:postal_code</td><td>http://axschema.org/contact/postalCode/home</td></tr>
|
108
|
+
<tr><td>:billing_street</td><td>http://specs.nic.cz/attr/addr/bill/street</td></tr>
|
109
|
+
<tr><td>:billing_street2</td><td>http://specs.nic.cz/attr/addr/bill/street2</td></tr>
|
110
|
+
<tr><td>:billing_street3</td><td>http://specs.nic.cz/attr/addr/bill/street3</td></tr>
|
111
|
+
<tr><td>:billing_city</td><td>http://specs.nic.cz/attr/addr/bill/city</td></tr>
|
112
|
+
<tr><td>:billing_state</td><td>http://specs.nic.cz/attr/addr/bill/sp</td></tr>
|
113
|
+
<tr><td>:billing_country</td><td>http://specs.nic.cz/attr/addr/bill/cc</td></tr>
|
114
|
+
<tr><td>:billing_postal_code</td><td>http://specs.nic.cz/attr/addr/bill/pc</td></tr>
|
115
|
+
<tr><td>:shipping_street</td><td>http://specs.nic.cz/attr/addr/ship/street</td></tr>
|
116
|
+
<tr><td>:shipping_street2</td><td>http://specs.nic.cz/attr/addr/ship/street2</td></tr>
|
117
|
+
<tr><td>:shipping_street3</td><td>http://specs.nic.cz/attr/addr/ship/street3</td></tr>
|
118
|
+
<tr><td>:shipping_city</td><td>http://specs.nic.cz/attr/addr/ship/city</td></tr>
|
119
|
+
<tr><td>:shipping_state</td><td>http://specs.nic.cz/attr/addr/ship/sp</td></tr>
|
120
|
+
<tr><td>:shipping_country</td><td>http://specs.nic.cz/attr/addr/ship/cc</td></tr>
|
121
|
+
<tr><td>:shipping_postal_code</td><td>http://specs.nic.cz/attr/addr/ship/pc</td></tr>
|
122
|
+
<tr><td>:mailing_street</td><td>http://specs.nic.cz/attr/addr/mail/street</td></tr>
|
123
|
+
<tr><td>:mailing_street2</td><td>http://specs.nic.cz/attr/addr/mail/street2</td></tr>
|
124
|
+
<tr><td>:mailing_street3</td><td>http://specs.nic.cz/attr/addr/mail/street3</td></tr>
|
125
|
+
<tr><td>:mailing_city</td><td>http://specs.nic.cz/attr/addr/mail/city</td></tr>
|
126
|
+
<tr><td>:mailing_state</td><td>http://specs.nic.cz/attr/addr/mail/sp</td></tr>
|
127
|
+
<tr><td>:mailing_country</td><td>http://specs.nic.cz/attr/addr/mail/cc</td></tr>
|
128
|
+
<tr><td>:mailing_postal_code</td><td>http://specs.nic.cz/attr/addr/mail/pc</td></tr>
|
129
|
+
<tr><td>:phone</td><td>http://axschema.org/contact/phone/default</td></tr>
|
130
|
+
<tr><td>:phone_home</td><td>http://axschema.org/contact/phone/home</td></tr>
|
131
|
+
<tr><td>:phone_business</td><td>http://axschema.org/contact/phone/business</td></tr>
|
132
|
+
<tr><td>:phone_cell</td><td>http://axschema.org/contact/phone/cell</td></tr>
|
133
|
+
<tr><td>:phone_fax</td><td>http://axschema.org/contact/phone/fax</td></tr>
|
134
|
+
<tr><td>:email</td><td>http://axschema.org/contact/email</td></tr>
|
135
|
+
<tr><td>:email_notify</td><td>http://specs.nic.cz/attr/email/notify</td></tr>
|
136
|
+
<tr><td>:email_other</td><td>http://specs.nic.cz/attr/email/next</td></tr>
|
137
|
+
<tr><td>:website</td><td>http://axschema.org/contact/web/default</td></tr>
|
138
|
+
<tr><td>:blog</td><td>http://axschema.org/contact/web/blog</td></tr>
|
139
|
+
<tr><td>:personal_url</td><td>http://specs.nic.cz/attr/url/personal</td></tr>
|
140
|
+
<tr><td>:work_url</td><td>http://specs.nic.cz/attr/url/work</td></tr>
|
141
|
+
<tr><td>:rss</td><td>http://specs.nic.cz/attr/url/rss</td></tr>
|
142
|
+
<tr><td>:facebook</td><td>http://specs.nic.cz/attr/url/facebook</td></tr>
|
143
|
+
<tr><td>:twitter</td><td>http://specs.nic.cz/attr/url/twitter</td></tr>
|
144
|
+
<tr><td>:linkedin</td><td>http://specs.nic.cz/attr/url/linkedin</td></tr>
|
145
|
+
<tr><td>:icq</td><td>http://axschema.org/contact/IM/ICQ</td></tr>
|
146
|
+
<tr><td>:jabber</td><td>http://axschema.org/contact/IM/Jabber</td></tr>
|
147
|
+
<tr><td>:skype</td><td>http://axschema.org/contact/IM/Skype</td></tr>
|
148
|
+
<tr><td>:gtalk</td><td>http://specs.nic.cz/attr/im/google_talk</td></tr>
|
149
|
+
<tr><td>:live_id</td><td>http://specs.nic.cz/attr/im/windows_live</td></tr>
|
150
|
+
<tr><td>:vat_id</td><td>http://specs.nic.cz/attr/contact/ident/vat_id</td></tr>
|
151
|
+
<tr><td>:vat</td><td>http://specs.nic.cz/attr/contact/vat</td></tr>
|
152
|
+
<tr><td>:id_card</td><td>http://specs.nic.cz/attr/contact/ident/card</td></tr>
|
153
|
+
<tr><td>:passport</td><td>http://specs.nic.cz/attr/contact/ident/pass</td></tr>
|
154
|
+
<tr><td>:ssn</td><td>http://specs.nic.cz/attr/contact/ident/ssn</td></tr>
|
155
|
+
<tr><td>:student</td><td>http://specs.nic.cz/attr/contact/student</td></tr>
|
156
|
+
<tr><td>:valid</td><td>http://specs.nic.cz/attr/contact/valid</td></tr>
|
157
|
+
<tr><td>:status</td><td>http://specs.nic.cz/attr/contact/status</td></tr>
|
158
|
+
<tr><td>:adult</td><td>http://specs.nic.cz/attr/contact/adult</td></tr>
|
159
|
+
<tr><td>:image</td><td>http://specs.nic.cz/attr/contact/image</td></tr>
|
160
|
+
</table>
|
161
|
+
|
162
|
+
## License
|
163
|
+
|
164
|
+
MIT License
|
data/Rakefile
ADDED
data/lib/attributes.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# for more informations about attributes look at http://www.mojeid.cz/page/800/jak-zavest-mojeid-/
|
2
|
+
|
3
|
+
module MojeIDAttributes
|
4
|
+
MOJE_ID = {
|
5
|
+
:name => 'http://axschema.org/namePerson',
|
6
|
+
:nickname => 'http://axschema.org/namePerson/friendly',
|
7
|
+
:first_name => 'http://axschema.org/namePerson/first',
|
8
|
+
:last_name => 'http://axschema.org/namePerson/last',
|
9
|
+
|
10
|
+
:company_name => 'http://axschema.org/company/name',
|
11
|
+
|
12
|
+
:street => 'http://axschema.org/contact/postalAddress/home',
|
13
|
+
:street2 => 'http://axschema.org/contact/postalAddressAdditional/home',
|
14
|
+
:street3 => 'http://specs.nic.cz/attr/addr/main/street3',
|
15
|
+
:city => 'http://axschema.org/contact/city/home',
|
16
|
+
:state => 'http://axschema.org/contact/state/home',
|
17
|
+
:country => 'http://axschema.org/contact/country/home',
|
18
|
+
:postal_code => 'http://axschema.org/contact/postalCode/home',
|
19
|
+
|
20
|
+
:billing_street => 'http://specs.nic.cz/attr/addr/bill/street',
|
21
|
+
:billing_street2 => 'http://specs.nic.cz/attr/addr/bill/street2',
|
22
|
+
:billing_street3 => 'http://specs.nic.cz/attr/addr/bill/street3',
|
23
|
+
:billing_city => 'http://specs.nic.cz/attr/addr/bill/city',
|
24
|
+
:billing_state => 'http://specs.nic.cz/attr/addr/bill/sp',
|
25
|
+
:billing_country => 'http://specs.nic.cz/attr/addr/bill/cc',
|
26
|
+
:billing_postal_code => 'http://specs.nic.cz/attr/addr/bill/pc',
|
27
|
+
|
28
|
+
:shipping_street => 'http://specs.nic.cz/attr/addr/ship/street',
|
29
|
+
:shipping_street2 => 'http://specs.nic.cz/attr/addr/ship/street2',
|
30
|
+
:shipping_street3 => 'http://specs.nic.cz/attr/addr/ship/street3',
|
31
|
+
:shipping_city => 'http://specs.nic.cz/attr/addr/ship/city',
|
32
|
+
:shipping_state => 'http://specs.nic.cz/attr/addr/ship/sp',
|
33
|
+
:shipping_country => 'http://specs.nic.cz/attr/addr/ship/cc',
|
34
|
+
:shipping_postal_code => 'http://specs.nic.cz/attr/addr/ship/pc',
|
35
|
+
|
36
|
+
:mailing_street => 'http://specs.nic.cz/attr/addr/mail/street',
|
37
|
+
:mailing_street2 => 'http://specs.nic.cz/attr/addr/mail/street2',
|
38
|
+
:mailing_street3 => 'http://specs.nic.cz/attr/addr/mail/street3',
|
39
|
+
:mailing_city => 'http://specs.nic.cz/attr/addr/mail/city',
|
40
|
+
:mailing_state => 'http://specs.nic.cz/attr/addr/mail/sp',
|
41
|
+
:mailing_country => 'http://specs.nic.cz/attr/addr/mail/cc',
|
42
|
+
:mailing_postal_code => 'http://specs.nic.cz/attr/addr/mail/pc',
|
43
|
+
|
44
|
+
:phone => 'http://axschema.org/contact/phone/default',
|
45
|
+
:phone_home => 'http://axschema.org/contact/phone/home',
|
46
|
+
:phone_business => 'http://axschema.org/contact/phone/business',
|
47
|
+
:phone_cell => 'http://axschema.org/contact/phone/cell',
|
48
|
+
:phone_fax => 'http://axschema.org/contact/phone/fax',
|
49
|
+
|
50
|
+
:email => 'http://axschema.org/contact/email',
|
51
|
+
:email_notify => 'http://specs.nic.cz/attr/email/notify',
|
52
|
+
:email_other => 'http://specs.nic.cz/attr/email/next',
|
53
|
+
|
54
|
+
:website => 'http://axschema.org/contact/web/default',
|
55
|
+
:blog => 'http://axschema.org/contact/web/blog',
|
56
|
+
:personal_url => 'http://specs.nic.cz/attr/url/personal',
|
57
|
+
:work_url => 'http://specs.nic.cz/attr/url/work',
|
58
|
+
:rss => 'http://specs.nic.cz/attr/url/rss',
|
59
|
+
:facebook => 'http://specs.nic.cz/attr/url/facebook',
|
60
|
+
:twitter => 'http://specs.nic.cz/attr/url/twitter',
|
61
|
+
:linkedin => 'http://specs.nic.cz/attr/url/linkedin',
|
62
|
+
|
63
|
+
:icq => 'http://axschema.org/contact/IM/ICQ',
|
64
|
+
:jabber => 'http://axschema.org/contact/IM/Jabber',
|
65
|
+
:skype => 'http://axschema.org/contact/IM/Skype',
|
66
|
+
:gtalk => 'http://specs.nic.cz/attr/im/google_talk',
|
67
|
+
:live_id => 'http://specs.nic.cz/attr/im/windows_live',
|
68
|
+
|
69
|
+
:vat_id => 'http://specs.nic.cz/attr/contact/ident/vat_id',
|
70
|
+
:vat => 'http://specs.nic.cz/attr/contact/vat',
|
71
|
+
|
72
|
+
:id_card => 'http://specs.nic.cz/attr/contact/ident/card',
|
73
|
+
:passport => 'http://specs.nic.cz/attr/contact/ident/pass',
|
74
|
+
:ssn => 'http://specs.nic.cz/attr/contact/ident/ssn',
|
75
|
+
:student => 'http://specs.nic.cz/attr/contact/student',
|
76
|
+
:valid => 'http://specs.nic.cz/attr/contact/valid',
|
77
|
+
:status => 'http://specs.nic.cz/attr/contact/status',
|
78
|
+
:adult => 'http://specs.nic.cz/attr/contact/adult',
|
79
|
+
:image => 'http://specs.nic.cz/attr/contact/image'
|
80
|
+
}
|
81
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'omniauth'
|
2
|
+
require 'omniauth-openid'
|
3
|
+
require 'rack/openid'
|
4
|
+
require 'openid/store/memory'
|
5
|
+
require 'attributes'
|
6
|
+
|
7
|
+
module OmniAuth
|
8
|
+
module Strategies
|
9
|
+
# OmniAuth strategy for connecting via MojeID.
|
10
|
+
class MojeID < OmniAuth::Strategies::OpenID
|
11
|
+
include OmniAuth::Strategy
|
12
|
+
include MojeIDAttributes
|
13
|
+
|
14
|
+
option :name, :mojeid
|
15
|
+
option :required, [:email, :name, :first_name, :last_name]
|
16
|
+
option :optional, [:nickname, :street, :city, :postal_code, :country]
|
17
|
+
option :store, ::OpenID::Store::Memory.new
|
18
|
+
option :identifier, 'https://mojeid.cz/endpoint/'
|
19
|
+
# option :identifier_param, 'mojeid_url'
|
20
|
+
|
21
|
+
# Called by omniauth when /auth/mojeid is opened.
|
22
|
+
def request_phase
|
23
|
+
openid = Rack::OpenID.new(dummy_app, options[:store])
|
24
|
+
response = openid.call(env)
|
25
|
+
case env['rack.openid.response']
|
26
|
+
when Rack::OpenID::MissingResponse, Rack::OpenID::TimeoutResponse
|
27
|
+
fail!(:connection_failed)
|
28
|
+
else
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
uid { openid_response.display_identifier }
|
34
|
+
|
35
|
+
info do
|
36
|
+
sreg_user_info.merge(ax_user_info)
|
37
|
+
end
|
38
|
+
|
39
|
+
extra do
|
40
|
+
{ 'response' => openid_response }
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# Simple app that builds the request.
|
47
|
+
def dummy_app
|
48
|
+
lambda{|env| [401, {"WWW-Authenticate" => Rack::OpenID.build_header(
|
49
|
+
:identifier => identifier,
|
50
|
+
:return_to => callback_url,
|
51
|
+
:required => options.required.map { |att| MOJE_ID[att] || att },
|
52
|
+
:optional => options.optional.map { |att| MOJE_ID[att] || att },
|
53
|
+
:method => 'post'
|
54
|
+
)}, []]}
|
55
|
+
end
|
56
|
+
|
57
|
+
# Extract SReg attributes.
|
58
|
+
# http://openid.net/specs/openid-simple-registration-extension-1_0.html
|
59
|
+
def sreg_user_info
|
60
|
+
sreg = ::OpenID::SReg::Response.from_success_response(openid_response)
|
61
|
+
return {} unless sreg
|
62
|
+
attrs = %w{fullname nickname dob email gender postcode country language timezone}
|
63
|
+
Hash[
|
64
|
+
attrs.map { |att| [att, sreg[att]] }
|
65
|
+
].reject{|k,v| v.nil? || v == ''}
|
66
|
+
end
|
67
|
+
|
68
|
+
# Extract all available user user profile attributes.
|
69
|
+
# https://www.mojeid.cz/files/mojeid/mojeid_technicky.pdf
|
70
|
+
def ax_user_info
|
71
|
+
ax = ::OpenID::AX::FetchResponse.from_success_response(openid_response)
|
72
|
+
return {} unless ax
|
73
|
+
Hash[
|
74
|
+
MOJE_ID.map { |key,att| [key,ax.get_single(att)] }
|
75
|
+
].reject{|k,v| v.nil? || v == ''}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
OmniAuth.config.add_camelization 'mojeid', 'MojeID'
|
82
|
+
OmniAuth.config.add_camelization 'Mojeid', 'MojeID'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../lib/omniauth-mojeid/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'omniauth-mojeid'
|
6
|
+
gem.version = OmniAuth::MojeID::VERSION
|
7
|
+
gem.summary = %Q{MojeID strategy for OmniAuth}
|
8
|
+
gem.description = %q{OmniAuth strategy to work with http://www.mojeid.cz}
|
9
|
+
gem.homepage = 'https://github.com/petrbela/omniauth-mojeid'
|
10
|
+
|
11
|
+
gem.authors = ['Petr Bela']
|
12
|
+
gem.email = 'github@petrbela.com'
|
13
|
+
gem.license = "MIT"
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if gem.respond_to?(:required_rubygems_version=)
|
19
|
+
|
20
|
+
gem.add_dependency 'omniauth', '~> 1.1.4'
|
21
|
+
gem.add_dependency 'rack-openid', '~> 1.3.1'
|
22
|
+
gem.add_dependency 'ruby-openid', '~> 2.1.8'
|
23
|
+
gem.add_dependency 'omniauth-openid', '~> 1.0.1'
|
24
|
+
gem.add_dependency 'json', '~> 1.7.7'
|
25
|
+
|
26
|
+
gem.add_development_dependency 'rack-test', '~> 0.5'
|
27
|
+
gem.add_development_dependency 'rspec', '~> 2.8.0'
|
28
|
+
gem.add_development_dependency 'rake', '~> 0.8'
|
29
|
+
gem.add_development_dependency 'rdiscount', '~> 1.6'
|
30
|
+
gem.add_development_dependency 'simplecov', '~> 0.4'
|
31
|
+
gem.add_development_dependency 'webmock', '~> 1.7'
|
32
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
33
|
+
# gem 'guard'
|
34
|
+
# gem 'guard-rspec'
|
35
|
+
# gem 'growl'
|
36
|
+
# gem 'rb-fsevent', '~> 0.9.3'
|
37
|
+
# gem 'bundler', '~> 1.3.4'
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/openid'
|
3
|
+
require 'omniauth-mojeid'
|
4
|
+
|
5
|
+
describe OmniAuth::Strategies::MojeID, :type => :strategy do
|
6
|
+
def app
|
7
|
+
Rack::Builder.new {
|
8
|
+
use Rack::Session::Cookie
|
9
|
+
use OmniAuth::Strategies::MojeID
|
10
|
+
run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [nil || env.key?('omniauth.auth').to_s]] }
|
11
|
+
}.to_app
|
12
|
+
end
|
13
|
+
|
14
|
+
def expired_query_string
|
15
|
+
'openid=consumer&janrain_nonce=2011-07-21T20%3A14%3A56ZJ8LP3T&openid.assoc_handle=%7BHMAC-SHA1%7D%7B4e284c39%7D%7B9nvQeg%3D%3D%7D&openid.claimed_id=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.identity=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.op_endpoint=http%3A%2F%2Flocalhost%3A1123%2Fserver%2F%3Fopenid.success%3Dtrue&openid.response_nonce=2011-07-21T20%3A14%3A56Zf9gC8S&openid.return_to=http%3A%2F%2Flocalhost%3A8888%2FDevelopment%2FWordpress%2Fwp_openid%2F%3Fopenid%3Dconsumer%26janrain_nonce%3D2011-07-21T20%253A14%253A56ZJ8LP3T&openid.sig=GufV13SUJt8VgmSZ92jGZCFBEvQ%3D&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Csigned'
|
16
|
+
end
|
17
|
+
|
18
|
+
# PENDING
|
19
|
+
describe '/auth/mojeid should redirect to mojeid.cz/endpoint', :pending do
|
20
|
+
context 'successful' do
|
21
|
+
before do
|
22
|
+
# TODO: change this mock to actually return some sort of OpenID response
|
23
|
+
stub_request(:get, @identifier_url)
|
24
|
+
get '/auth/mojeid'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should redirect to MojeID website' do
|
28
|
+
last_response.should be_redirect
|
29
|
+
last_response.headers['Location'].should =~ %r{^https://mojeid\.cz/endpoint.*}
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should tell MojeID server to return to the callback URL' do
|
33
|
+
return_to = CGI.escape(last_request.url + '/callback')
|
34
|
+
last_response.headers['Location'].should =~ %r{[\?&]openid.return_to=#{return_to}}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# PENDING
|
40
|
+
describe 'followed by /auth/mojeid/callback', :pending do
|
41
|
+
context 'successful' do
|
42
|
+
#before do
|
43
|
+
# @identifier_url = 'http://me.example.org'
|
44
|
+
# # TODO: change this mock to actually return some sort of OpenID response
|
45
|
+
# stub_request(:get, @identifier_url)
|
46
|
+
# get '/auth/mojeid/callback'
|
47
|
+
#end
|
48
|
+
|
49
|
+
it "should set provider to mojeid"
|
50
|
+
it "should create auth_hash based on sreg"
|
51
|
+
it "should create auth_hash based on ax"
|
52
|
+
|
53
|
+
#it 'should call through to the master app' do
|
54
|
+
# last_response.body.should == 'true'
|
55
|
+
#end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'unsuccessful' do
|
59
|
+
describe 'returning with expired credentials' do
|
60
|
+
before do
|
61
|
+
# get '/auth/mojeid/callback?' + expired_query_string
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'it should redirect to invalid credentials' do
|
65
|
+
pending
|
66
|
+
last_response.should be_redirect
|
67
|
+
last_response.headers['Location'].should =~ %r{invalid_credentials}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rack/test'
|
6
|
+
require 'rspec'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'omniauth-mojeid'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include WebMock::API
|
12
|
+
config.include Rack::Test::Methods
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-mojeid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Petr Bela
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-openid
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-openid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.1.8
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.1.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: omniauth-openid
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.7.7
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.7.7
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-test
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.8.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.8.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rdiscount
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.6'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.6'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.4'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.4'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.7'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.7'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.7'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.7'
|
181
|
+
description: OmniAuth strategy to work with http://www.mojeid.cz
|
182
|
+
email: github@petrbela.com
|
183
|
+
executables: []
|
184
|
+
extensions: []
|
185
|
+
extra_rdoc_files: []
|
186
|
+
files:
|
187
|
+
- .gemtest
|
188
|
+
- .gitignore
|
189
|
+
- .rspec
|
190
|
+
- .yardopts
|
191
|
+
- Gemfile
|
192
|
+
- Guardfile
|
193
|
+
- LICENSE
|
194
|
+
- README.md
|
195
|
+
- Rakefile
|
196
|
+
- lib/attributes.rb
|
197
|
+
- lib/omniauth-mojeid.rb
|
198
|
+
- lib/omniauth-mojeid/version.rb
|
199
|
+
- lib/omniauth/strategies/mojeid.rb
|
200
|
+
- omniauth-mojeid.gemspec
|
201
|
+
- spec/omniauth/strategies/mojeid_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
homepage: https://github.com/petrbela/omniauth-mojeid
|
204
|
+
licenses:
|
205
|
+
- MIT
|
206
|
+
metadata: {}
|
207
|
+
post_install_message:
|
208
|
+
rdoc_options: []
|
209
|
+
require_paths:
|
210
|
+
- lib
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ! '>='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ! '>='
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: 1.3.6
|
221
|
+
requirements: []
|
222
|
+
rubyforge_project:
|
223
|
+
rubygems_version: 2.0.3
|
224
|
+
signing_key:
|
225
|
+
specification_version: 4
|
226
|
+
summary: MojeID strategy for OmniAuth
|
227
|
+
test_files:
|
228
|
+
- spec/omniauth/strategies/mojeid_spec.rb
|
229
|
+
- spec/spec_helper.rb
|
230
|
+
has_rdoc:
|