omniauth-orcid 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +42 -8
- data/config.yml +5 -5
- data/demo.rb +15 -3
- data/lib/omniauth-orcid/version.rb +1 -1
- data/omniauth-orcid.gemspec +1 -0
- metadata +3 -3
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ORCID OAuth 2.0 Strategy for the wonderful [OmniAuth Ruby authentication framework](http://www.omniauth.org).
|
4
4
|
|
5
|
-
Provides basic support for connecting a client application to the [Open Researcher & Contributor ID registry service](http://
|
5
|
+
Provides basic support for connecting a client application to the [Open Researcher & Contributor ID registry service](http://orcid.org).
|
6
6
|
|
7
7
|
Originally created for the [ORCID example client application in Rails](https://github.com/gthorisson/ORCID-example-client-app-rails), then turned into a gem.
|
8
8
|
|
@@ -24,7 +24,7 @@ gem 'omniauth-orcid' , :git => 'git://github.com/gthorisson/omniauth-orcid.git'
|
|
24
24
|
|
25
25
|
Then run `bundle install` to install into your environment.
|
26
26
|
|
27
|
-
You can also install the gem system-wide:
|
27
|
+
You can also install the gem system-wide in the usual way:
|
28
28
|
|
29
29
|
```bash
|
30
30
|
[mummi@nfmac07]gem install omniauth-orcid
|
@@ -43,7 +43,34 @@ use OmniAuth::Builder do
|
|
43
43
|
end
|
44
44
|
```
|
45
45
|
|
46
|
-
|
46
|
+
OmniAuth takes care of the OAuth external-authentication handshake or "dance". All that the gem does is grab the identifier and tokens at the end of the dance and stick it into the OmniAuth hash which is subsequently accessible to your app via `request.env['omniauth.auth']` (see [AuthHashSchema](https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema)). The hash looks something like this:
|
47
|
+
|
48
|
+
```json
|
49
|
+
{
|
50
|
+
provider: "orcid",
|
51
|
+
uid: "0000-0003-2012-0010",
|
52
|
+
info: {
|
53
|
+
name: null
|
54
|
+
},
|
55
|
+
credentials: {
|
56
|
+
token: "e82938fa-a287-42cf-a2ce-f48ef68c9a35",
|
57
|
+
refresh_token: "f94c58dd-b452-44f4-8863-0bf8486a0071",
|
58
|
+
expires_at: 1979903874,
|
59
|
+
expires: true
|
60
|
+
},
|
61
|
+
extra: { }
|
62
|
+
}
|
63
|
+
```
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
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 API guide for more details:
|
68
|
+
|
69
|
+
http://support.orcid.org/knowledgebase/articles/116874-orcid-api-guide
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Here's how to get going with a couple of popular Rack-based frameworks:
|
47
74
|
|
48
75
|
|
49
76
|
### Sinatra
|
@@ -122,15 +149,21 @@ class AuthenticationsController < ApplicationController
|
|
122
149
|
```
|
123
150
|
|
124
151
|
|
125
|
-
|
126
152
|
## Configuration
|
127
153
|
|
128
|
-
You can also grab parameters from a config file (recommended) and pass
|
154
|
+
You can also grab parameters from a config file (recommended) and pass
|
155
|
+
to the strategy, along with other options specific to your app. The OAuth scope or
|
156
|
+
scopes in particular frequently need to be customized. Here's an example from the bundled Sinatra app in `demo.rb`:
|
157
|
+
|
158
|
+
*UPDATE The [omniauth-oauth2 gem](https://github.com/intridea/omniauth-oauth2) was recently been updated to process options slightly differently. The `:scope` string must now be passed in via `:authorize_params`, see below*
|
129
159
|
|
130
160
|
```ruby
|
131
161
|
config_file 'config.yml'
|
132
162
|
use OmniAuth::Builder do
|
133
163
|
provider :orcid, settings.client_id, settings.client_secret,
|
164
|
+
:authorize_params => {
|
165
|
+
:scope => '/orcid-profile/read-limited'
|
166
|
+
},
|
134
167
|
:client_options => {
|
135
168
|
:site => settings.site,
|
136
169
|
:authorize_url => settings.authorize_url,
|
@@ -142,14 +175,15 @@ end
|
|
142
175
|
|
143
176
|
Different sets of params from `config.yml` are used for production environment (points to live ORCID service) vs. development environment (points to ORCID sandbox service).
|
144
177
|
|
145
|
-
You can
|
178
|
+
You can do something similar with in Rails with the same config file, or something . See a working example here: https://github.com/gthorisson/ORCID-example-client-app-rails
|
146
179
|
|
147
180
|
|
148
181
|
|
149
182
|
## More information
|
150
183
|
|
151
|
-
ORCID
|
152
|
-
|
184
|
+
ORCID Open Source Project - https://github.com/ORCID/ORCID-Source
|
185
|
+
Developer Wiki - https://github.com/ORCID/ORCID-Source/wiki
|
186
|
+
Technical community - http://orcid.org/about/community/orcid-technical-community
|
153
187
|
|
154
188
|
|
155
189
|
|
data/config.yml
CHANGED
@@ -8,8 +8,8 @@ production:
|
|
8
8
|
client_secret:
|
9
9
|
|
10
10
|
development:
|
11
|
-
site: http://api.
|
12
|
-
authorize_url: http://
|
13
|
-
token_url: http://api.
|
14
|
-
client_id: 0000-0002-
|
15
|
-
client_secret:
|
11
|
+
site: http://api.sandbox-1.orcid.org
|
12
|
+
authorize_url: http://sandbox-1.orcid.org/oauth/authorize
|
13
|
+
token_url: http://api.sandbox-1.orcid.org/oauth/token
|
14
|
+
client_id: 0000-0002-8831-0104
|
15
|
+
client_secret: 7fb56071-0c68-4d42-af00-5a52804ae645
|
data/demo.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# ORCID example client application in Sinatra.
|
2
|
+
#
|
2
3
|
# Modelled after this app: https://github.com/zuzara/jQuery-OAuth-Popup
|
3
4
|
|
4
5
|
require 'rubygems'
|
@@ -6,6 +7,7 @@ require 'sinatra'
|
|
6
7
|
require 'sinatra/config_file'
|
7
8
|
require 'haml'
|
8
9
|
require 'omniauth-orcid'
|
10
|
+
require 'oauth2'
|
9
11
|
require 'json'
|
10
12
|
|
11
13
|
enable :sessions
|
@@ -31,6 +33,8 @@ use OmniAuth::Builder do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
|
36
|
+
|
37
|
+
|
34
38
|
get '/' do
|
35
39
|
|
36
40
|
@orcid = ''
|
@@ -46,10 +50,11 @@ get '/' do
|
|
46
50
|
- if session[:omniauth]
|
47
51
|
%p
|
48
52
|
Signed in with ORCiD <b>#{@orcid}</b>
|
53
|
+
%a(href="/signout") sign out
|
49
54
|
%p
|
50
|
-
%a(href="/user_info")
|
55
|
+
%a(href="/user_info")Show OmniAuth user data as JSON
|
51
56
|
%p
|
52
|
-
%a(href="/
|
57
|
+
%a(href="/orcid_profile")Connect to ORCID API to fetch full profile data as JSON
|
53
58
|
- else
|
54
59
|
%p
|
55
60
|
%a(href="/auth/orcid") Log in with my ORCiD
|
@@ -69,10 +74,17 @@ get '/auth/orcid/callback' do
|
|
69
74
|
redirect '/'
|
70
75
|
end
|
71
76
|
|
77
|
+
get '/orcid_profile' do
|
78
|
+
client = OAuth2::Client.new settings.client_id,settings.client_secret, :site => settings.site
|
79
|
+
atoken = OAuth2::AccessToken.new client, session[:omniauth]['credentials']['token']
|
80
|
+
response = atoken.get "/#{session[:omniauth]['uid']}/orcid-profile", :headers => {'Accept' => 'application/json'}
|
81
|
+
response.body
|
82
|
+
end
|
83
|
+
|
84
|
+
|
72
85
|
get '/signout' do
|
73
86
|
session.clear
|
74
87
|
redirect '/'
|
75
88
|
end
|
76
89
|
|
77
90
|
|
78
|
-
__END__
|
data/omniauth-orcid.gemspec
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: '0.
|
4
|
+
version: '0.6'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
83
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.8.
|
84
|
+
rubygems_version: 1.8.25
|
85
85
|
signing_key:
|
86
86
|
specification_version: 3
|
87
87
|
summary: ORCID OAuth 2.0 Strategy for OmniAuth 1.0
|