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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDM0Mjc1OTBjZWY4ZjgxOTU4ODJmNTRlOTdiZmE0ZTAwMzU0MmIxNw==
4
+ ODMzNWYwZWQyZTQ0MmZmZTk3MGRlNzhjNzU3ZTM3NDA4NzI0ODZjMw==
5
5
  data.tar.gz: !binary |-
6
- NTIxOGI3OWRhMGYwMzFkZDgyZDljYWIzYjYzNjA1YzgwZmQ4MGU2MQ==
6
+ OGQzOTVkYmY4OWFhZjllY2VmZGY2MWY3NzFlMjMwN2RkOGI2NDQwOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjRjMjFmNDFiNmQ2OTQ5ZDY2YzlkNzRmOWY3ZDVhZWVmNzlhN2UyMGRkMDdl
10
- ZDE4ZjI5Y2QwZDY2NmIzYzYyYjBlNWY4ZDk0OWM1OGEwY2Y3NjFiYzViMzAx
11
- MDk3MDQ1OWFkODgyZDI3MGVjZmViNjIxNmQ4OGVjODNmZDdmYzU=
9
+ ZjQzZjkyZmVlNmQzZGRjODcwYjI3MWE1MjhhZmJmMzBmZGMyMGZhOWMwMjZi
10
+ YjRmYzM1MzViMThmODQyNGQ0MjRmYThlYzE4ZjJmNTY2MTVhMjFjOTcwYTUy
11
+ ZWFlZjYwMzZmMmZiY2IzNjY2Mjk4ZjYzNzUzZGVjYmY0ZmVlY2E=
12
12
  data.tar.gz: !binary |-
13
- ZTQyOGRiNjAwY2Y1ZTM2NGJmZWUxZTU3NmE4YmQ1MmUzOWVjMGQ4ZmU0NTM1
14
- MmMxNTE4YWQ4YWY2Mjg4NDNmNmI1MzMzOGUwMDhjZmUxZDJiNTg5MTMyMWQ0
15
- YjRmMDA4MTNiMjJhYTMzMjc0NWYzN2Q1M2Y1MzNjNTZiMWQ5OTE=
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
 
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Orcid
3
- VERSION = "1.1.7"
3
+ VERSION = "1.2"
4
4
  end
5
5
  end
@@ -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, :show_login]
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
- %w[scope redirect_uri show_login lang].each do |v|
35
- if request.params[v]
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
- params[:show_login] ||= 'true'
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
- '/orcid-profile/read-limited /orcid-works/create /orcid-bio/external-identifiers/create /affiliations/create /funding/create'
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: nil,
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
- subject { OmniAuth::Strategies::ORCID.new({}) }
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
- describe 'client options' do
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
- it 'should have correct site' do
12
- expect(subject.options.client_options.site).to eq('http://pub.orcid.org')
13
- end
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
- it 'should have correct authorize url' do
16
- expect(subject.options.client_options.authorize_url).to eq('https://orcid.org/oauth/authorize')
17
- end
37
+ it 'should have correct scope' do
38
+ expect(subject.options.client_options.scope).to eq('/authenticate')
39
+ end
18
40
 
