Class: OmniAuth::Strategies::LibLynx
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::LibLynx
show all
- Defined in:
- lib/omniauth/strategies/liblynx.rb
Defined Under Namespace
Classes: NoAccountInfo, NoInstitution
Instance Method Summary
collapse
Instance Method Details
#access_token ⇒ Object
92
93
94
95
96
|
# File 'lib/omniauth/strategies/liblynx.rb', line 92
def access_token
@access_token ||= client.client_credentials.get_token
@access_token = @access_token.refresh! if @access_token.expired?
@access_token
end
|
#callback_phase ⇒ Object
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/omniauth/strategies/liblynx.rb', line 81
def callback_phase
@auth_url = [
id_body[:url],
'?',
URI.encode_www_form(request.params)
].join
return fail!(:no_account_info, NoAccountInfo.new) if raw_info.blank?
env['omniauth.auth'] = auth_hash
call_app!
end
|
#callback_url ⇒ Object
29
30
31
|
# File 'lib/omniauth/strategies/liblynx.rb', line 29
def callback_url
options[:callback_url] || (full_host + script_name + callback_path)
end
|
#raw_info ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/omniauth/strategies/liblynx.rb', line 66
def raw_info
@raw_info ||= begin
r = access_token
.request(:post, options.id_url, body: id_body.merge(url: @auth_url))
.parsed
ref = r.dig('account', 'publisher_reference')
{
'_response' => r,
'reference' => ref
}
.compact
.merge(r['account_individual'] || {})
end
end
|
#request_phase ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/omniauth/strategies/liblynx.rb', line 49
def request_phase
res = access_token
.request(:post, options.id_url, body: id_body)
.parsed
email = id_body[:email] || ''
if email.present?
institution = res['user_institution']
return fail!(:no_institution, NoInstitution.new) unless institution
account_name = institution['account_name']
log(:info, "User institution: #{institution}")
end
id = res['id']
url = URI.join(callback_url, "?email=#{CGI.escape(email)}&institution=#{CGI.escape(account_name.to_s)}").to_s
hmac = OpenSSL::HMAC.hexdigest('SHA256', client.secret, url)
redirect("#{client.site}/wayf/#{id}?url=#{CGI.escape(url)}&hash=#{hmac}")
end
|