omniauth-orcid 0.3 → 0.4
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.
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -2
- data/config.yml +15 -0
- data/demo.rb +78 -0
- data/lib/omniauth/strategies/orcid.rb +4 -5
- data/lib/omniauth-orcid/version.rb +1 -1
- data/omniauth-orcid.gemspec +22 -0
- metadata +8 -3
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (C) 2012, Gudmundur A. Thorisson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -2,12 +2,148 @@
|
|
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://about.orcid.org).
|
6
|
+
|
5
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.
|
6
8
|
|
7
|
-
*Note: the gem comes configured to connected to the [ORCID sandbox service](http://devsandbox.orcid.org). Please update the parameters in ```:client_options``` to connect to the live service when it launches (see http://dev.orcid.org/launch)*
|
8
9
|
|
9
10
|
|
10
|
-
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
The usual way with Bundler: add the following to your `Gemfile` to install the current version of the gem:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'omniauth-orcid'
|
17
|
+
```
|
18
|
+
|
19
|
+
Or, if you're impatient, you can install straight from GitHub
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'omniauth-orcid' , :git => 'git://github.com/gthorisson/omniauth-orcid.git'
|
23
|
+
```
|
24
|
+
|
25
|
+
Then run `bundle install` to install into your environment.
|
26
|
+
|
27
|
+
You can also install the gem system-wide:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
[mummi@nfmac07]gem install omniauth-orcid
|
31
|
+
```
|
32
|
+
|
33
|
+
## Getting started
|
34
|
+
|
35
|
+
Like other OmniAuth strategies, `OmniAuth::Strategies::ORCID` is a piece of Rack middleware. Please read the OmniAuth documentation for detailed instructions: https://github.com/intridea/omniauth.
|
36
|
+
|
37
|
+
|
38
|
+
By default the module connects to the live ORCID service. In the very simplest usage, all you have to provide are your client app credentials ([see more here](http://support.orcid.org/knowledgebase/articles/116739)):
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
use OmniAuth::Builder do
|
42
|
+
provider :orcid, ENV['ORCID_KEY'], ENV['ORCID_SECRET']
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
You also have to implement a callback handler to grab user data after the OAuth handshake has been completed, and then do something cool with those data. Here's how to get going with a couple of popular Rack-based frameworks:
|
47
|
+
|
48
|
+
|
49
|
+
### Sinatra
|
50
|
+
|
51
|
+
|
52
|
+
Configure the strategy and implement a callback routine in your app:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'sinatra'
|
56
|
+
require 'sinatra/config_file'
|
57
|
+
require 'omniauth-orcid'
|
58
|
+
enable :sessions
|
59
|
+
|
60
|
+
use OmniAuth::Builder do
|
61
|
+
provider :orcid, ENV['ORCID_KEY'], ENV['ORCID_SECRET']
|
62
|
+
end
|
63
|
+
...
|
64
|
+
get '/auth/orcid/callback' do
|
65
|
+
session[:omniauth] = request.env['omniauth.auth']
|
66
|
+
redirect '/'
|
67
|
+
end
|
68
|
+
|
69
|
+
get '/' do
|
70
|
+
|
71
|
+
if session[:omniauth]
|
72
|
+
@orcid = session[:omniauth][:uid]
|
73
|
+
end
|
74
|
+
..
|
75
|
+
```
|
76
|
+
|
77
|
+
The bundled `demo.rb` file contains an uber-simple working Sinatra example app. Spin it up, point your browser to http://localhost:4567/ and play:
|
78
|
+
|
79
|
+
```bash
|
80
|
+
gem install sinatra
|
81
|
+
ruby demo.rb
|
82
|
+
[2012-11-26 21:41:08] INFO WEBrick 1.3.1
|
83
|
+
[2012-11-26 21:41:08] INFO ruby 1.9.3 (2012-04-20) [x86_64-darwin11.3.0]
|
84
|
+
== Sinatra/1.3.2 has taken the stage on 4567 for development with backup from WEBrick
|
85
|
+
[2012-11-26 21:41:08] INFO WEBrick::HTTPServer#start: pid=8383 port=4567
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
### Rails
|
91
|
+
|
92
|
+
|
93
|
+
Add this to `config/initializers/omniauth.rb` to configure the strategy:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
require 'omniauth-orcid'
|
97
|
+
|
98
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
99
|
+
provider :orcid, ENV['ORCID_KEY'], ENV['ORCID_SECRET']
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
Register a callback path in 'config/routes.rb'
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
..
|
107
|
+
match '/auth/:provider/callback' => 'authentications#create'
|
108
|
+
..
|
109
|
+
```
|
110
|
+
|
111
|
+
Implement a callback handler method in a controller:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
class AuthenticationsController < ApplicationController
|
115
|
+
..
|
116
|
+
def create
|
117
|
+
omniauth = request.env["omniauth.auth"]
|
118
|
+
session[:omniauth] = omniauth
|
119
|
+
session[:params] = params
|
120
|
+
..
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
## Configuration
|
127
|
+
|
128
|
+
You can also grab parameters from a config file (recommended) and pass to the strategy via the `:client_options` hash. Here's an example from the bundled Sinatra app in `demo.rb`:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
config_file 'config.yml'
|
132
|
+
use OmniAuth::Builder do
|
133
|
+
provider :orcid, settings.client_id, settings.client_secret,
|
134
|
+
:client_options => {
|
135
|
+
:site => settings.site,
|
136
|
+
:authorize_url => settings.authorize_url,
|
137
|
+
:token_url => settings.token_url
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
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
|
+
|
145
|
+
You can d 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
|
+
|
11
147
|
|
12
148
|
|
13
149
|
## More information
|
data/config.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Default endpoint URLs for the ORCID OAuth API
|
2
|
+
|
3
|
+
production:
|
4
|
+
site: https://api.orcid.org
|
5
|
+
authorize_url: https://orcid.org/oauth/authorize
|
6
|
+
token_url: https://api.orcid.org/oauth/token
|
7
|
+
client_id:
|
8
|
+
client_secret:
|
9
|
+
|
10
|
+
development:
|
11
|
+
site: http://api.devsandbox.orcid.org
|
12
|
+
authorize_url: http://devsandbox.orcid.org/oauth/authorize
|
13
|
+
token_url: http://api.devsandbox.orcid.org/oauth/token
|
14
|
+
client_id: 0000-0002-7649-0259
|
15
|
+
client_secret: 5a81472f-d318-4823-887a-ea64ac6f680a
|
data/demo.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# ORCID example client application in Sinatra.
|
2
|
+
# Modelled after this app: https://github.com/zuzara/jQuery-OAuth-Popup
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'sinatra'
|
6
|
+
require 'sinatra/config_file'
|
7
|
+
require 'haml'
|
8
|
+
require 'omniauth-orcid'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
enable :sessions
|
12
|
+
use Rack::Session::Cookie
|
13
|
+
|
14
|
+
config_file 'config.yml'
|
15
|
+
if development?
|
16
|
+
puts "Sinatra running in development mode"
|
17
|
+
elsif production?
|
18
|
+
puts "Sinatra running in production mode"
|
19
|
+
end
|
20
|
+
|
21
|
+
puts "Connecting to ORCID API at " + settings.site + " as client app #{settings.client_id}"
|
22
|
+
|
23
|
+
# Configure the ORCID strategy
|
24
|
+
use OmniAuth::Builder do
|
25
|
+
provider :orcid, settings.client_id, settings.client_secret,
|
26
|
+
:client_options => {
|
27
|
+
:site => settings.site,
|
28
|
+
:authorize_url => settings.authorize_url,
|
29
|
+
:token_url => settings.token_url
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
get '/' do
|
35
|
+
|
36
|
+
@orcid = ''
|
37
|
+
|
38
|
+
if session[:omniauth]
|
39
|
+
@orcid = session[:omniauth][:uid]
|
40
|
+
end
|
41
|
+
haml <<-HTML
|
42
|
+
%html
|
43
|
+
%head
|
44
|
+
%title ORCID OmniAuth demo app
|
45
|
+
%body
|
46
|
+
- if session[:omniauth]
|
47
|
+
%p
|
48
|
+
Signed in with ORCiD <b>#{@orcid}</b>
|
49
|
+
%p
|
50
|
+
%a(href="/user_info")fetch user info as JSON
|
51
|
+
%p
|
52
|
+
%a(href="/signout") sign out
|
53
|
+
- else
|
54
|
+
%p
|
55
|
+
%a(href="/auth/orcid") Log in with my ORCiD
|
56
|
+
HTML
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
get '/user_info' do
|
61
|
+
content_type :json
|
62
|
+
session[:omniauth].to_json
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
get '/auth/orcid/callback' do
|
67
|
+
puts "Adding OmniAuth user info to session: " + request.env['omniauth.auth'].inspect
|
68
|
+
session[:omniauth] = request.env['omniauth.auth']
|
69
|
+
redirect '/'
|
70
|
+
end
|
71
|
+
|
72
|
+
get '/signout' do
|
73
|
+
session.clear
|
74
|
+
redirect '/'
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
__END__
|
@@ -6,13 +6,13 @@ module OmniAuth
|
|
6
6
|
module Strategies
|
7
7
|
class ORCID < OmniAuth::Strategies::OAuth2
|
8
8
|
|
9
|
-
DEFAULT_SCOPE = '/orcid-bio/read-limited'
|
9
|
+
DEFAULT_SCOPE = '/orcid-bio/read-limited'
|
10
10
|
|
11
11
|
option :client_options, {
|
12
|
-
:site => 'http://api.
|
13
|
-
:authorize_url => 'http://
|
12
|
+
:site => 'http://api.orcid.org',
|
13
|
+
:authorize_url => 'http://orcid.org/oauth/authorize',
|
14
14
|
:token_url => 'http://api.devsandbox.orcid.org/oauth/token',
|
15
|
-
:scope => '
|
15
|
+
:scope => 'http://api.orcid.org/oauth/token',
|
16
16
|
:response_type => 'code',
|
17
17
|
:mode => :header
|
18
18
|
}
|
@@ -30,7 +30,6 @@ module OmniAuth
|
|
30
30
|
super.tap do |params|
|
31
31
|
%w[scope].each { |v| params[v.to_sym] = request.params[v] if request.params[v] }
|
32
32
|
params[:scope] ||= DEFAULT_SCOPE # ensure that we're always request *some* default scope
|
33
|
-
Rails.logger.debug "Customizing authz params: " + params.inspect
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path("../lib/omniauth-orcid/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.authors = ["Gudmundur A. Thorisson"]
|
5
|
+
s.email = %q{gthorisson@gmail.com}
|
6
|
+
s.name = "omniauth-orcid"
|
7
|
+
s.homepage = %q{https://github.com/gthorisson/omniauth-orcid}
|
8
|
+
s.summary = %q{ORCID OAuth 2.0 Strategy for OmniAuth 1.0}
|
9
|
+
s.date = Date.today
|
10
|
+
s.description = %q{Enables third-party client apps to connect to the ORCID API and access/update protected profile data }
|
11
|
+
s.files = Dir["{lib}/**/*.rb", "bin/*", "LICENSE.txt", "*.md", "Rakefile", "Gemfile", "demo.rb", "config.yml", "omniauth-orcid.gemspec"]
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.version = OmniAuth::ORCID::VERSION
|
14
|
+
s.extra_rdoc_files = ["README.md"]
|
15
|
+
|
16
|
+
|
17
|
+
# Declary dependencies here, rather than in the Gemfile
|
18
|
+
s.add_dependency 'omniauth', '~> 1.0'
|
19
|
+
s.add_dependency 'omniauth-oauth2', '~> 1.1'
|
20
|
+
|
21
|
+
end
|
22
|
+
|
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.4'
|
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: 2012-
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '1.1'
|
46
46
|
description: ! 'Enables third-party client apps to connect to the ORCID API and access/update
|
47
|
-
protected
|
47
|
+
protected profile data '
|
48
48
|
email: gthorisson@gmail.com
|
49
49
|
executables: []
|
50
50
|
extensions: []
|
@@ -54,8 +54,13 @@ files:
|
|
54
54
|
- lib/omniauth/strategies/orcid.rb
|
55
55
|
- lib/omniauth-orcid/version.rb
|
56
56
|
- lib/omniauth-orcid.rb
|
57
|
+
- LICENSE.txt
|
57
58
|
- README.md
|
58
59
|
- Rakefile
|
60
|
+
- Gemfile
|
61
|
+
- demo.rb
|
62
|
+
- config.yml
|
63
|
+
- omniauth-orcid.gemspec
|
59
64
|
homepage: https://github.com/gthorisson/omniauth-orcid
|
60
65
|
licenses: []
|
61
66
|
post_install_message:
|