omniauth-orcid 1.2.3 → 2.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.
- checksums.yaml +4 -4
- data/README.md +56 -6
- data/lib/omniauth/orcid/version.rb +1 -1
- data/lib/omniauth/strategies/orcid.rb +27 -27
- data/omniauth-orcid.gemspec +1 -1
- data/spec/fixtures/access_token.json +9 -0
- data/spec/fixtures/request_info.json +213 -0
- data/spec/omniauth/strategies/orcid_spec.rb +83 -19
- data/spec/spec_helper.rb +4 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc033017ce0638e8e20fbec70003539d806ec89
|
4
|
+
data.tar.gz: 8dcc4883295d1e26f5d50fcec5a633388f0ca13e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c364fee700aaf0781d9f38a886a9f78121f237033aefaad932a212d42e4953c755070d5e27e79cf380a39c9ce68773ef1139498f80e10cb6b6cfb4a0c103d732
|
7
|
+
data.tar.gz: a74e74f9c6d2522a6cea476b84a73764e05fd06cd08a03aceba3b64b20143eb286d4b26af27d28fb3378b16a1422a76d0df8b67f3a1e61d211cad0d104451867
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ use OmniAuth::Builder do
|
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
62
|
-
`omniauth-orcid` sets the appropriate default scope depending on the `member`
|
62
|
+
`omniauth-orcid` sets the appropriate default scope depending on the `member` flag:
|
63
63
|
|
64
64
|
* non-member: `/authenticate`
|
65
65
|
* member: `/read-limited /activities/update /person/update`
|
@@ -74,7 +74,14 @@ OmniAuth takes care of the OAuth external-authentication handshake or "dance". A
|
|
74
74
|
"uid": "0000-0003-2012-0010",
|
75
75
|
"info": {
|
76
76
|
"name": "John Smith",
|
77
|
-
"email":
|
77
|
+
"email": "jsmith@example.com",
|
78
|
+
"first_name": "John",
|
79
|
+
"last_name": "Smith",
|
80
|
+
"location": "GB",
|
81
|
+
"description": "John Smith is the ...",
|
82
|
+
"urls": [
|
83
|
+
{ "Blog": "http://blog.martinfenner.org" }
|
84
|
+
]
|
78
85
|
},
|
79
86
|
"credentials": {
|
80
87
|
"token": "e82938fa-a287-42cf-a2ce-f48ef68c9a35",
|
@@ -83,13 +90,32 @@ OmniAuth takes care of the OAuth external-authentication handshake or "dance". A
|
|
83
90
|
"expires": true
|
84
91
|
},
|
85
92
|
"extra": {
|
93
|
+
"raw_info": {
|
94
|
+
"email": "jsmith@example.com",
|
95
|
+
"first_name": "John",
|
96
|
+
"last_name": "Smith",
|
97
|
+
"other_names": ["John Fitzgerald Smith"],
|
98
|
+
"location": "GB",
|
99
|
+
"description": "John Smith is the ...",
|
100
|
+
"urls": [
|
101
|
+
{ "Blog": "http://blog.martinfenner.org" }
|
102
|
+
],
|
103
|
+
"external_identifiers": [
|
104
|
+
{ "type": "GitHub",
|
105
|
+
"value":"mfenner",
|
106
|
+
"url": "https://github.com/mfenner" }
|
107
|
+
]
|
108
|
+
}
|
86
109
|
}
|
87
110
|
}
|
88
111
|
```
|
112
|
+
ject. Martin has a medical degree from the Free University of Berlin and is a Board-certified medical oncologist.", :location=>["DE"], :urls=>["http://blog.martinfenner.org"], :external_identifiers=>[{"type"=>"GitHub", "value"=>"mfenner", "url"=>"https://github.com/mfenner"}]}
|
113
|
+
........
|
114
|
+
|
89
115
|
|
90
116
|
You have to implement a callback handler to grab at least the `uid` from the hash and (typically) save it in a session. This effectively provides basic **Log in with your ORCID** functionality.
|
91
117
|
|
92
|
-
Most likely, with the token in hand, you'll want to do something more sophisticated with the API, like retrieving profile data and do something cool with it. See the [
|
118
|
+
Most likely, with the token in hand, you'll want to do something more sophisticated with the API, like retrieving profile data and do something cool with it. See the [Basic Tutorial: Read data on ORCID record](http://members.orcid.org/api/tutorial/read-orcid-records) for more details.
|
93
119
|
|
94
120
|
Here's how to get going with a couple of popular Rack-based frameworks:
|
95
121
|
|
@@ -133,10 +159,8 @@ ruby demo.rb
|
|
133
159
|
|
134
160
|
```
|
135
161
|
|
136
|
-
|
137
162
|
### Rails
|
138
163
|
|
139
|
-
|
140
164
|
Add this to `config/initializers/omniauth.rb` to configure the strategy:
|
141
165
|
|
142
166
|
```ruby
|
@@ -168,13 +192,39 @@ class AuthenticationsController < ApplicationController
|
|
168
192
|
end
|
169
193
|
```
|
170
194
|
|
195
|
+
Or use `omniauth-orcid` with the [Devise](https://github.com/plataformatec/devise)
|
196
|
+
authentication solution.
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
# in config/initializers/devise.rb
|
200
|
+
|
201
|
+
config.omniauth :orcid, ENV['ORCID_CLIENT_ID'],
|
202
|
+
ENV['ORCID_CLIENT_SECRET'],
|
203
|
+
member: ENV['ORCID_MEMBER'],
|
204
|
+
sandbox: ENV['ORCID_SANDBOX']
|
205
|
+
```
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
# in app/models/user.rb
|
209
|
+
|
210
|
+
devise :omniauthable, :omniauth_providers => [:orcid]
|
211
|
+
```
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
# in config/routes.rb
|
215
|
+
|
216
|
+
Rails.application.routes.draw do
|
217
|
+
devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
|
218
|
+
```
|
219
|
+
|
220
|
+
And then add custom logic in `users/omniauth_callbacks`.
|
221
|
+
|
171
222
|
## More information
|
172
223
|
|
173
224
|
* [ORCID Open Source Project](https://github.com/ORCID/ORCID-Source)
|
174
225
|
* [Developer Wiki](https://github.com/ORCID/ORCID-Source/wiki)
|
175
226
|
* [Technical community](http://orcid.org/about/community/orcid-technical-community)
|
176
227
|
|
177
|
-
|
178
228
|
## License
|
179
229
|
|
180
230
|
The [MIT License](license.txt) (OSI approved, see more at http://www.opensource.org/licenses/mit-license.php)
|
@@ -6,7 +6,7 @@ module OmniAuth
|
|
6
6
|
module Strategies
|
7
7
|
class ORCID < OmniAuth::Strategies::OAuth2
|
8
8
|
|
9
|
-
API_VERSION = '
|
9
|
+
API_VERSION = '2.0'
|
10
10
|
|
11
11
|
option :name, "orcid"
|
12
12
|
|
@@ -20,7 +20,6 @@ module OmniAuth
|
|
20
20
|
:given_names,
|
21
21
|
:family_names,
|
22
22
|
:email,
|
23
|
-
:orcid,
|
24
23
|
:scope]
|
25
24
|
|
26
25
|
args [:client_id, :client_secret]
|
@@ -37,7 +36,7 @@ module OmniAuth
|
|
37
36
|
# available options at https://members.orcid.org/api/get-oauthauthorize
|
38
37
|
def authorize_params
|
39
38
|
super.tap do |params|
|
40
|
-
%w[scope redirect_uri show_login lang given_names family_names email
|
39
|
+
%w[scope redirect_uri show_login lang given_names family_names email].each do |v|
|
41
40
|
if request.params[v]
|
42
41
|
params[v.to_sym] = request.params[v]
|
43
42
|
end
|
@@ -76,9 +75,9 @@ module OmniAuth
|
|
76
75
|
|
77
76
|
def api_base_url
|
78
77
|
if options[:sandbox]
|
79
|
-
"
|
78
|
+
"https://pub.sandbox.orcid.org/v#{API_VERSION}"
|
80
79
|
else
|
81
|
-
"
|
80
|
+
"https://pub.orcid.org/v#{API_VERSION}"
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
@@ -109,10 +108,11 @@ module OmniAuth
|
|
109
108
|
uid { access_token.params["orcid"] }
|
110
109
|
|
111
110
|
info do
|
112
|
-
{ name:
|
111
|
+
{ name: access_token.params["name"],
|
113
112
|
email: raw_info[:email],
|
114
113
|
first_name: raw_info[:first_name],
|
115
114
|
last_name: raw_info[:last_name],
|
115
|
+
location: raw_info[:location],
|
116
116
|
description: raw_info[:description],
|
117
117
|
urls: raw_info[:urls]
|
118
118
|
}
|
@@ -123,31 +123,31 @@ module OmniAuth
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def request_info
|
126
|
-
client.request(:get, "#{api_base_url}/#{uid}/
|
126
|
+
@request_info || client.request(:get, "#{api_base_url}/#{uid}/person", headers: { accept: 'application/json' }).parsed || {}
|
127
127
|
end
|
128
128
|
|
129
129
|
def raw_info
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
130
|
+
# retrieve all verified email addresses and include visibility (LIMITED vs. PUBLIC)
|
131
|
+
# and whether this is the primary email address
|
132
|
+
# all other information will in almost all cases be PUBLIC
|
133
|
+
emails = request_info.dig('emails', 'email')
|
134
|
+
.select { |e| e.fetch('verified') }
|
135
|
+
.map { |e| e.select { |k, | %w(email visibility primary).include? k } }
|
136
|
+
|
137
|
+
{ first_name: request_info.dig('name', 'given-names', 'value'),
|
138
|
+
last_name: request_info.dig('name', 'family-name', 'value'),
|
139
|
+
other_names: request_info.dig('other-names', 'other-name').map { |o| o.fetch('content') },
|
140
|
+
description: request_info.dig('biography', 'content'),
|
141
|
+
location: request_info.dig('addresses', 'address').map { |a| a.dig('country', 'value') }.first,
|
142
|
+
email: emails.find { |e| e.fetch('primary') }.to_h.fetch('email'),
|
143
|
+
urls: request_info.dig('researcher-urls', 'researcher-url').map do |r|
|
144
|
+
{ r.fetch("url-name", nil) => r.dig('url', 'value') }
|
145
|
+
end,
|
146
|
+
external_identifiers: request_info.dig('external-identifiers', 'external-identifier').map do |e|
|
147
|
+
{ 'type' => e.fetch('external-id-type', nil),
|
148
|
+
'value' => e.fetch('external-id-value', nil),
|
149
|
+
'url' => e.dig('external-id-url', 'value') }
|
141
150
|
end
|
142
|
-
end
|
143
|
-
|
144
|
-
{ name: orcid_bio.fetch('personal-details', nil).to_h.fetch('credit-name', nil).to_h.fetch('value', nil),
|
145
|
-
first_name: orcid_bio.fetch('personal-details', nil).to_h.fetch('given-names', nil).to_h.fetch('value', nil),
|
146
|
-
last_name: orcid_bio.fetch('personal-details', nil).to_h.fetch('family-name', nil).to_h.fetch('value', nil),
|
147
|
-
other_names: orcid_bio.fetch('personal-details', nil).to_h.fetch('other-names', nil).to_h.fetch('other-name', [{}]).map { |other_name| other_name.fetch('value', nil) },
|
148
|
-
description: orcid_bio.fetch('biography', nil).to_h.fetch('value', nil),
|
149
|
-
urls: {},
|
150
|
-
email: email
|
151
151
|
}
|
152
152
|
end
|
153
153
|
|
data/omniauth-orcid.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency 'bundler', '~> 1.0'
|
24
24
|
s.add_development_dependency 'rspec', '~> 3.4'
|
25
25
|
s.add_development_dependency 'rack-test', '~> 0.6.3'
|
26
|
-
s.add_development_dependency 'webmock', '~>
|
26
|
+
s.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
|
27
27
|
s.add_development_dependency 'codeclimate-test-reporter', "~> 1.0.0"
|
28
28
|
s.add_development_dependency 'simplecov'
|
29
29
|
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
{
|
2
|
+
"name": {
|
3
|
+
"credit-name": {
|
4
|
+
"value": "Martin Fenner"
|
5
|
+
},
|
6
|
+
"family-name": {
|
7
|
+
"value": "Fenner"
|
8
|
+
},
|
9
|
+
"last-modified-date": {
|
10
|
+
"value": 1500190904445
|
11
|
+
},
|
12
|
+
"created-date": {
|
13
|
+
"value": 1460669194723
|
14
|
+
},
|
15
|
+
"visibility": "PUBLIC",
|
16
|
+
"source": null,
|
17
|
+
"given-names": {
|
18
|
+
"value": "Martin"
|
19
|
+
},
|
20
|
+
"path": "0000-0001-6528-2027"
|
21
|
+
},
|
22
|
+
"last-modified-date": {
|
23
|
+
"value": 1500192622273
|
24
|
+
},
|
25
|
+
"researcher-urls": {
|
26
|
+
"researcher-url": [
|
27
|
+
{
|
28
|
+
"put-code": 42818,
|
29
|
+
"last-modified-date": {
|
30
|
+
"value": 1500192382862
|
31
|
+
},
|
32
|
+
"url": {
|
33
|
+
"value": "http://blog.martinfenner.org"
|
34
|
+
},
|
35
|
+
"created-date": {
|
36
|
+
"value": 1500192382862
|
37
|
+
},
|
38
|
+
"visibility": "PUBLIC",
|
39
|
+
"source": {
|
40
|
+
"source-orcid": {
|
41
|
+
"path": "0000-0001-6528-2027",
|
42
|
+
"host": "sandbox.orcid.org",
|
43
|
+
"uri": "http://sandbox.orcid.org/0000-0001-6528-2027"
|
44
|
+
},
|
45
|
+
"source-name": {
|
46
|
+
"value": "Martin Fenner"
|
47
|
+
},
|
48
|
+
"source-client-id": null
|
49
|
+
},
|
50
|
+
"display-index": 1,
|
51
|
+
"path": "/0000-0001-6528-2027/researcher-urls/42818",
|
52
|
+
"url-name": "Blog"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"path": "/0000-0001-6528-2027/researcher-urls",
|
56
|
+
"last-modified-date": {
|
57
|
+
"value": 1500192382862
|
58
|
+
}
|
59
|
+
},
|
60
|
+
"other-names": {
|
61
|
+
"other-name": [
|
62
|
+
{
|
63
|
+
"put-code": 16403,
|
64
|
+
"last-modified-date": {
|
65
|
+
"value": 1500191301536
|
66
|
+
},
|
67
|
+
"created-date": {
|
68
|
+
"value": 1500191301534
|
69
|
+
},
|
70
|
+
"visibility": "PUBLIC",
|
71
|
+
"content": "Martin Hellmut Fenner",
|
72
|
+
"source": {
|
73
|
+
"source-orcid": {
|
74
|
+
"path": "0000-0001-6528-2027",
|
75
|
+
"host": "sandbox.orcid.org",
|
76
|
+
"uri": "http://sandbox.orcid.org/0000-0001-6528-2027"
|
77
|
+
},
|
78
|
+
"source-name": {
|
79
|
+
"value": "Martin Fenner"
|
80
|
+
},
|
81
|
+
"source-client-id": null
|
82
|
+
},
|
83
|
+
"display-index": 1,
|
84
|
+
"path": "/0000-0001-6528-2027/other-names/16403"
|
85
|
+
}
|
86
|
+
],
|
87
|
+
"path": "/0000-0001-6528-2027/other-names",
|
88
|
+
"last-modified-date": {
|
89
|
+
"value": 1500191301536
|
90
|
+
}
|
91
|
+
},
|
92
|
+
"keywords": {
|
93
|
+
"path": "/0000-0001-6528-2027/keywords",
|
94
|
+
"keyword": [],
|
95
|
+
"last-modified-date": null
|
96
|
+
},
|
97
|
+
"path": "/0000-0001-6528-2027/person",
|
98
|
+
"external-identifiers": {
|
99
|
+
"path": "/0000-0001-6528-2027/external-identifiers",
|
100
|
+
"external-identifier": [
|
101
|
+
{
|
102
|
+
"external-id-value": "mfenner",
|
103
|
+
"put-code": 3882,
|
104
|
+
"last-modified-date": {
|
105
|
+
"value": 1499800792190
|
106
|
+
},
|
107
|
+
"external-id-relationship": "SELF",
|
108
|
+
"created-date": {
|
109
|
+
"value": 1499800792189
|
110
|
+
},
|
111
|
+
"external-id-type": "GitHub",
|
112
|
+
"source": {
|
113
|
+
"source-orcid": null,
|
114
|
+
"source-name": {
|
115
|
+
"value": "DataCite/ORCID Claim Tool"
|
116
|
+
},
|
117
|
+
"source-client-id": {
|
118
|
+
"path": "APP-127VAQ5PMV9OKM9F",
|
119
|
+
"host": "sandbox.orcid.org",
|
120
|
+
"uri": "http://sandbox.orcid.org/client/APP-127VAQ5PMV9OKM9F"
|
121
|
+
}
|
122
|
+
},
|
123
|
+
"visibility": "PUBLIC",
|
124
|
+
"display-index": 0,
|
125
|
+
"path": "/0000-0001-6528-2027/external-identifiers/3882",
|
126
|
+
"external-id-url": {
|
127
|
+
"value": "https://github.com/mfenner"
|
128
|
+
}
|
129
|
+
}
|
130
|
+
],
|
131
|
+
"last-modified-date": {
|
132
|
+
"value": 1499800792190
|
133
|
+
}
|
134
|
+
},
|
135
|
+
"emails": {
|
136
|
+
"path": "/0000-0001-6528-2027/email",
|
137
|
+
"email": [
|
138
|
+
{
|
139
|
+
"put-code": null,
|
140
|
+
"verified": true,
|
141
|
+
"last-modified-date": {
|
142
|
+
"value": 1438058214424
|
143
|
+
},
|
144
|
+
"created-date": {
|
145
|
+
"value": 1438058214424
|
146
|
+
},
|
147
|
+
"visibility": "LIMITED",
|
148
|
+
"primary": true,
|
149
|
+
"source": {
|
150
|
+
"source-orcid": {
|
151
|
+
"path": "0000-0001-6528-2027",
|
152
|
+
"host": "sandbox.orcid.org",
|
153
|
+
"uri": "http://sandbox.orcid.org/0000-0001-6528-2027"
|
154
|
+
},
|
155
|
+
"source-name": {
|
156
|
+
"value": "Martin Fenner"
|
157
|
+
},
|
158
|
+
"source-client-id": null
|
159
|
+
},
|
160
|
+
"path": null,
|
161
|
+
"email": "martin.fenner@datacite.org"
|
162
|
+
}
|
163
|
+
],
|
164
|
+
"last-modified-date": {
|
165
|
+
"value": 1438058214424
|
166
|
+
}
|
167
|
+
},
|
168
|
+
"biography": {
|
169
|
+
"content": "Martin Fenner is the DataCite Technical Director and manages the technical architecture for Datacite as well as DataCite\u2019s technical contributions for the EU-funded THOR project. From 2012 to 2015 he was the technical lead for the PLOS Article-Level Metrics project. Martin has a medical degree from the Free University of Berlin and is a Board-certified medical oncologist.",
|
170
|
+
"path": "/0000-0001-6528-2027/biography",
|
171
|
+
"created-date": {
|
172
|
+
"value": 1460669194724
|
173
|
+
},
|
174
|
+
"visibility": "PUBLIC",
|
175
|
+
"last-modified-date": {
|
176
|
+
"value": 1500206408067
|
177
|
+
}
|
178
|
+
},
|
179
|
+
"addresses": {
|
180
|
+
"path": "/0000-0001-6528-2027/address",
|
181
|
+
"address": [
|
182
|
+
{
|
183
|
+
"put-code": 4809,
|
184
|
+
"last-modified-date": {
|
185
|
+
"value": 1500192622273
|
186
|
+
},
|
187
|
+
"country": {
|
188
|
+
"value": "DE"
|
189
|
+
},
|
190
|
+
"created-date": {
|
191
|
+
"value": 1500192622273
|
192
|
+
},
|
193
|
+
"visibility": "PUBLIC",
|
194
|
+
"source": {
|
195
|
+
"source-orcid": {
|
196
|
+
"path": "0000-0001-6528-2027",
|
197
|
+
"host": "sandbox.orcid.org",
|
198
|
+
"uri": "http://sandbox.orcid.org/0000-0001-6528-2027"
|
199
|
+
},
|
200
|
+
"source-name": {
|
201
|
+
"value": "Martin Fenner"
|
202
|
+
},
|
203
|
+
"source-client-id": null
|
204
|
+
},
|
205
|
+
"display-index": 1,
|
206
|
+
"path": "/0000-0001-6528-2027/address/4809"
|
207
|
+
}
|
208
|
+
],
|
209
|
+
"last-modified-date": {
|
210
|
+
"value": 1500192622273
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
@@ -47,7 +47,7 @@ describe OmniAuth::Strategies::ORCID do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should have correct base url' do
|
50
|
-
expect(subject.options.client_options.api_base_url).to eq('
|
50
|
+
expect(subject.options.client_options.api_base_url).to eq('https://pub.orcid.org/v2.0')
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -73,7 +73,7 @@ describe OmniAuth::Strategies::ORCID do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'should have correct base url' do
|
76
|
-
expect(subject.options.client_options.api_base_url).to eq("
|
76
|
+
expect(subject.options.client_options.api_base_url).to eq("https://pub.sandbox.orcid.org/v2.0")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -176,26 +176,90 @@ describe OmniAuth::Strategies::ORCID do
|
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
179
|
+
context 'info' do
|
180
|
+
let(:params) { JSON.parse(IO.read(fixture_path + 'access_token.json')) }
|
181
|
+
let(:access_token) { OpenStruct.new("params" => params) }
|
182
|
+
let(:request_info) { JSON.parse(IO.read(fixture_path + 'request_info.json')) }
|
183
183
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
184
|
+
before do
|
185
|
+
allow(subject).to receive(:access_token).and_return(access_token)
|
186
|
+
allow(subject).to receive(:request_info).and_return(request_info)
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should return name' do
|
190
|
+
expect(subject.info[:name]).to eq('Martin Fenner')
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should return first_name' do
|
194
|
+
expect(subject.info[:first_name]).to eq('Martin')
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should return last_name' do
|
198
|
+
expect(subject.info[:last_name]).to eq('Fenner')
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should return description' do
|
202
|
+
expect(subject.info[:description]).to start_with('Martin Fenner is the DataCite Technical Director')
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should return location' do
|
206
|
+
expect(subject.info[:location]).to eq("DE")
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should return email' do
|
210
|
+
expect(subject.info[:email]).to eq( "martin.fenner@datacite.org")
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should return urls' do
|
214
|
+
expect(subject.info[:urls]).to eq([{"Blog"=>"http://blog.martinfenner.org"}])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'raw_info' do
|
219
|
+
let(:params) { JSON.parse(IO.read(fixture_path + 'access_token.json')) }
|
220
|
+
let(:access_token) { OpenStruct.new("params" => params) }
|
221
|
+
let(:request_info) { JSON.parse(IO.read(fixture_path + 'request_info.json')) }
|
188
222
|
|
189
|
-
|
190
|
-
|
223
|
+
before do
|
224
|
+
allow(subject).to receive(:access_token).and_return(access_token)
|
225
|
+
allow(subject).to receive(:request_info).and_return(request_info)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should not include raw_info' do
|
229
|
+
subject.options[:skip_info] = true
|
230
|
+
expect(subject.extra).not_to have_key(:raw_info)
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should return first_name' do
|
234
|
+
expect(subject.extra.dig(:raw_info, :first_name)).to eq('Martin')
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'should return last_name' do
|
238
|
+
expect(subject.extra.dig(:raw_info, :last_name)).to eq('Fenner')
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'should return other_names' do
|
242
|
+
expect(subject.extra.dig(:raw_info, :other_names)).to eq(["Martin Hellmut Fenner"])
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should return description' do
|
246
|
+
expect(subject.extra.dig(:raw_info, :description)).to start_with('Martin Fenner is the DataCite Technical Director')
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should return location' do
|
250
|
+
expect(subject.extra.dig(:raw_info, :location)).to eq("DE")
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'should return email' do
|
254
|
+
expect(subject.extra.dig(:raw_info, :email)).to eq( "martin.fenner@datacite.org")
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'should return urls' do
|
258
|
+
expect(subject.extra.dig(:raw_info, :urls)).to eq([{"Blog"=>"http://blog.martinfenner.org"}])
|
259
|
+
end
|
191
260
|
|
192
|
-
|
193
|
-
|
194
|
-
# with(:headers => { 'Accept'=>'application/json' }).
|
195
|
-
# to_return(:status => 200, :body => "", :headers => {})
|
196
|
-
# expect(subject.extra[:raw_info]).to eq('sub' => '12345')
|
197
|
-
# end
|
198
|
-
# end
|
261
|
+
it 'should return external_identifiers' do
|
262
|
+
expect(subject.extra.dig(:raw_info, :external_identifiers)).to eq([{"type"=>"GitHub", "value"=>"mfenner", "url"=>"https://github.com/mfenner"}])
|
199
263
|
end
|
200
264
|
end
|
201
265
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,10 @@ require 'webmock/rspec'
|
|
11
11
|
require 'omniauth'
|
12
12
|
require 'omniauth-orcid'
|
13
13
|
|
14
|
+
def fixture_path
|
15
|
+
File.expand_path("../fixtures", __FILE__) + '/'
|
16
|
+
end
|
17
|
+
|
14
18
|
RSpec.configure do |config|
|
15
19
|
config.include WebMock::API
|
16
20
|
config.include Rack::Test::Methods
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-orcid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gudmundur A. Thorisson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth-oauth2
|
@@ -73,20 +73,20 @@ dependencies:
|
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '3.0'
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
79
|
+
version: 3.0.1
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '
|
86
|
+
version: '3.0'
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.0.1
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
91
|
name: codeclimate-test-reporter
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,6 +138,8 @@ files:
|
|
138
138
|
- lib/omniauth/orcid/version.rb
|
139
139
|
- lib/omniauth/strategies/orcid.rb
|
140
140
|
- omniauth-orcid.gemspec
|
141
|
+
- spec/fixtures/access_token.json
|
142
|
+
- spec/fixtures/request_info.json
|
141
143
|
- spec/omniauth/strategies/orcid_spec.rb
|
142
144
|
- spec/spec_helper.rb
|
143
145
|
homepage: https://github.com/datacite/omniauth-orcid
|