Class: OmniAuth::Strategies::ORCID
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::ORCID
- Defined in:
- lib/omniauth/strategies/orcid.rb
Constant Summary collapse
- API_VERSION =
'1.2'
Instance Method Summary collapse
- #api_base_url ⇒ Object
-
#authorize_params ⇒ Object
available options at members.orcid.org/api/get-oauthauthorize.
- #authorize_url ⇒ Object
- #callback_url ⇒ Object
-
#initialize(app, *args, &block) ⇒ ORCID
constructor
A new instance of ORCID.
-
#namespace ⇒ Object
URLs for ORCID OAuth: members.orcid.org/api/tokens-through-3-legged-oauth-authorization.
- #raw_info ⇒ Object
- #request_info ⇒ Object
- #scope ⇒ Object
- #site ⇒ Object
- #token_url ⇒ Object
Constructor Details
#initialize(app, *args, &block) ⇒ ORCID
Returns a new instance of ORCID.
28 29 30 31 32 33 34 35 |
# File 'lib/omniauth/strategies/orcid.rb', line 28 def initialize(app, *args, &block) super @options..site = site @options..api_base_url = api_base_url @options.. = @options..token_url = token_url end |
Instance Method Details
#api_base_url ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/omniauth/strategies/orcid.rb', line 77 def api_base_url if [:sandbox] "http://pub.sandbox.orcid.org/v#{API_VERSION}" else "http://pub.orcid.org/v#{API_VERSION}" end end |
#authorize_params ⇒ Object
available options at members.orcid.org/api/get-oauthauthorize
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/omniauth/strategies/orcid.rb', line 38 def super.tap do |params| %w[scope redirect_uri show_login lang given_names family_names email orcid].each do |v| if request.params[v] params[v.to_sym] = request.params[v] end end # show login form and not registration form by default params[:show_login] = 'true' if params[:show_login].nil? session['omniauth.state'] = params[:state] if params['state'] params[:scope] ||= scope end end |
#authorize_url ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/omniauth/strategies/orcid.rb', line 85 def if [:sandbox] 'https://sandbox.orcid.org/oauth/authorize' else 'https://orcid.org/oauth/authorize' end end |
#callback_url ⇒ Object
150 151 152 |
# File 'lib/omniauth/strategies/orcid.rb', line 150 def callback_url full_host + script_name + callback_path end |
#namespace ⇒ Object
URLs for ORCID OAuth: members.orcid.org/api/tokens-through-3-legged-oauth-authorization
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omniauth/strategies/orcid.rb', line 56 def namespace if [:member] && [:sandbox] 'sandbox' elsif [:member] 'production' elsif [:sandbox] 'public_sandbox' else 'public' end end |
#raw_info ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/omniauth/strategies/orcid.rb', line 125 def raw_info orcid_bio = request_info.fetch('orcid-profile', nil).to_h.fetch('orcid-bio', {}) emails = orcid_bio.fetch('contact-details', nil).to_h.fetch('email', nil) email = nil if emails.is_a? Array emails.each do |e| next unless e['visibility'] == "PUBLIC" next unless e['verified'] email = e['value'] break end end { name: orcid_bio.fetch('personal-details', nil).to_h.fetch('credit-name', nil).to_h.fetch('value', nil), first_name: orcid_bio.fetch('personal-details', nil).to_h.fetch('given-names', nil).to_h.fetch('value', nil), last_name: orcid_bio.fetch('personal-details', nil).to_h.fetch('family-name', nil).to_h.fetch('value', nil), 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) }, description: orcid_bio.fetch('biography', nil).to_h.fetch('value', nil), urls: {}, email: email } end |
#request_info ⇒ Object
121 122 123 |
# File 'lib/omniauth/strategies/orcid.rb', line 121 def request_info client.request(:get, "#{api_base_url}/#{uid}/orcid-bio", headers: { accept: 'application/json' }).parsed || {} end |
#scope ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/omniauth/strategies/orcid.rb', line 97 def scope if [:member] '/read-limited /activities/update /person/update' else '/authenticate' end end |
#site ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/omniauth/strategies/orcid.rb', line 68 def site case namespace when 'sandbox' then 'https://api.sandbox.orcid.org' when 'production' then 'https://api.orcid.org' when 'public_sandbox' then 'https://pub.sandbox.orcid.org' when 'public' then 'https://pub.orcid.org' end end |
#token_url ⇒ Object
93 94 95 |
# File 'lib/omniauth/strategies/orcid.rb', line 93 def token_url site + '/oauth/token' end |