19
- it 'should have correct base url' do
20
- expect(subject.options.client_options.api_base_url).to eq('http://pub.orcid.org/v1.2')
21
- end
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
- it 'should have correct scope' do
24
- expect(subject.options.client_options.scope).to eq('/authenticate')
25
- end
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
- describe 'uid' do
29
- before do
30
- allow(subject).to receive(:request_info).and_return(request_info_hash)
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
- # it 'should return the uid' do
34
- # expect(subject.uid).to eq(1)
35
- # end
36
- end
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
- describe 'info' do
39
- before do
40
- allow(subject).to receive(:request_info).and_return(request_info_hash)
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
- it 'should return name' do
44
- expect(subject.info[:name]).to eq("Martin Fenner")
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
- it 'should return first_name' do
48
- expect(subject.info[:first_name]).to eq("Martin")
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
- it 'should return last_name' do
52
- expect(subject.info[:last_name]).to eq("Fenner")
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
- it 'should return description' do
56
- expect(subject.info[:description]).to eq("Martin Fenner is the DataCite Technical Director and manages the technical architecture for Datacite as well as DataCite’s technical contributions for the EU-funded THOR project.. From 2012 to 2015 he was technical lead for the PLOS Article-Level Metrics project. He served on the Board of the Open Researcher and Contributor ID (ORCID) initiative from 2010-2012, and worked for ORCID EU in the EC-funded ODIN project from 2012 to 2013. Martin has a medical degree from the Free University of Berlin and is a Board-certified medical oncologist.")
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
- describe 'raw_info' do
61
- before do
62
- allow(subject).to receive(:request_info).and_return(request_info_hash)
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
- it 'should return other_names' do
66
- expect(subject.raw_info[:other_names]).to eq([" Martin Hellmut Fenner", "M Fenner", "MH Fenner", "Martin H. Fenner"])
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
- def request_info_hash
74
- { 'message-version' => '1.2', 'orcid-profile' => { 'orcid' => nil, 'orcid-id' => nil, 'orcid-identifier' => { 'value' => nil, 'uri' => 'http://orcid.org/0000-0003-1419-2405', 'path' => '0000-0003-1419-2405', 'host' => 'orcid.org' }, 'orcid-deprecated' => nil, 'orcid-preferences' => { 'locale' => 'EN' }, 'orcid-history' => { 'creation-method' => 'WEBSITE', 'completion-date' => { 'value' => 1_349_732_964_340 }, 'submission-date' => { 'value' => 1_349_729_360_270 }, 'last-modified-date' => { 'value' => 1_446_719_619_721 }, 'claimed' => { 'value' => true }, 'source' => nil, 'deactivation-date' => nil, 'verified-email' => { 'value' => true }, 'verified-primary-email' => { 'value' => true }, 'visibility' => nil }, 'orcid-bio' => { 'personal-details' => { 'given-names' => { 'value' => 'Martin' }, 'family-name' => { 'value' => 'Fenner' }, 'credit-name' => { 'value' => 'Martin Fenner', 'visibility' => 'PUBLIC' }, 'other-names' => { 'other-name' => [{ 'value' => ' Martin Hellmut Fenner' }, { 'value' => 'M Fenner' }, { 'value' => 'MH Fenner' }, { 'value' => 'Martin H. Fenner' }], 'visibility' => 'PUBLIC' } }, 'biography' => { 'value' => 'Martin Fenner is the DataCite Technical Director and manages the technical architecture for Datacite as well as DataCite’s technical contributions for the EU-funded THOR project.. From 2012 to 2015 he was technical lead for the PLOS Article-Level Metrics project. He served on the Board of the Open Researcher and Contributor ID (ORCID) initiative from 2010-2012, and worked for ORCID EU in the EC-funded ODIN project from 2012 to 2013. Martin has a medical degree from the Free University of Berlin and is a Board-certified medical oncologist.', 'visibility' => 'PUBLIC' }, 'researcher-urls' => { 'researcher-url' => [{ 'url-name' => { 'value' => 'Blog' }, 'url' => { 'value' => 'http://blog.martinfenner.org' } }, { 'url-name' => { 'value' => 'Twitter' }, 'url' => { 'value' => 'http://twitter.com/mfenner' } }, { 'url-name' => { 'value' => 'My SciENCV' }, 'url' => { 'value' => 'http://www.ncbi.nlm.nih.gov/myncbi/mfenner/cv/1413/' } }], 'visibility' => 'PUBLIC' }, 'contact-details' => { 'email' => [], 'address' => { 'country' => { 'value' => 'DE', 'visibility' => 'PUBLIC' } } }, 'keywords' => nil, 'external-identifiers' => { 'external-identifier' => [{ 'orcid' => nil, 'external-id-orcid' => nil, 'external-id-common-name' => { 'value' => 'ISNI' }, 'external-id-reference' => { 'value' => '000000035060549X' }, 'external-id-url' => { 'value' => 'http://isni.org/000000035060549X' }, 'external-id-source' => nil, 'source' => { 'source-orcid' => { 'value' => nil, 'uri' => 'http://orcid.org/0000-0003-0412-1857', 'path' => '0000-0003-0412-1857', 'host' => 'orcid.org' }, 'source-client-id' => nil, 'source-name' => nil, 'source-date' => nil } }, { 'orcid' => nil, 'external-id-orcid' => nil, 'external-id-common-name' => { 'value' => 'Scopus Author ID' }, 'external-id-reference' => { 'value' => '7006600825' }, 'external-id-url' => { 'value' => 'http://www.scopus.com/inward/authorDetails.url?authorID=7006600825&partnerID=MN8TOARS' }, 'external-id-source' => nil, 'source' => { 'source-orcid' => { 'value' => nil, 'uri' => 'http://orcid.org/0000-0002-5982-8983', 'path' => '0000-0002-5982-8983', 'host' => 'orcid.org' }, 'source-client-id' => nil, 'source-name' => nil, 'source-date' => nil } }], 'visibility' => 'PUBLIC' }, 'delegation' => nil, 'scope' => nil }, 'orcid-activities' => nil, 'orcid-internal' => nil, 'type' => 'USER', 'group-type' => nil, 'client-type' => nil }, 'orcid-search-results' => nil, 'error-desc' => nil }
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
@@ -1,5 +1,7 @@
1
- $:.unshift File.expand_path('..', __FILE__)
2
- $:.unshift File.expand_path('../../lib', __FILE__)
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'omniauth-orcid'
3
5
  require 'rspec'
4
6
  require 'rack/test'
5
7
  require 'webmock/rspec'
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.1.7
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-08-11 00:00:00.000000000 Z
12
+ date: 2016-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth2