omniauth-orcid 1.1.7 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -0
- data/lib/omniauth/orcid/version.rb +1 -1
- data/lib/omniauth/strategies/orcid.rb +30 -10
- data/spec/omniauth/strategies/orcid_spec.rb +158 -44
- data/spec/spec_helper.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODMzNWYwZWQyZTQ0MmZmZTk3MGRlNzhjNzU3ZTM3NDA4NzI0ODZjMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGQzOTVkYmY4OWFhZjllY2VmZGY2MWY3NzFlMjMwN2RkOGI2NDQwOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjQzZjkyZmVlNmQzZGRjODcwYjI3MWE1MjhhZmJmMzBmZGMyMGZhOWMwMjZi
|
10
|
+
YjRmYzM1MzViMThmODQyNGQ0MjRmYThlYzE4ZjJmNTY2MTVhMjFjOTcwYTUy
|
11
|
+
ZWFlZjYwMzZmMmZiY2IzNjY2Mjk4ZjYzNzUzZGVjYmY0ZmVlY2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjdiN2E0MWJhMzRmYTM2MzFmMzBjOGI4YzcyNjJiNmRiZWU5YzZjYmJiNGQw
|
14
|
+
Y2M4MzVhNTE0OTRlMzM5YzdmYTJhMzc2Mjg1OGNjYTM3NWJiYTk5MmQ0ZGNi
|
15
|
+
ZjE4ZmY3MDkxYThkY2RiZTM5ZTg1MGNkNGIyZjJlZjM4ZTAxNGE=
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# OmniAuth ORCID
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/omniauth-orcid.svg)](https://badge.fury.io/rb/omniauth-orcid)
|
3
4
|
[![Build Status](https://travis-ci.org/datacite/omniauth-orcid.svg?branch=master)](https://travis-ci.org/datacite/omniauth-orcid)
|
4
5
|
[![DOI](https://zenodo.org/badge/15088/datacite/omniauth-orcid.svg)](https://zenodo.org/badge/latestdoi/15088/datacite/omniauth-orcid)
|
5
6
|
|
@@ -6,7 +6,6 @@ module OmniAuth
|
|
6
6
|
module Strategies
|
7
7
|
class ORCID < OmniAuth::Strategies::OAuth2
|
8
8
|
|
9
|
-
DEFAULT_SCOPE = '/orcid-profile/read-limited /orcid-works/create'
|
10
9
|
API_VERSION = '1.2'
|
11
10
|
|
12
11
|
option :name, "orcid"
|
@@ -15,7 +14,13 @@ module OmniAuth
|
|
15
14
|
option :sandbox, false
|
16
15
|
option :provider_ignores_state, true
|
17
16
|
|
18
|
-
option :authorize_options, [:redirect_uri,
|
17
|
+
option :authorize_options, [:redirect_uri,
|
18
|
+
:show_login,
|
19
|
+
:lang,
|
20
|
+
:given_names,
|
21
|
+
:family_names,
|
22
|
+
:email,
|
23
|
+
:orcid]
|
19
24
|
|
20
25
|
args [:client_id, :client_secret]
|
21
26
|
|
@@ -29,15 +34,17 @@ module OmniAuth
|
|
29
34
|
@options.client_options.scope = scope
|
30
35
|
end
|
31
36
|
|
37
|
+
# available options at https://members.orcid.org/api/get-oauthauthorize
|
32
38
|
def authorize_params
|
33
39
|
super.tap do |params|
|
34
|
-
|
35
|
-
|
36
|
-
params[v.to_sym] = request.params[v]
|
37
|
-
end
|
40
|
+
options[:authorize_options].each do |k|
|
41
|
+
params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
|
38
42
|
end
|
39
43
|
|
40
|
-
|
44
|
+
# show login form and not registration form by default
|
45
|
+
params[:show_login] = 'true' if params[:show_login].nil?
|
46
|
+
|
47
|
+
session['omniauth.state'] = params[:state] if params['state']
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
@@ -90,7 +97,7 @@ module OmniAuth
|
|
90
97
|
|
91
98
|
def scope
|
92
99
|
if options[:member]
|
93
|
-
'/
|
100
|
+
'/read-limited /activities/update /orcid-bio/update'
|
94
101
|
else
|
95
102
|
'/authenticate'
|
96
103
|
end
|
@@ -100,7 +107,7 @@ module OmniAuth
|
|
100
107
|
|
101
108
|
info do
|
102
109
|
{ name: raw_info[:name],
|
103
|
-
email:
|
110
|
+
email: raw_info[:email],
|
104
111
|
first_name: raw_info[:first_name],
|
105
112
|
last_name: raw_info[:last_name],
|
106
113
|
description: raw_info[:description],
|
@@ -119,12 +126,25 @@ module OmniAuth
|
|
119
126
|
def raw_info
|
120
127
|
orcid_bio = request_info.fetch('orcid-profile', nil).to_h.fetch('orcid-bio', {})
|
121
128
|
|
129
|
+
emails = orcid_bio.fetch('contact-details', nil).to_h.fetch('email', nil)
|
130
|
+
email = nil
|
131
|
+
|
132
|
+
if emails.is_a? Array
|
133
|
+
emails.each do |e|
|
134
|
+
next unless e['visibility'] == "PUBLIC"
|
135
|
+
next unless e['verified']
|
136
|
+
email = e['value']
|
137
|
+
break
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
122
141
|
{ name: orcid_bio.fetch('personal-details', nil).to_h.fetch('credit-name', nil).to_h.fetch('value', nil),
|
123
142
|
first_name: orcid_bio.fetch('personal-details', nil).to_h.fetch('given-names', nil).to_h.fetch('value', nil),
|
124
143
|
last_name: orcid_bio.fetch('personal-details', nil).to_h.fetch('family-name', nil).to_h.fetch('value', nil),
|
125
144
|
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) },
|
126
145
|
description: orcid_bio.fetch('biography', nil).to_h.fetch('value', nil),
|
127
|
-
urls: {}
|
146
|
+
urls: {},
|
147
|
+
email: email
|
128
148
|
}
|
129
149
|
end
|
130
150
|
|
@@ -1,75 +1,189 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OmniAuth::Strategies::ORCID do
|
4
|
-
|
4
|
+
let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
|
5
|
+
let(:app) {
|
6
|
+
lambda do
|
7
|
+
[200, {}, ["Hello."]]
|
8
|
+
end
|
9
|
+
}
|
10
|
+
|
11
|
+
subject do
|
12
|
+
OmniAuth::Strategies::ORCID.new(app, 'client_id', 'client_secret', @options || {}).tap do |strategy|
|
13
|
+
allow(strategy).to receive(:request) {
|
14
|
+
request
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
OmniAuth.config.test_mode = true
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
OmniAuth.config.test_mode = false
|
25
|
+
end
|
5
26
|
|
6
|
-
|
27
|
+
context 'client options' do
|
7
28
|
it 'should have correct name' do
|
8
29
|
expect(subject.options.name).to eq('orcid')
|
9
30
|
end
|
10
31
|
|
11
|
-
|
12
|
-
|
13
|
-
|
32
|
+
describe "default" do
|
33
|
+
it 'should have correct site' do
|
34
|
+
expect(subject.options.client_options.site).to eq('http://pub.orcid.org')
|
35
|
+
end
|
14
36
|
|
15
|
-
|
16
|
-
|
17
|
-
|
37
|
+
it 'should have correct scope' do
|
38
|
+
expect(subject.options.client_options.scope).to eq('/authenticate')
|
39
|
+
end
|
18
40
|
|
19
|
-
|
20
|
-
|
21
|
-
|
41
|
+
it 'should have correct token url' do
|
42
|
+
expect(subject.options.client_options.token_url).to eq("https://pub.orcid.org/oauth/token")
|
43
|
+
end
|
22
44
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
45
|
+
it 'should have correct authorize url' do
|
46
|
+
expect(subject.options.client_options.authorize_url).to eq('https://orcid.org/oauth/authorize')
|
47
|
+
end
|
27
48
|
|
28
|
-
|
29
|
-
|
30
|
-
|
49
|
+
it 'should have correct base url' do
|
50
|
+
expect(subject.options.client_options.api_base_url).to eq('http://pub.orcid.org/v1.2')
|
51
|
+
end
|
31
52
|
end
|
32
53
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
54
|
+
describe "sandbox" do
|
55
|
+
before do
|
56
|
+
@options = { sandbox: true }
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should have correct site' do
|
60
|
+
expect(subject.options.client_options.site).to eq("http://pub.sandbox.orcid.org")
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have correct scope' do
|
64
|
+
expect(subject.options.client_options.scope).to eq("/authenticate")
|
65
|
+
end
|
37
66
|
|
38
|
-
|
39
|
-
|
40
|
-
|
67
|
+
it 'should have correct token url' do
|
68
|
+
expect(subject.options.client_options.token_url).to eq("https://pub.sandbox.orcid.org/oauth/token")
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should have correct authorize url' do
|
72
|
+
expect(subject.options.client_options.authorize_url).to eq("https://sandbox.orcid.org/oauth/authorize")
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should have correct base url' do
|
76
|
+
expect(subject.options.client_options.api_base_url).to eq("http://pub.sandbox.orcid.org/v1.2")
|
77
|
+
end
|
41
78
|
end
|
42
79
|
|
43
|
-
|
44
|
-
|
80
|
+
describe "member" do
|
81
|
+
before do
|
82
|
+
@options = { member: true }
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should have correct site' do
|
86
|
+
expect(subject.options.client_options.site).to eq('http://api.orcid.org')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should have correct scope' do
|
90
|
+
expect(subject.options.client_options.scope).to eq('/read-limited /activities/update /orcid-bio/update')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should have correct token url' do
|
94
|
+
expect(subject.options.client_options.token_url).to eq("https://api.orcid.org/oauth/token")
|
95
|
+
end
|
45
96
|
end
|
46
97
|
|
47
|
-
|
48
|
-
|
98
|
+
describe "member sandbox" do
|
99
|
+
before do
|
100
|
+
@options = { member: true, sandbox: true }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should have correct site' do
|
104
|
+
expect(subject.options.client_options.site).to eq("http://api.sandbox.orcid.org")
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should have correct scope' do
|
108
|
+
expect(subject.options.client_options.scope).to eq('/read-limited /activities/update /orcid-bio/update')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should have correct token url' do
|
112
|
+
expect(subject.options.client_options.token_url).to eq("https://api.sandbox.orcid.org/oauth/token")
|
113
|
+
end
|
49
114
|
end
|
50
115
|
|
51
|
-
|
52
|
-
|
116
|
+
describe "redirect_uri" do
|
117
|
+
it 'should default to nil' do
|
118
|
+
@options = {}
|
119
|
+
expect(subject.authorize_params['redirect_uri']).to be_nil
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should set the redirect_uri parameter if present' do
|
123
|
+
@options = { redirect_uri: 'https://example.com' }
|
124
|
+
expect(subject.authorize_params['redirect_uri']).to eq('https://example.com')
|
125
|
+
end
|
53
126
|
end
|
54
127
|
|
55
|
-
|
56
|
-
|
128
|
+
describe "show_login" do
|
129
|
+
it 'should default to true' do
|
130
|
+
@options = {}
|
131
|
+
expect(subject.authorize_params['show_login']).to eq("true")
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should set the show_login parameter if present' do
|
135
|
+
@options = { show_login: "false" }
|
136
|
+
expect(subject.authorize_params['show_login']).to eq("false")
|
137
|
+
end
|
57
138
|
end
|
58
|
-
end
|
59
139
|
|
60
|
-
|
61
|
-
|
62
|
-
|
140
|
+
describe "lang" do
|
141
|
+
it 'should default to nil' do
|
142
|
+
@options = {}
|
143
|
+
expect(subject.authorize_params['lang']).to be_nil
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should set the lang parameter if present' do
|
147
|
+
@options = { lang: 'es' }
|
148
|
+
expect(subject.authorize_params['lang']).to eq("es")
|
149
|
+
end
|
63
150
|
end
|
64
151
|
|
65
|
-
|
66
|
-
|
152
|
+
describe "names and email" do
|
153
|
+
it 'should default to nil' do
|
154
|
+
@options = {}
|
155
|
+
expect(subject.authorize_params['given_names']).to be_nil
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should set the names and email parameters if present' do
|
159
|
+
@options = { given_names: "Josiah", family_names: "Carberry", email: "josiah@brown.edu" }
|
160
|
+
expect(subject.authorize_params["given_names"]).to eq("Josiah")
|
161
|
+
expect(subject.authorize_params["family_names"]).to eq("Carberry")
|
162
|
+
expect(subject.authorize_params["email"]).to eq("josiah@brown.edu")
|
163
|
+
end
|
67
164
|
end
|
68
165
|
end
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
166
|
|
73
|
-
|
74
|
-
|
167
|
+
describe 'extra' do
|
168
|
+
describe 'raw_info' do
|
169
|
+
context 'when skip_info is true' do
|
170
|
+
before { subject.options[:skip_info] = true }
|
171
|
+
|
172
|
+
it 'should not include raw_info' do
|
173
|
+
expect(subject.extra).not_to have_key(:raw_info)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# context 'when skip_info is false' do
|
178
|
+
# before { subject.options[:skip_info] = false }
|
179
|
+
|
180
|
+
# it 'should include raw_info' do
|
181
|
+
# stub_request(:get, "http://pub.orcid.org/v1.2/0000-0002-1825-0097/orcid-bio").
|
182
|
+
# with(:headers => { 'Accept'=>'application/json' }).
|
183
|
+
# to_return(:status => 200, :body => "", :headers => {})
|
184
|
+
# expect(subject.extra[:raw_info]).to eq('sub' => '12345')
|
185
|
+
# end
|
186
|
+
# end
|
187
|
+
end
|
188
|
+
end
|
75
189
|
end
|
data/spec/spec_helper.rb
CHANGED
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: 1.
|
4
|
+
version: '1.2'
|
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: 2016-
|
12
|
+
date: 2016-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth-oauth2
|