omniauth-nusso 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 372fca1755b7d777832e456d32d9d7dab95536c03233f40b455bd9b74ff8ee62
4
+ data.tar.gz: 5ba79e279f4659e2d36b4c850cbbf14cf5993ae47617c3b244454a8eff15ed3c
5
+ SHA512:
6
+ metadata.gz: c4164359e4e306012663329fd253c6a42dcd810c78cc261646feacbc257328d2f1c8af6f8e22a64f91f00114c44b6a4fecaf3b747acc926b36a6f1bd27763c55
7
+ data.tar.gz: 4eefac39a22768fc388f1908212dff3bdb0cc90b97c6c9aa725a0690d9720ff92002c1b382347d9f684ce4e08fcfbfd57c6ea71942145893690a21a5a9ca872e
@@ -0,0 +1,29 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.6.5
6
+ environment:
7
+ BUNDLER_VERSION: 2.1.4
8
+ steps:
9
+ - checkout
10
+ - run:
11
+ name: Install Bundler 2.1.4
12
+ command: gem install --no-doc bundler:2.1.4
13
+ - restore_cache:
14
+ keys:
15
+ - bundle-{{ checksum "Gemfile" }}-{{ checksum "omniauth-nusso.gemspec" }}
16
+ - bundle- # used if checksum fails
17
+ - run:
18
+ name: Install dependencies
19
+ command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs 4 --retry 3
20
+ - save_cache:
21
+ key: bundle-{{ checksum "Gemfile" }}-{{ checksum "omniauth-nusso.gemspec" }}
22
+ paths:
23
+ - "vendor/bundle"
24
+ - run:
25
+ name: Run Rubocop
26
+ command: bundle exec rubocop
27
+ - run:
28
+ name: Run Specs
29
+ command: bundle exec rspec spec
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ inherit_gem:
4
+ bixby: bixby_default.yml
5
+
6
+ inherit_mode:
7
+ merge:
8
+ - Exclude
9
+
10
+ AllCops:
11
+ Exclude:
12
+ - "spec/**/*"
13
+ TargetRubyVersion: 2.3
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,13 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-03-23 14:23:42 -0500 using RuboCop version 0.63.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
11
+ # URISchemes: http, https
12
+ Metrics/LineLength:
13
+ Max: 87
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in omniauth-nusso.gemspec
6
+ gemspec
7
+
8
+ gem 'omniauth', '~> 1.0'
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ##########################################################################
2
+ # Copyright 2020 Northwestern University Library
3
+ # Additional copyright may be held by others, as reflected in the commit log
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # OmniAuth::Nusso
2
+
3
+ [OmniAuth](https://github.com/omniauth/omniauth) strategy for use with Northwestern University Agentless SSO.
4
+
5
+ [![CircleCI](https://circleci.com/gh/nulib/omniauth-nusso.svg?style=svg)](https://circleci.com/gh/nulib/omniauth-nusso)
6
+ [![Coverage Status](https://coveralls.io/repos/github/nulib/omniauth-nusso/badge.svg?branch=master)](https://coveralls.io/github/nulib/omniauth-nusso?branch=master)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'omniauth-nusso'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install omniauth-nusso
23
+
24
+ ## Usage
25
+
26
+ TODO
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nulib/omniauth-nusso.
37
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'omniauth/nusso'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/nusso/version'
4
+ require 'omniauth/strategies/nusso'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Nusso
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+ require 'omniauth'
6
+ require 'pry'
7
+
8
+ module OmniAuth
9
+ module Strategies
10
+ class Nusso
11
+ class AuthException < RuntimeError; end
12
+
13
+ include OmniAuth::Strategy
14
+
15
+ args [:base_url, :consumer_key]
16
+ option :base_url, nil
17
+ option :consumer_key, nil
18
+ option :sso_cookie, 'nusso'
19
+ option :include_attributes, true
20
+
21
+ ATTRIBUTE_MAP = {
22
+ name: 'displayName',
23
+ email: 'mail',
24
+ first_name: 'givenName',
25
+ last_name: 'sn',
26
+ phone: 'telephoneNumber',
27
+ description: 'title'
28
+ }.freeze
29
+
30
+ def connection
31
+ @connection ||= Faraday::Connection.new(options.base_url)
32
+ end
33
+
34
+ protected
35
+
36
+ def request_phase
37
+ response = get('get-ldap-redirect-url', goto: callback_url)
38
+ redirect response['redirecturl']
39
+ end
40
+
41
+ def callback_phase
42
+ token = request.cookies[options.sso_cookie]
43
+ response = get('validateWebSSOToken', webssotoken: token)
44
+ @user_info = { 'uid' => response['netid'] }
45
+ if options.include_attributes
46
+ @user_info.merge!(get_directory_attributes(token))
47
+ end
48
+ super
49
+ rescue AuthException => err
50
+ fail!(err.message)
51
+ end
52
+
53
+ uid { @user_info['uid'] }
54
+
55
+ info do
56
+ Hash[
57
+ ATTRIBUTE_MAP.map do |key, user_info_key|
58
+ [key, @user_info[user_info_key]]
59
+ end
60
+ ]
61
+ end
62
+
63
+ extra { { raw_info: @user_info } }
64
+
65
+ private
66
+
67
+ def get(path, headers)
68
+ headers = headers.merge(apikey: options.consumer_key)
69
+ response = connection.get(path, nil, headers)
70
+ case response.status
71
+ when 200..299
72
+ JSON.parse(response.body)
73
+ when 407
74
+ raise AuthException, "Missing or Invalid Token"
75
+ else
76
+ raise AuthException, "Unknown Response"
77
+ end
78
+ end
79
+
80
+ def get_directory_attributes(token)
81
+ response = get("validate-with-directory-search-response", webssotoken: token)
82
+ Hash[
83
+ response['results'].first.map do |k, v|
84
+ case v
85
+ when [] then nil
86
+ when "" then nil
87
+ when Array then [k, v.first]
88
+ else [k, v]
89
+ end
90
+ end.compact
91
+ ]
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/nusso'
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/omniauth/nusso/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'omniauth-nusso'
7
+ spec.version = OmniAuth::Nusso::VERSION
8
+ spec.license = 'Apache-2.0'
9
+ spec.authors = ['Brendan Quinn']
10
+ spec.email = ['brendan-quinn@northwestern.edu']
11
+
12
+ spec.summary = 'OmniAuth strategy for Northwestern University Agentless SSO.'
13
+ spec.homepage = 'https://github.com/nulib/omniauth-nusso'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/nulib/omniauth-nusso'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_runtime_dependency 'omniauth'
29
+ spec.add_runtime_dependency 'faraday'
30
+
31
+ spec.add_development_dependency 'bixby', '~> 2.0'
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
+ spec.add_development_dependency 'coveralls', '~> 0.8.3'
34
+ spec.add_development_dependency 'pry'
35
+ spec.add_development_dependency 'pry-byebug'
36
+ spec.add_development_dependency 'rake', '~> 12.0'
37
+ spec.add_development_dependency 'rack-test'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency 'simplecov'
40
+ spec.add_development_dependency 'webmock'
41
+ end
data/tags ADDED
@@ -0,0 +1,11 @@
1
+ !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2
+ !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3
+ !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
4
+ !_TAG_PROGRAM_NAME Exuberant Ctags //
5
+ !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
6
+ !_TAG_PROGRAM_VERSION 5.8 //
7
+ Error lib/omniauth/nusso.rb /^ class Error < StandardError; end$/;" c class:Omniauth.Nusso
8
+ Nusso lib/omniauth/nusso.rb /^ module Nusso$/;" m class:Omniauth
9
+ Nusso lib/omniauth/nusso/version.rb /^ module Nusso$/;" m class:Omniauth
10
+ Omniauth lib/omniauth/nusso.rb /^module Omniauth$/;" m
11
+ Omniauth lib/omniauth/nusso/version.rb /^module Omniauth$/;" m
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-nusso
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brendan Quinn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-25 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bixby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '12.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '12.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rack-test
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description:
182
+ email:
183
+ - brendan-quinn@northwestern.edu
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".circleci/config.yml"
189
+ - ".gitignore"
190
+ - ".rspec"
191
+ - ".rubocop.yml"
192
+ - ".rubocop_todo.yml"
193
+ - Gemfile
194
+ - LICENSE
195
+ - README.md
196
+ - Rakefile
197
+ - bin/console
198
+ - bin/setup
199
+ - lib/omniauth/nusso.rb
200
+ - lib/omniauth/nusso/version.rb
201
+ - lib/omniauth/strategies/nusso.rb
202
+ - lib/omniauth_nusso.rb
203
+ - omniauth-nusso.gemspec
204
+ - tags
205
+ homepage: https://github.com/nulib/omniauth-nusso
206
+ licenses:
207
+ - Apache-2.0
208
+ metadata:
209
+ homepage_uri: https://github.com/nulib/omniauth-nusso
210
+ source_code_uri: https://github.com/nulib/omniauth-nusso
211
+ post_install_message:
212
+ rdoc_options: []
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: 2.3.0
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ requirements: []
226
+ rubygems_version: 3.0.3
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: OmniAuth strategy for Northwestern University Agentless SSO.
230
+ test_files: []