omniauth-liblynx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f7623daa8e8cadf5e8f653ac2d24124ad9a819e6a7103edc01e5627d408fb579
4
+ data.tar.gz: 07b6f1841d7aa628e0391d0cae77d980df01fb55bd24b5bf1aa2e96b9071c1c2
5
+ SHA512:
6
+ metadata.gz: b4435398864fdf46e900e18439c6aca4300c5c324761543238689f9d678245582b37199513b1a08e5699ac2cf4003272c2b2b0f6f30e2897b47116ca7441bccc
7
+ data.tar.gz: 99badcd12cd76cb838ff5673f53ba377acda7b8733e3b40652d456c8c4491be7de34819e7eed8f061487f9c48a4ecf20485fec62066698e38e60e87d45cd3691
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Denis Sablic
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # OmniAuth LibLynx Strategy
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'omniauth-liblynx'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
14
+
15
+ ```ruby
16
+ Rails.application.config.middleware.use OmniAuth::Builder do
17
+ provider :liblynx, ENV['LIBLYNX_ID'], ENV['LIBLYNX_SECRET']
18
+ end
19
+ ```
20
+
21
+ Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
@@ -0,0 +1,2 @@
1
+ require "omniauth-liblynx/version"
2
+ require 'omniauth/strategies/liblynx'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module LibLynx
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,97 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class LibLynx < OmniAuth::Strategies::OAuth2
6
+ class NoAccountInfo < StandardError
7
+ def message
8
+ 'Failed to obtain the account info'
9
+ end
10
+ end
11
+
12
+ class NoInstitution < StandardError
13
+ def message
14
+ 'The given email domain is not registered with any of the supported institutions'
15
+ end
16
+ end
17
+
18
+ option :client_options,
19
+ site: 'https://connect.liblynx.com',
20
+ token_url: '/oauth/v2/token',
21
+ client_options: {
22
+ auth_scheme: :basic_auth
23
+ }
24
+
25
+ option :id_url, 'https://connect.liblynx.com/api/identifications'
26
+
27
+ def callback_url
28
+ options[:callback_url] || (full_host + script_name + callback_path)
29
+ end
30
+
31
+ uid { raw_info['id'] }
32
+
33
+ info do
34
+ i = raw_info['individual']
35
+ {
36
+ 'email' => id_body[:email],
37
+ 'institution' => request.params['institution'],
38
+ 'reference' => raw_info['reference'],
39
+ 'name' => i['display_name'],
40
+ 'surname' => i['surname'],
41
+ 'given_name' => i['given_name']
42
+ }
43
+ end
44
+
45
+ def request_phase
46
+ res = access_token
47
+ .request(:post, options.id_url, body: id_body)
48
+ .parsed
49
+ if id_body[:email].present?
50
+ institution = res['user_institution']
51
+ return fail!(:no_institution, NoInstitution.new) unless institution
52
+ log(:info, "User institution: #{institution}")
53
+ end
54
+ id = res['id']
55
+ url = URI.join(callback_url, "?email=#{id_body[:email]}&institution=#{institution['account_name']}").to_s
56
+ hmac = OpenSSL::HMAC.hexdigest('SHA256', client.secret, url)
57
+ redirect("#{client.site}/wayf/#{id}?url=#{CGI.escape(url)}&hash=#{hmac}")
58
+ end
59
+
60
+ def raw_info
61
+ @raw_info ||= begin
62
+ r = access_token
63
+ .request(:post, options.id_url, body: id_body.merge(url: @auth_url))
64
+ .parsed
65
+ ref = r.dig('account', 'publisher_reference')
66
+ (r['account_individual'] || {}).merge('reference' => ref)
67
+ end
68
+ end
69
+
70
+ def callback_phase
71
+ @auth_url = [id_body[:url], '?', URI.encode_www_form(request.params)].join
72
+ return fail!(:no_account_info, NoAccountInfo.new) if raw_info.blank?
73
+ env['omniauth.auth'] = auth_hash
74
+ call_app!
75
+ end
76
+
77
+ def access_token
78
+ @access_token ||= client.client_credentials.get_token
79
+ @access_token = @access_token.refresh! if @access_token.expired?
80
+ @access_token
81
+ end
82
+
83
+ private
84
+
85
+ def id_body
86
+ {
87
+ ip: request.ip,
88
+ url: callback_url,
89
+ user_agent: request.user_agent,
90
+ email: request.params['email']
91
+ }.compact
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ OmniAuth.config.add_camelization('liblynx', 'LibLynx')
@@ -0,0 +1,21 @@
1
+
2
+ # -*- encoding: utf-8 -*-
3
+ require File.expand_path('../lib/omniauth-liblynx/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ['Denis Sablic']
7
+ gem.email = ['denis.sablic@gmail.com']
8
+ gem.homepage = 'https://github.com/dsablic/omniauth-liblynx'
9
+ gem.summary = 'OmniAuth strategy for LibLynx'
10
+ gem.license = 'MIT'
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = 'omniauth-liblynx'
16
+ gem.require_paths = ['lib']
17
+ gem.version = OmniAuth::LibLynx::VERSION
18
+
19
+ gem.add_dependency 'omniauth', '~> 1.5'
20
+ gem.add_dependency 'omniauth-oauth2', '>= 1.4.0', '< 2.0'
21
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-liblynx
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Denis Sablic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ description:
48
+ email:
49
+ - denis.sablic@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - LICENSE
55
+ - README.md
56
+ - lib/omniauth-liblynx.rb
57
+ - lib/omniauth-liblynx/version.rb
58
+ - lib/omniauth/strategies/liblynx.rb
59
+ - omniauth-liblynx.gemspec
60
+ homepage: https://github.com/dsablic/omniauth-liblynx
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.7.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: OmniAuth strategy for LibLynx
84
+ test_files: []