omniauth-matique 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 980e0dc38689fb49ac61f868d081e8c167b4b5e3
4
+ data.tar.gz: 5f986205dfec931feebba5dcc6c4052c8dc42243
5
+ SHA512:
6
+ metadata.gz: 6b767b4eb52be4f98c1a45f64c445ba0bedbb895c1dfb01511810ae62ca744a16bd4052cf965ced8ff963de5186a47bb6cad3e8195ceb63ca2fc37f550faf6a3
7
+ data.tar.gz: 92375956494094a3704849d11ae41e80ec3b9530428b88a37afd04974c93185411619cf0f1e7ba10d81b4a7b3adad50372fb71b2dc908f00075df9f01511702a
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ coverage/
3
+
4
+ *.gem
5
+ *.log
6
+ *.lock
7
+ *.sqlite
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rails-5.1
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.4.1
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ sudo: false
3
+
4
+ bundler_args: --without production
5
+ before_install: gem update bundler --no-document
6
+ script: 'bundle exec rake test'
7
+
8
+ rvm:
9
+ # - 2.0.0
10
+ # - 2.2.3
11
+ - 2.3.0
12
+ - 2.4.1
13
+
14
+ notifications:
15
+ email: false
data/.watchr ADDED
@@ -0,0 +1,53 @@
1
+ HH = '#' * 22 unless defined?(HH)
2
+ H = '#' * 5 unless defined?(H)
3
+
4
+ def usage
5
+ puts <<-EOS
6
+ Ctrl-\\ or ctrl-4 Running all tests
7
+ Ctrl-C Exit
8
+ EOS
9
+ end
10
+
11
+ def run(cmd)
12
+ puts "#{HH} #{Time.now} #{HH}"
13
+ puts "#{H} #{cmd}"
14
+ system "/usr/bin/time --format '#{HH} Elapsed time %E' #{cmd}"
15
+ end
16
+
17
+ def run_it(type, file)
18
+ case type
19
+ when 'test'; run %Q{ruby -I"lib:test" -rubygems #{file}}
20
+ when 'spec'; run %Q{rspec -X #{file}}
21
+ else; puts "#{H} unknown type: #{type}, file: #{file}"
22
+ end
23
+ end
24
+
25
+ def run_all_tests
26
+ puts "\n#{HH} Running all tests #{HH}\n"
27
+ %w{test}.each { |dir| run "rake #{dir} RAILS_ENV=test" if File.exists?(dir) }
28
+ %w{spec}.each { |dir| run "rake #{dir} RAILS_ENV=test" if File.exists?(dir) }
29
+ end
30
+
31
+ def run_matching_files(base)
32
+ base = base.split('_').first
33
+ %w{test spec}.each { |type|
34
+ files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
35
+ run_it type, files.join(' ') unless files.empty?
36
+ }
37
+ end
38
+
39
+ %w{test spec}.each { |type|
40
+ watch("#{type}/#{type}_helper\.rb") { run_all_tests }
41
+ watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
42
+ }
43
+ %w{rb erb haml slim}.each { |type|
44
+ watch("app/.*/.*\.#{type}") { |m|
45
+ run_matching_files("#{m[0].split('/').at(2).split('.').first}")
46
+ }
47
+ }
48
+
49
+ # Ctrl-\ or ctrl-4
50
+ Signal.trap('QUIT') { run_all_tests }
51
+ # Ctrl-C
52
+ Signal.trap('INT') { abort("Interrupted\n") }
53
+ usage
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :development, :test do
5
+ gem 'observr'
6
+ gem 'simplecov', require: false
7
+ gem 'minitest'
8
+ gem 'mocha'
9
+ gem 'sqlite3'
10
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016-2017 Dittmar Krall http://matique.de
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ Omniauth-Matique
2
+ ================
3
+ [![Gem Version](https://badge.fury.io/rb/omniauth-matique.svg)](https://badge.fury.io/rb/omniauth-matique)
4
+ [![Build Status](https://travis-ci.org/matique/omniauth-matique.png?branch=master)](https://travis-ci.org/matique/omniauth-matique)
5
+
6
+ # OmniAuth Matique Strategy
7
+
8
+ Strategy to authenticate with matique UG via OAuth2 in OmniAuth.
9
+
10
+ ## Installation
11
+
12
+ Add to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem 'omniauth-matique'
16
+ ```
17
+
18
+ Then `bundle install`.
19
+
20
+ ## Usage
21
+
22
+ Here's an example for adding the middleware to a
23
+ Rails app (config/initializers/omniauth.rb):
24
+
25
+ ```ruby
26
+ Rails.application.config.middleware.use OmniAuth::Builder do
27
+ provider :matique, ENV["CLIENT_ID"], ENV["CLIENT_SECRET"]
28
+ end
29
+ OmniAuth.config.logger = Rails.logger
30
+ ```
31
+
32
+ Here's an routing example for a Rails app (config/routes.rb):
33
+
34
+ ```ruby
35
+ match '/auth/:provider/callback', to: 'sessions#create', via: [:get, :post]
36
+ get '/auth/failure', to: 'sessions#failure'
37
+
38
+ get '/auth/login', to: 'sessions#new', as: :login
39
+ get '/auth/logout', to: 'sessions#destroy', as: :logout
40
+ ```
41
+
42
+ You must take care about (see also sample "app"):
43
+ - app/controllers/sessions_controller.rb
44
+ - config/initializers/omniauth.rb
45
+
46
+ You can now access the OmniAuth Matique URL: /auth/matique
47
+
48
+
49
+ ## Credits
50
+
51
+ Inspiration from the web.
52
+ See also:
53
+
54
+ - http://intridea.github.io/omniauth/
55
+ - http://blog.joshsoftware.com/2010/12/16/multiple-applications-with-devise-omniauth-and-single-sign-on/
56
+ - http://codetheory.in/rails-devise-omniauth-sso/
57
+ - https://github.com/intridea/omniauth.git
58
+
59
+ Copyright (c) [Dittmar Krall], released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test.rb'
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ require "omniauth-matique/version"
2
+ require 'omniauth/strategies/matique'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Matique
3
+ VERSION = '0.1.1'
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Matique < OmniAuth::Strategies::OAuth2
6
+ # AuthUrl = ENV["HEROKU_AUTH_URL"] || "https://id.heroku.com"
7
+ # SITE = 'https://login.matique.de'
8
+ SITE = 'http://localhost:3010'
9
+ STRATEGY = 'matique'
10
+
11
+ option :client_options, {
12
+ site: SITE,
13
+ authorize_url: "#{SITE}/auth/#{STRATEGY}/authorize",
14
+ token_url: "#{SITE}/auth/#{STRATEGY}/access_token"
15
+ }
16
+
17
+ uid { raw_info['id'] }
18
+
19
+ info do
20
+ { 'email' => raw_info['email'] }
21
+ end
22
+
23
+ extra do
24
+ { 'raw_info' => raw_info }
25
+ end
26
+
27
+ def raw_info
28
+ @raw_info ||= access_token.get(
29
+ "/auth/matique/user.json?oauth_token=#{access_token.token}").
30
+ parsed || {}
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'omniauth-matique/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-matique'
7
+ s.version = OmniAuth::Matique::VERSION
8
+ s.summary = 'OmniAuth strategy for matique'
9
+ s.description = <<-'END'
10
+ Strategy to authenticate with matique UG via OAuth2 in OmniAuth.
11
+ END
12
+ s.authors = ['Dittmar Krall']
13
+ s.email = ['dittmar.krall@matique.de']
14
+ s.homepage = 'https://github.com/matique/omniauth-matique'
15
+
16
+ s.license = 'MIT'
17
+ s.platform = Gem::Platform::RUBY
18
+
19
+ s.files = `git ls-files -z`.split("\x0")
20
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_development_dependency 'bundler', '~> 1'
24
+ s.add_development_dependency 'rake', '~> 12'
25
+ s.add_dependency 'omniauth-oauth2', '~> 1'
26
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require 'omniauth-matique'
3
+
4
+ # based on omniauth-github, omniauth-clef and others
5
+
6
+ describe OmniAuth::Strategies::Matique do
7
+ let(:strategy) { OmniAuth::Strategies::Matique.new({}) }
8
+ let(:over) { OmniAuth::Strategies::Matique.new('KEY', 'SECRET',
9
+ client_options: {
10
+ site: 'S',
11
+ authorize_url: 'A',
12
+ token_url: 'T'
13
+ }
14
+ )
15
+ }
16
+
17
+ it 'Client has correct default client_options' do
18
+ # site = "https://login.matique.de"
19
+ site = "http://localhost:3010"
20
+ assert_equal "#{site}", strategy.client.site
21
+ assert_equal "#{site}/auth/matique/authorize",
22
+ strategy.client.options[:authorize_url]
23
+ assert_equal "#{site}/auth/matique/access_token",
24
+ strategy.client.options[:token_url]
25
+ end
26
+
27
+ it "client options should be overwritable" do
28
+ assert_equal 'S', over.options.client_options.site
29
+ assert_equal 'A', over.options.client_options.authorize_url
30
+ assert_equal 'T', over.options.client_options.token_url
31
+ end
32
+
33
+ describe 'raw_info' do
34
+ def setup
35
+ super
36
+ @raw_info ||= {
37
+ 'email' => 'test@example.com',
38
+ 'id' => '123'
39
+ }
40
+ strategy.stubs(:raw_info).returns(@raw_info)
41
+ end
42
+
43
+ it 'uid returns the id from raw_info' do
44
+ assert_equal '123', strategy.uid
45
+ end
46
+
47
+ it 'access email from the raw_info' do
48
+ assert_equal 'test@example.com', strategy.info['email']
49
+ # coverage
50
+ refute_nil strategy.extra['raw_info']
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,92 @@
1
+ # adapted from gem omniauth-facebook/omniauth-clef
2
+
3
+ require 'test_helper'
4
+
5
+ describe OmniAuth::Strategies do
6
+
7
+ def setup
8
+ @request = stub('Request')
9
+ @request.stubs(:params).returns({})
10
+ @request.stubs(:cookies).returns({})
11
+ @request.stubs(:env).returns({})
12
+
13
+ @client_id = '123'
14
+ @client_secret = '53cr3tz'
15
+ end
16
+
17
+ def strategy
18
+ @strategy ||= begin
19
+ args = [@client_id, @client_secret, @options].compact
20
+ OmniAuth::Strategies::Matique.new(nil, *args).tap do |strategy|
21
+ strategy.stubs(:request).returns(@request)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "ClientTests" do
27
+ it 'should be initialized with symbolized client_options' do
28
+ @options = { client_options: { 'authorize_url' => 'https://example.com' } }
29
+ assert_equal 'https://example.com',
30
+ strategy.client.options[:authorize_url]
31
+ end
32
+ end
33
+
34
+ describe "AuthorizeParamsTests" do
35
+ it 'should include any authorize params passed in the :authorize_params option' do
36
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
37
+ assert_equal 'bar', strategy.authorize_params['foo']
38
+ assert_equal 'zip', strategy.authorize_params['baz']
39
+ end
40
+
41
+ it 'should include top-level options that are marked as :authorize_options' do
42
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
43
+ assert_equal 'bar', strategy.authorize_params['scope']
44
+ assert_equal 'baz', strategy.authorize_params['foo']
45
+ end
46
+
47
+ it 'should exclude top-level options that are not passed' do
48
+ @options = { :authorize_options => [:bar] }
49
+ refute_has_key :bar, strategy.authorize_params
50
+ refute_has_key 'bar', strategy.authorize_params
51
+ end
52
+ end
53
+
54
+ describe "CSRFAuthorizeParamsTests" do
55
+ it 'should store random state in the session when none is present in authorize or request params' do
56
+ assert_includes strategy.authorize_params.keys, 'state'
57
+ refute_empty strategy.authorize_params['state']
58
+ refute_empty strategy.session['omniauth.state']
59
+ assert_equal strategy.authorize_params['state'], strategy.session['omniauth.state']
60
+ end
61
+
62
+ it 'should not store state in the session when present in authorize params vs. a random one' do
63
+ @options = { :authorize_params => { :state => 'bar' } }
64
+ refute_empty strategy.authorize_params['state']
65
+ refute_equal 'bar', strategy.authorize_params[:state]
66
+ refute_empty strategy.session['omniauth.state']
67
+ refute_equal 'bar', strategy.session['omniauth.state']
68
+ end
69
+
70
+ it 'should not store state in the session when present in request params vs. a random one' do
71
+ @request.stubs(:params).returns({ 'state' => 'foo' })
72
+ refute_empty strategy.authorize_params['state']
73
+ refute_equal 'foo', strategy.authorize_params[:state]
74
+ refute_empty strategy.session['omniauth.state']
75
+ refute_equal 'foo', strategy.session['omniauth.state']
76
+ end
77
+ end
78
+
79
+ describe "TokenParamsTests" do
80
+ it 'should include any authorize params passed in the :token_params option' do
81
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
82
+ assert_equal 'bar', strategy.token_params['foo']
83
+ assert_equal 'zip', strategy.token_params['baz']
84
+ end
85
+
86
+ it 'should include top-level options that are marked as :token_options' do
87
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
88
+ assert_equal 'bar', strategy.token_params['scope']
89
+ assert_equal 'baz', strategy.token_params['foo']
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,41 @@
1
+ # inspired by omniauth-github, omniauth-clef and others
2
+
3
+ require 'test_helper'
4
+ require 'omniauth-matique'
5
+
6
+ describe OmniAuth::Strategies::Matique, 'raw_info test' do
7
+ let(:strategy) { OmniAuth::Strategies::Matique.new({}) }
8
+ let(:access_token) { stub('OAuth2::AccessToken') }
9
+ let(:get_param) { '/auth/matique/user.json?oauth_token=123' }
10
+
11
+ def setup
12
+ super
13
+ strategy.stubs(:access_token).returns(access_token)
14
+ access_token.stubs(:token).returns(123)
15
+ end
16
+
17
+ it 'performs a GET to https://...' do
18
+ access_token.expects(:get).with(get_param).
19
+ returns(stub_everything('OAuth2::Response'))
20
+ strategy.raw_info
21
+ end
22
+
23
+ it 'returns a Hash' do
24
+ raw_response = stub('Faraday::Response')
25
+ raw_response.stubs(:body).returns('{ "ohai": "thar" }')
26
+ raw_response.stubs(:status).returns(200)
27
+ raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
28
+ oauth2_response = OAuth2::Response.new(raw_response)
29
+ access_token.stubs(:get).with(get_param).returns(oauth2_response)
30
+ assert_kind_of Hash, strategy.raw_info
31
+ assert_equal 'thar', strategy.raw_info['ohai']
32
+ end
33
+
34
+ it 'returns an empty hash when the response is false' do
35
+ oauth2_response = stub('OAuth2::Response', :parsed => false)
36
+ access_token.stubs(:get).with(get_param).returns(oauth2_response)
37
+ access_token.stubs(:get).with(get_param).returns(oauth2_response)
38
+ assert_kind_of Hash, strategy.raw_info
39
+ end
40
+
41
+ end
@@ -0,0 +1,19 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'bundler/setup'
5
+ require 'minitest/autorun'
6
+ require 'mocha/setup'
7
+ require 'omniauth/strategies/matique'
8
+
9
+ OmniAuth.config.test_mode = true
10
+
11
+ def assert_has_key(key, hash, msg = nil)
12
+ msg = message(msg) { "Expected #{hash.inspect} to have key #{key.inspect}" }
13
+ assert hash.has_key?(key), msg
14
+ end
15
+
16
+ def refute_has_key(key, hash, msg = nil)
17
+ msg = message(msg) { "Expected #{hash.inspect} not to have key #{key.inspect}" }
18
+ refute hash.has_key?(key), msg
19
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-matique
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dittmar Krall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ description: " Strategy to authenticate with matique UG via OAuth2 in OmniAuth.\n"
56
+ email:
57
+ - dittmar.krall@matique.de
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-gemset"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
66
+ - ".watchr"
67
+ - Gemfile
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - lib/omniauth-matique.rb
72
+ - lib/omniauth-matique/version.rb
73
+ - lib/omniauth/strategies/matique.rb
74
+ - omniauth-matique.gemspec
75
+ - test/matique_test.rb
76
+ - test/oauth2strategy_test.rb
77
+ - test/raw_info_test.rb
78
+ - test/test_helper.rb
79
+ homepage: https://github.com/matique/omniauth-matique
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.6.12
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: OmniAuth strategy for matique
103
+ test_files:
104
+ - test/matique_test.rb
105
+ - test/oauth2strategy_test.rb
106
+ - test/raw_info_test.rb
107
+ - test/test_helper.rb