omniauth-redmine-oauth2 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
+ SHA1:
3
+ metadata.gz: 29dc07377a60b0d0887f761b20d860bedbb14ab3
4
+ data.tar.gz: 6f6864ed841d365486abdcc44cf71454542fbf7a
5
+ SHA512:
6
+ metadata.gz: 617d1574712a1ffb75671797185a8e4d0e8a452d6eff8ffad76fc2e81b63e95d5a228cd9b1c02af2fc839d1ba33713900d6b9d5c1e3cda4bee310060a9936f16
7
+ data.tar.gz: a2342137fe4aa6a79bb226c9ba3f10f7db3a1190d1ee73d0aa911c595ca5824b1134960e875e521a8b4556354009125b398d30cf91b0e7a34a0187651d92a8c9
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-redmine-oauth2 (0.1.0)
5
+ omniauth (~> 1.8)
6
+ omniauth-oauth2 (~> 1.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.4.4)
16
+ faraday (1.0.1)
17
+ multipart-post (>= 1.2, < 3)
18
+ hashdiff (1.0.1)
19
+ hashie (4.1.0)
20
+ jwt (2.2.2)
21
+ multi_json (1.15.0)
22
+ multi_xml (0.6.0)
23
+ multipart-post (2.1.1)
24
+ oauth2 (1.4.4)
25
+ faraday (>= 0.8, < 2.0)
26
+ jwt (>= 1.0, < 3.0)
27
+ multi_json (~> 1.3)
28
+ multi_xml (~> 0.5)
29
+ rack (>= 1.2, < 3)
30
+ omniauth (1.9.1)
31
+ hashie (>= 3.4.6)
32
+ rack (>= 1.6.2, < 3)
33
+ omniauth-oauth2 (1.7.0)
34
+ oauth2 (~> 1.4)
35
+ omniauth (~> 1.9)
36
+ public_suffix (4.0.5)
37
+ rack (2.2.3)
38
+ rack-test (1.1.0)
39
+ rack (>= 1.0, < 3)
40
+ rake (13.0.1)
41
+ rspec (3.9.0)
42
+ rspec-core (~> 3.9.0)
43
+ rspec-expectations (~> 3.9.0)
44
+ rspec-mocks (~> 3.9.0)
45
+ rspec-core (3.9.2)
46
+ rspec-support (~> 3.9.3)
47
+ rspec-expectations (3.9.2)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.9.0)
50
+ rspec-mocks (3.9.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.9.0)
53
+ rspec-support (3.9.3)
54
+ safe_yaml (1.0.5)
55
+ webmock (3.8.3)
56
+ addressable (>= 2.3.6)
57
+ crack (>= 0.3.2)
58
+ hashdiff (>= 0.4.0, < 2.0.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ omniauth-redmine-oauth2!
65
+ rack-test
66
+ rake
67
+ rspec (~> 3.5)
68
+ webmock
69
+
70
+ BUNDLED WITH
71
+ 1.17.3
@@ -0,0 +1,59 @@
1
+ # OAuth 2 OmniAuth strategy for Redmine
2
+
3
+ Allows client applications to access Redmine resources. For now, you will need
4
+ to apply [this patch](https://www.redmine.org/issues/24808).
5
+
6
+ ## Usage
7
+
8
+ Add the Gem to your Gemfile. Exact usage depends on your environment, here are
9
+ some examples:
10
+
11
+ ### Rails, plain OmniAuth
12
+
13
+ In an initializer, do
14
+
15
+ ~~~ruby
16
+ Rails.application.config.middleware.use OmniAuth::Builder do
17
+ provider :redmine_oauth2,
18
+ ENV['REDMINE_APP_ID'],
19
+ ENV['REDMINE_APP_SECRET'],
20
+ client_options: { site: 'https://redmine.yourcompany.com' },
21
+ scope: 'view_issues'
22
+ end
23
+ ~~~
24
+
25
+ ### Rails, with Devise
26
+
27
+ ~~~ruby
28
+ Devise.setup do |config|
29
+ config.omniauth :redmine_oauth2,
30
+ ENV['REDMINE_APP_ID'],
31
+ ENV['REDMINE_APP_SECRET'],
32
+ client_options: { site: 'https://redmine.yourcompany.com' },
33
+ scope: 'view_issues'
34
+ end
35
+ ~~~
36
+
37
+
38
+
39
+ ## License
40
+
41
+ Copyright (c) 2020 by Jens Kraemer, Planio GmbH
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
44
+ this software and associated documentation files (the "Software"), to deal in
45
+ the Software without restriction, including without limitation the rights to
46
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
47
+ of the Software, and to permit persons to whom the Software is furnished to do
48
+ so, subject to the following conditions:
49
+
50
+ The above copyright notice and this permission notice shall be included in all
51
+ copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
59
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task default: :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth/redmine_oauth2/version"
2
+ require "omniauth/strategies/redmine_oauth2"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module RedmineOauth2
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth-oauth2"
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class RedmineOauth2 < OmniAuth::Strategies::OAuth2
8
+
9
+ USER_INFO_PATH = "users/current.json"
10
+
11
+ option :name, "redmine_oauth2"
12
+
13
+ option :client_options, {
14
+ site: "https://redmine.example.org",
15
+ authorize_url: "/oauth/authorize",
16
+ token_url: "/oauth/token"
17
+ }
18
+
19
+ uid { raw_info["id"] }
20
+
21
+ info do
22
+ {
23
+ email: email,
24
+ login: raw_info["login"],
25
+ last_name: raw_info["lastname"],
26
+ first_name: raw_info["firstname"]
27
+ }
28
+ end
29
+
30
+ extra do
31
+ { raw_info: raw_info, scope: scope }
32
+ end
33
+
34
+ def email
35
+ raw_info['mail']
36
+ end
37
+
38
+ def scope
39
+ access_token['scope']
40
+ end
41
+
42
+ def raw_info
43
+ access_token.options[:mode] = :header
44
+ @raw_info ||= access_token.get(USER_INFO_PATH).parsed['user']
45
+ end
46
+
47
+ private
48
+
49
+ # https://github.com/omniauth/omniauth-oauth2/issues/81
50
+ def callback_url
51
+ full_host + script_name + callback_path
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(
4
+ File.join('..', 'lib', 'omniauth', 'redmine_oauth2', 'version'),
5
+ __FILE__
6
+ )
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'omniauth-redmine-oauth2'
10
+ gem.version = OmniAuth::RedmineOauth2::VERSION
11
+ gem.license = 'MIT'
12
+ gem.summary = %(A Redmine OAuth2 strategy for OmniAuth 1.x)
13
+ gem.description = %(A Redmine OAuth2 strategy for OmniAuth 1.x. This allows you to login to OAuth enabled Redmine with your Ruby app.)
14
+ gem.authors = ['Jens Kraemer']
15
+ gem.email = ['jens@planio.com']
16
+ gem.homepage = 'https://github.com/planio-gmbh/omniauth-redmine-oauth2'
17
+
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.required_ruby_version = '>= 2.4'
22
+
23
+ gem.add_runtime_dependency 'omniauth', '~> 1.8'
24
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.5'
25
+
26
+ gem.add_development_dependency 'rspec', '~> 3.5'
27
+ gem.add_development_dependency 'rake'
28
+ gem.add_development_dependency 'rack-test'
29
+ gem.add_development_dependency 'webmock'
30
+ end
31
+
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::RedmineOauth2 do
4
+ let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'view_issues') }
5
+ let(:parsed_response) { instance_double('ParsedResponse') }
6
+ let(:response) { instance_double('Response', :parsed => parsed_response) }
7
+
8
+ let(:redmine_site) { 'https://some.redmine.com' }
9
+
10
+ subject do
11
+ OmniAuth::Strategies::RedmineOauth2.new('REDMINE_KEY', 'REDMINE_SECRET',
12
+ {
13
+ :client_options => {
14
+ :site => redmine_site
15
+ }
16
+ }
17
+ )
18
+ end
19
+
20
+ before(:each) do
21
+ allow(subject).to receive(:access_token).and_return(access_token)
22
+ end
23
+
24
+ context 'client options' do
25
+ it 'should have correct authorize url' do
26
+ expect(subject.options.client_options.authorize_url).to eq('/oauth/authorize')
27
+ end
28
+
29
+ it 'should have correct token url' do
30
+ expect(subject.options.client_options.token_url).to eq('/oauth/token')
31
+ end
32
+
33
+ it 'should have configured site' do
34
+ expect(subject.options.client_options.site).to eq(redmine_site)
35
+ end
36
+ end
37
+
38
+ context '#email' do
39
+ it 'should return email from raw_info if available' do
40
+ allow(subject).to receive(:raw_info).and_return({ 'mail' => 'you@example.com' })
41
+ expect(subject.email).to eq('you@example.com')
42
+ end
43
+ end
44
+
45
+ context '#raw_info' do
46
+ it 'should use relative paths' do
47
+ expect(access_token).to receive(:get).with('users/current.json').and_return(response)
48
+ expect(subject.raw_info).to eq(parsed_response)
49
+ end
50
+
51
+ it 'should use the header auth mode' do
52
+ expect(access_token).to receive(:get).with('users/current.json').and_return(response)
53
+ subject.raw_info
54
+ expect(access_token.options[:mode]).to eq(:header)
55
+ end
56
+ end
57
+
58
+ context '#info' do
59
+ it 'should contain email' do
60
+ allow(subject).to receive(:raw_info).and_return({ 'mail' => 'you@example.com' })
61
+ expect(subject.info[:email]).to eq('you@example.com')
62
+ end
63
+ it 'should contain login' do
64
+ allow(subject).to receive(:raw_info).and_return({ 'login' => 'bob' })
65
+ expect(subject.info[:login]).to eq('bob')
66
+ end
67
+ end
68
+
69
+ context '#extra.scope' do
70
+ it 'returns the scope on the returned access_token' do
71
+ expect(subject.scope).to eq('view_issues')
72
+ end
73
+ end
74
+
75
+ describe '#callback_url' do
76
+ it 'is a combination of host, script name, and callback path' do
77
+ allow(subject).to receive(:full_host).and_return('https://example.com')
78
+ allow(subject).to receive(:script_name).and_return('/sub_uri')
79
+
80
+ expect(subject.send :callback_url).to eq('https://example.com/sub_uri/auth/redmine_oauth2/callback')
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'rack/test'
6
+ require 'webmock/rspec'
7
+ require 'omniauth'
8
+ require 'omniauth-redmine-oauth2'
9
+
10
+ RSpec.configure do |config|
11
+ config.include WebMock::API
12
+ config.include Rack::Test::Methods
13
+ config.extend OmniAuth::Test::StrategyMacros, type: :strategy
14
+ end
15
+
16
+
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-redmine-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jens Kraemer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-24 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.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
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.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
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
+ description: A Redmine OAuth2 strategy for OmniAuth 1.x. This allows you to login
98
+ to OAuth enabled Redmine with your Ruby app.
99
+ email:
100
+ - jens@planio.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - README.md
108
+ - Rakefile
109
+ - lib/omniauth-redmine-oauth2.rb
110
+ - lib/omniauth/redmine_oauth2/version.rb
111
+ - lib/omniauth/strategies/redmine_oauth2.rb
112
+ - omniauth-redmine-oauth2.gemspec
113
+ - spec/omniauth/strategies/redmine_oauth2_spec.rb
114
+ - spec/spec_helper.rb
115
+ homepage: https://github.com/planio-gmbh/omniauth-redmine-oauth2
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '2.4'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.6.14.4
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: A Redmine OAuth2 strategy for OmniAuth 1.x
139
+ test_files: []