omniauth-osso 0.1.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: 1d06f1431dfda1ada1148f0bab1f236e31c80ed15e3e3050f1938f30dd508e9e
4
+ data.tar.gz: c12528d4977371f2d235cb4abcf7630655fb87efd64a4e940cf189d02adb2c5d
5
+ SHA512:
6
+ metadata.gz: fca2e07d268d7d06f4146ec7cc1ddef34cf13480853e6900d5da33fa445e8512cdb222fc32d30636e9ec682df52a5802d7b8509040a4008102f41179198b153c
7
+ data.tar.gz: 75b3acc3b3c4af7d898e4f974295ef7d6884fd2b3d661fd3de3352d28af9524d02a250630898bd88f949c2f23d4cfbe372a80227eb08b108de07a2d4c5c2311c
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,21 @@
1
+ Layout/LineLength:
2
+ Max: 120
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*'
7
+
8
+ Style/Documentation:
9
+ Exclude:
10
+ - 'spec/**/*'
11
+
12
+ Lint/RaiseException:
13
+ Enabled: true
14
+ Lint/StructNewOverride:
15
+ Enabled: true
16
+ Style/HashEachMethods:
17
+ Enabled: true
18
+ Style/HashTransformKeys:
19
+ Enabled: true
20
+ Style/HashTransformValues:
21
+ Enabled: true
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ group :test do
8
+ gem 'pry'
9
+ gem 'rack-test'
10
+ gem 'rspec', '~> 3.2'
11
+ gem 'rubocop'
12
+ gem 'webmock', '~> 3.0'
13
+ end
14
+
15
+ gemspec
@@ -0,0 +1,93 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-osso (0.1.0)
5
+ omniauth-oauth2 (~> 1.6.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.0)
13
+ coderay (1.1.2)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ faraday (1.0.1)
18
+ multipart-post (>= 1.2, < 3)
19
+ hashdiff (1.0.1)
20
+ hashie (4.1.0)
21
+ jaro_winkler (1.5.4)
22
+ jwt (2.2.1)
23
+ method_source (1.0.0)
24
+ multi_json (1.14.1)
25
+ multi_xml (0.6.0)
26
+ multipart-post (2.1.1)
27
+ oauth2 (1.4.4)
28
+ faraday (>= 0.8, < 2.0)
29
+ jwt (>= 1.0, < 3.0)
30
+ multi_json (~> 1.3)
31
+ multi_xml (~> 0.5)
32
+ rack (>= 1.2, < 3)
33
+ omniauth (1.9.1)
34
+ hashie (>= 3.4.6)
35
+ rack (>= 1.6.2, < 3)
36
+ omniauth-oauth2 (1.6.0)
37
+ oauth2 (~> 1.1)
38
+ omniauth (~> 1.9)
39
+ parallel (1.19.1)
40
+ parser (2.7.1.0)
41
+ ast (~> 2.4.0)
42
+ pry (0.13.0)
43
+ coderay (~> 1.1)
44
+ method_source (~> 1.0)
45
+ public_suffix (4.0.4)
46
+ rack (2.2.2)
47
+ rack-test (1.1.0)
48
+ rack (>= 1.0, < 3)
49
+ rainbow (3.0.0)
50
+ rexml (3.2.4)
51
+ rspec (3.8.0)
52
+ rspec-core (~> 3.8.0)
53
+ rspec-expectations (~> 3.8.0)
54
+ rspec-mocks (~> 3.8.0)
55
+ rspec-core (3.8.2)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-expectations (3.8.4)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.8.0)
60
+ rspec-mocks (3.8.1)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-support (3.8.2)
64
+ rubocop (0.81.0)
65
+ jaro_winkler (~> 1.5.1)
66
+ parallel (~> 1.10)
67
+ parser (>= 2.7.0.1)
68
+ rainbow (>= 2.2.2, < 4.0)
69
+ rexml
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 2.0)
72
+ ruby-progressbar (1.10.1)
73
+ safe_yaml (1.0.5)
74
+ unicode-display_width (1.7.0)
75
+ webmock (3.8.3)
76
+ addressable (>= 2.3.6)
77
+ crack (>= 0.3.2)
78
+ hashdiff (>= 0.4.0, < 2.0.0)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ bundler (~> 2.1)
85
+ omniauth-osso!
86
+ pry
87
+ rack-test
88
+ rspec (~> 3.2)
89
+ rubocop
90
+ webmock (~> 3.0)
91
+
92
+ BUNDLED WITH
93
+ 2.1.4
@@ -0,0 +1,36 @@
1
+ # Omniauth::Osso
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/osso`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-osso'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install omniauth-osso
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omniauth-osso.
36
+ # omniauth-osso
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'omniauth_osso'
6
+
7
+ require 'irb'
8
+ IRB.start(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Osso
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+ require 'pry'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ # The main source for the Osso Omniauth Strategy
9
+ class Osso < OmniAuth::Strategies::OAuth2
10
+ include OmniAuth::Strategy
11
+
12
+ option :name, 'osso'
13
+ option :client_id, nil
14
+ option :client_secret, nil
15
+ option :client_options, { site: ENV['OSSO_BASE_URL'] }
16
+ option :authorize_params, { state: SecureRandom.hex(24) }
17
+ option :authorize_options, %i[state domain]
18
+ option :token_params, {}
19
+ option :token_options, []
20
+ option :auth_token_params, {}
21
+ option :provider_ignores_state, false
22
+
23
+ def authorize_params
24
+ params = options.authorize_params.merge(options_for('authorize')) || {}
25
+
26
+ raise StandardError if params[:domain].nil?
27
+
28
+ if OmniAuth.config.test_mode
29
+ @env ||= {}
30
+ @env['rack.session'] ||= {}
31
+ end
32
+
33
+ session['omniauth.state'] = params[:state]
34
+
35
+ params
36
+ end
37
+
38
+ uid { raw_info['id'] }
39
+
40
+ info do
41
+ {
42
+ email: raw_info['email']
43
+ }
44
+ end
45
+
46
+ extra do
47
+ {
48
+ idp: raw_info['idp']
49
+ }
50
+ end
51
+
52
+ def raw_info
53
+ @raw_info ||= access_token.get("/oauth/me?access_token=#{access_token.token}").parsed
54
+ end
55
+
56
+ protected
57
+
58
+ def options_for(option)
59
+ options_for = options.send(:"#{option}_options")
60
+ params_for = options.send(:"#{option}_params")
61
+
62
+ options_for.each_with_object({}) do |key, hash|
63
+ value = params_for[key] || options[key]
64
+ hash[key.to_sym] = value.respond_to?(:call) ? value.call : value
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-osso/version'
4
+ require 'omniauth/strategies/osso'
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/omniauth-osso/version', __dir__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ['Sam Bauch']
7
+ gem.email = ['sbauch@gmail.com']
8
+ gem.description = 'An OAuth 2.0 OmniAuth provider for Osso SSO.'
9
+ gem.summary = gem.description
10
+ gem.homepage = 'https://github.com/enterprise-oss/omniauth-osso'
11
+ gem.license = 'MIT'
12
+
13
+ gem.add_dependency 'omniauth-oauth2', '~> 1.6.0'
14
+ gem.add_development_dependency 'bundler', '~> 2.1'
15
+
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ gem.name = 'omniauth-osso'
20
+ gem.require_paths = ['lib']
21
+ gem.version = OmniAuth::Osso::VERSION
22
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe OmniAuth::Strategies::Osso do
6
+ let(:fresh_strategy) { Class.new(OmniAuth::Strategies::Osso) }
7
+
8
+ before do
9
+ OmniAuth.config.test_mode = true
10
+ end
11
+
12
+ after do
13
+ OmniAuth.config.test_mode = false
14
+ end
15
+
16
+ describe 'Subclassing Behavior' do
17
+ subject { fresh_strategy }
18
+
19
+ it 'performs the OmniAuth::Strategy included hook' do
20
+ expect(OmniAuth.strategies).to include(OmniAuth::Strategies::Osso)
21
+ expect(OmniAuth.strategies).to include(subject)
22
+ end
23
+ end
24
+
25
+ describe '#client' do
26
+ subject { fresh_strategy }
27
+
28
+ it 'is initialized with symbolized client_options' do
29
+ instance = subject.new(app, client_options: { 'authorize_url' => 'https://example.com' })
30
+ expect(instance.client.options[:authorize_url]).to eq('https://example.com')
31
+ end
32
+
33
+ it 'sets ssl options as connection options' do
34
+ instance = subject.new(app, client_options: { 'ssl' => { 'ca_path' => 'foo' } })
35
+ expect(instance.client.options[:connection_opts][:ssl]).to eq(ca_path: 'foo')
36
+ end
37
+ end
38
+
39
+ describe '#authorize_params' do
40
+ subject { fresh_strategy }
41
+
42
+ it 'includes the domain authorize param passed in the :authorize_params option' do
43
+ instance = subject.new('abc', 'def', authorize_params: { domain: 'bar.com' })
44
+ expect(instance.authorize_params['domain']).to eq('bar.com')
45
+ end
46
+
47
+ it 'includes top-level domain' do
48
+ instance = subject.new('abc', 'def', domain: 'bar.com')
49
+ expect(instance.authorize_params['domain']).to eq('bar.com')
50
+ expect(instance.authorize_params['state']).not_to be_empty
51
+ end
52
+
53
+ it 'includes random state in the authorize params' do
54
+ instance = subject.new('abc', 'def', authorize_params: { domain: 'bar.com' })
55
+ expect(instance.authorize_params.keys).to include('state')
56
+ expect(instance.session['omniauth.state']).not_to be_empty
57
+ end
58
+
59
+ it 'includes custom state in the authorize params' do
60
+ instance = subject.new('abc', 'def', authorize_params: { state: proc { 'qux' }, domain: 'foo.com' })
61
+ expect(instance.authorize_params.keys).to include('state')
62
+ expect(instance.session['omniauth.state']).to eq('qux')
63
+ end
64
+
65
+ it 'includes state and domain as authorize options' do
66
+ instance = subject.new('abc', 'def', domain: 'foo.com')
67
+ expect(instance.authorize_params.keys).to eq(%w[state domain])
68
+ end
69
+ end
70
+
71
+ describe '#token_params' do
72
+ subject { fresh_strategy }
73
+
74
+ it 'includes any authorize params passed in the :authorize_params option' do
75
+ instance = subject.new('abc', 'def', token_params: { foo: 'bar', baz: 'zip' })
76
+ expect(instance.token_params).to eq('foo' => 'bar', 'baz' => 'zip')
77
+ end
78
+
79
+ it 'includes top-level options that are marked as :authorize_options' do
80
+ instance = subject.new('abc', 'def', token_options: %i[scope foo], scope: 'bar', foo: 'baz')
81
+ expect(instance.token_params).to eq('scope' => 'bar', 'foo' => 'baz')
82
+ end
83
+ end
84
+
85
+ describe '#callback_phase' do
86
+ subject { fresh_strategy }
87
+ it 'calls fail with the client error received' do
88
+ instance = subject.new('abc', 'def')
89
+ allow(instance).to receive(:request) do
90
+ double('Request', params: { 'error_reason' => 'user_denied', 'error' => 'access_denied' })
91
+ end
92
+
93
+ expect(instance).to receive(:fail!).with('user_denied', anything)
94
+ instance.callback_phase
95
+ end
96
+ end
97
+ end
98
+
99
+ describe OmniAuth::Strategies::Osso::CallbackError do
100
+ let(:error) { Class.new(OmniAuth::Strategies::Osso::CallbackError) }
101
+ describe '#message' do
102
+ subject { error }
103
+ it 'includes all of the attributes' do
104
+ instance = subject.new('error', 'description', 'uri')
105
+ expect(instance.message).to match(/error/)
106
+ expect(instance.message).to match(/description/)
107
+ expect(instance.message).to match(/uri/)
108
+ end
109
+ it 'includes all of the attributes' do
110
+ instance = subject.new(nil, :symbol)
111
+ expect(instance.message).to eq('symbol')
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path(__dir__)
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
+
6
+ require 'omniauth_osso'
7
+
8
+ require 'omniauth'
9
+ require 'omniauth-oauth2'
10
+ require 'rack/test'
11
+ require 'rspec'
12
+ require 'webmock/rspec'
13
+
14
+ ENV['RACK_ENV'] = 'test'
15
+ ENV['SESSION_SECRET'] = 'supersecret'
16
+
17
+ module RSpecMixin
18
+ include Rack::Test::Methods
19
+
20
+ def app
21
+ Rack::Builder.new do
22
+ use OmniAuth::Test::PhonySession
23
+ use OmniAuth::Builder do
24
+ provider :osso, 'abc', 'def', client_options: { site: 'https://api.example.org' }, name: 'example.org'
25
+ end
26
+ run ->(env) { [404, { 'Content-Type' => 'text/plain' }, [env.key?('omniauth.auth').to_s]] }
27
+ end.to_app
28
+ end
29
+
30
+ def session
31
+ last_request.env['rack.session']
32
+ end
33
+
34
+ def last_json_response
35
+ JSON.parse(last_response.body, symbolize_names: true)
36
+ end
37
+ end
38
+
39
+ RSpec.configure do |config|
40
+ config.include RSpecMixin
41
+
42
+ # OmniAuth.config.test_mode = true
43
+ # OmniAuth.config.logger = Logger.new('/dev/null')
44
+ WebMock.disable_net_connect!(allow_localhost: true)
45
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-osso
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Bauch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ description: An OAuth 2.0 OmniAuth provider for Osso SSO.
42
+ email:
43
+ - sbauch@gmail.com
44
+ executables:
45
+ - console
46
+ - setup
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".rspec"
52
+ - ".rubocop.yml"
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - lib/omniauth-osso/version.rb
60
+ - lib/omniauth/strategies/osso.rb
61
+ - lib/omniauth_osso.rb
62
+ - omniauth-osso.gemspec
63
+ - spec/omniauth/strategies/osso_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/enterprise-oss/omniauth-osso
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.7.6.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: An OAuth 2.0 OmniAuth provider for Osso SSO.
89
+ test_files:
90
+ - spec/omniauth/strategies/osso_spec.rb
91
+ - spec/spec_helper.rb