Class: OmniAuth::Strategies::ORCID
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::ORCID
- Defined in:
- lib/omniauth/strategies/orcid.rb
Constant Summary collapse
- DEFAULT_SCOPE =
'/orcid-profile/read-limited /orcid-works/create'- API_VERSION =
'1.2'
Instance Method Summary collapse
- #api_base_url ⇒ Object
- #authorize_params ⇒ Object
- #authorize_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.
22 23 24 25 26 27 28 29 30 |
# File 'lib/omniauth/strategies/orcid.rb', line 22 def initialize(app, *args, &block) super ..site = site ..api_base_url = api_base_url .. = ..token_url = token_url ..scope = scope end |
Instance Method Details
#api_base_url ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/omniauth/strategies/orcid.rb', line 67 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
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omniauth/strategies/orcid.rb', line 32 def super.tap do |params| %w[scope redirect_uri show_login lang].each do |v| if request.params[v] params[v.to_sym] = request.params[v] end end params[:show_login] ||= 'true' params[:scope] ||= DEFAULT_SCOPE end end |
#authorize_url ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/omniauth/strategies/orcid.rb', line 75 def if [:sandbox] 'https://sandbox.orcid.org/oauth/authorize' else 'https://orcid.org/oauth/authorize' end end |
#namespace ⇒ Object
URLs for ORCID OAuth: members.orcid.org/api/tokens-through-3-legged-oauth-authorization
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/omniauth/strategies/orcid.rb', line 46 def namespace if [:member] && [:sandbox] 'sandbox' elsif [:member] 'production' elsif [:sandbox] 'public_sandbox' else 'public' end end |
#raw_info ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/omniauth/strategies/orcid.rb', line 120 def raw_info orcid_bio = request_info.fetch('orcid-profile', nil).to_h.fetch('orcid-bio', {}) { 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: {} } end |
#request_info ⇒ Object
116 117 118 |
# File 'lib/omniauth/strategies/orcid.rb', line 116 def request_info client.request(:get, "#{api_base_url}/#{uid}/orcid-bio", headers: { accept: 'application/json' }).parsed || {} end |
#scope ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/omniauth/strategies/orcid.rb', line 92 def scope if [:member] '/orcid-profile/read-limited /orcid-works/create' else '/authenticate' end end |
#site ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/omniauth/strategies/orcid.rb', line 58 def site case namespace when 'sandbox' then 'http://api.sandbox.orcid.org' when 'production' then 'http://api.orcid.org' when 'public_sandbox' then 'http://pub.sandbox.orcid.org' when 'public' then 'http://pub.orcid.org' end end |
#token_url ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/omniauth/strategies/orcid.rb', line 83 def token_url case namespace when 'sandbox' then 'https://api.sandbox.orcid.org/oauth/token' when 'production' then 'https://api.orcid.org/oauth/token' when 'public_sandbox' then 'https://pub.sandbox.orcid.org/oauth/token' when 'public' then 'https://pub.orcid.org/oauth/token' end end |