omniauth-confluence-oauth2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +22 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +76 -0
- data/README.md +96 -0
- data/lib/omniauth-confluence-oauth2.rb +3 -0
- data/lib/omniauth/confluence_oauth2.rb +3 -0
- data/lib/omniauth/confluence_oauth2/version.rb +7 -0
- data/lib/omniauth/strategies/confluence_oauth2.rb +63 -0
- data/omniauth-confluence-oauth2.gemspec +29 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ac3d71dc95236d5efc111ad1e41c1e4aeaafbc6
|
4
|
+
data.tar.gz: c14471319332e0b6142da216b67ca7f210db480f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aedc5705cc763e273d652d33e18f6a0fe725ac9e7b7dbe9e42455ddf03102ba97b961defc1c1edad3dc9f109d79f750c4effa1edaef9b521e8ac6f668b46b460
|
7
|
+
data.tar.gz: eb431f34a69a887f883d66371c31b6b7c4345b0c947468671d8f34626309afd98cb04054da5c6b56e54cafde760f1afb3724c568c5f2f495762562fc68551424
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
ClassLength:
|
2
|
+
Enabled: false
|
3
|
+
Layout/IndentHeredoc:
|
4
|
+
Enabled: false
|
5
|
+
Metrics/AbcSize:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/BlockLength:
|
8
|
+
ExcludedMethods: ['describe', 'context']
|
9
|
+
Metrics/CyclomaticComplexity:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/LineLength:
|
12
|
+
Enabled: false
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Enabled: false
|
15
|
+
Metrics/PerceivedComplexity:
|
16
|
+
Enabled: false
|
17
|
+
Naming:
|
18
|
+
Enabled: false
|
19
|
+
Style/MutableConstant:
|
20
|
+
Enabled: false
|
21
|
+
Gemspec/RequiredRubyVersion:
|
22
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file. Follows the
|
4
|
+
religion set forth in https://keepachangelog.com/en/1.0.0/
|
5
|
+
|
6
|
+
## 0.2.0 - 2018-03-02
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- Fixed issue where callback phase was unnecessarily slow.
|
10
|
+
|
11
|
+
## 0.1.0 - 2018-03-01
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- First version released.
|
15
|
+
- Docs in README.
|
16
|
+
- Supports Jira API, refresh tokens, populating auth hash profile values, etc.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-atlassian-oauth2 (0.1.0)
|
5
|
+
omniauth (>= 1.1.1)
|
6
|
+
omniauth-oauth2 (>= 1.5)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
faraday (0.15.4)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
hashie (3.6.0)
|
16
|
+
jaro_winkler (1.5.2)
|
17
|
+
jwt (2.1.0)
|
18
|
+
multi_json (1.13.1)
|
19
|
+
multi_xml (0.6.0)
|
20
|
+
multipart-post (2.0.0)
|
21
|
+
oauth2 (1.4.1)
|
22
|
+
faraday (>= 0.8, < 0.16.0)
|
23
|
+
jwt (>= 1.0, < 3.0)
|
24
|
+
multi_json (~> 1.3)
|
25
|
+
multi_xml (~> 0.5)
|
26
|
+
rack (>= 1.2, < 3)
|
27
|
+
omniauth (1.9.0)
|
28
|
+
hashie (>= 3.4.6, < 3.7.0)
|
29
|
+
rack (>= 1.6.2, < 3)
|
30
|
+
omniauth-oauth2 (1.6.0)
|
31
|
+
oauth2 (~> 1.1)
|
32
|
+
omniauth (~> 1.9)
|
33
|
+
parallel (1.14.0)
|
34
|
+
parser (2.6.0.0)
|
35
|
+
ast (~> 2.4.0)
|
36
|
+
powerpack (0.1.2)
|
37
|
+
psych (3.1.0)
|
38
|
+
rack (2.0.6)
|
39
|
+
rainbow (3.0.0)
|
40
|
+
rake (12.3.2)
|
41
|
+
rspec (3.8.0)
|
42
|
+
rspec-core (~> 3.8.0)
|
43
|
+
rspec-expectations (~> 3.8.0)
|
44
|
+
rspec-mocks (~> 3.8.0)
|
45
|
+
rspec-core (3.8.0)
|
46
|
+
rspec-support (~> 3.8.0)
|
47
|
+
rspec-expectations (3.8.2)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-mocks (3.8.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-support (3.8.0)
|
54
|
+
rubocop (0.65.0)
|
55
|
+
jaro_winkler (~> 1.5.1)
|
56
|
+
parallel (~> 1.10)
|
57
|
+
parser (>= 2.5, != 2.5.1.1)
|
58
|
+
powerpack (~> 0.1)
|
59
|
+
psych (>= 3.1.0)
|
60
|
+
rainbow (>= 2.2.2, < 4.0)
|
61
|
+
ruby-progressbar (~> 1.7)
|
62
|
+
unicode-display_width (~> 1.4.0)
|
63
|
+
ruby-progressbar (1.10.0)
|
64
|
+
unicode-display_width (1.4.1)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
omniauth-atlassian-oauth2!
|
71
|
+
rake (~> 12.0)
|
72
|
+
rspec (~> 3.6)
|
73
|
+
rubocop (~> 0.49)
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
1.17.1
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# OmniAuth Confluence OAuth2 Strategy
|
2
|
+
|
3
|
+
Strategy to authenticate with Confluence via OAuth2 in OmniAuth.
|
4
|
+
|
5
|
+
Get your API key at: https://developer.atlassian.com/apps/ Note the Client ID
|
6
|
+
and the Client Secret.
|
7
|
+
|
8
|
+
For more details, read the Atlassian Confluence docs about OAuth 2.0 (3LO):
|
9
|
+
https://developer.atlassian.com/cloud/confluence/oauth-2-authorization-code-grants-3lo-for-apps/
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add to your `Gemfile`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'omniauth-confluence-oauth2'
|
17
|
+
```
|
18
|
+
|
19
|
+
Then `bundle install`.
|
20
|
+
|
21
|
+
## Confluence API Setup
|
22
|
+
|
23
|
+
* Go to 'https://developer.atlassian.com/apps/'
|
24
|
+
* Create a new app.
|
25
|
+
* Note the Client ID and Secret values in the App Details section.
|
26
|
+
* Under APIs and Features, add the "Authorization code grants" feature.
|
27
|
+
Configure the feature with your callback URL (something like
|
28
|
+
http://localhost:3000/auth/confluence_oauth2/callback).
|
29
|
+
* Under APIs and Features, add the "Confluence platform REST API" API.
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Here's an example for adding the middleware to a Rails app in
|
34
|
+
`config/initializers/omniauth.rb`:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
38
|
+
provider :confluence_oauth2, ENV['CONFLUENCE_CLIENT_ID'], ENV['CONFLUENCE_CLIENT_SECRET'],
|
39
|
+
scope: "offline_access read:me read:confluence-space.summary read:confluence-props read:confluence-content.all read:confluence-content.summary search:confluence",
|
40
|
+
prompt: "consent"
|
41
|
+
end
|
42
|
+
```
|
43
|
+
The `offline_access` scope must be included if you wish to attain a refresh token.
|
44
|
+
You may wish to include additional scopes depending on how you've configured
|
45
|
+
your app in the Atlassian UI.
|
46
|
+
|
47
|
+
You can now access the OmniAuth Confluence OAuth2 URL: `/auth/confluence_oauth2`
|
48
|
+
|
49
|
+
NOTE: While developing your application, if you change the scope in the
|
50
|
+
initializer you will need to restart your app server.
|
51
|
+
|
52
|
+
## Auth Hash
|
53
|
+
|
54
|
+
Here's an example of an authentication hash available in the callback by
|
55
|
+
accessing `request.env['omniauth.auth']`:
|
56
|
+
|
57
|
+
After authing a user, when you make API calls over time, you should follow the
|
58
|
+
[Confluence OAuth 2.0 docs](https://developer.atlassian.com/cloud/confluence/oauth-2-authorization-code-grants-3lo-for-apps/)
|
59
|
+
and continue to check the `accessible-resources` endpoint to ensure your app
|
60
|
+
continues to have access to the sites you expect.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
{
|
64
|
+
"provider" => "confluence_oauth2",
|
65
|
+
"uid" => "100000000000000000000",
|
66
|
+
"info" => {
|
67
|
+
"name" => "John Smith",
|
68
|
+
"email" => "john@example.com",
|
69
|
+
"nickname" => "john_smith", # username
|
70
|
+
"location" => "Australia/Sydney", # time zone
|
71
|
+
"image" => "https://whatever.atlassiancdn.com/photo.jpg",
|
72
|
+
},
|
73
|
+
"credentials" => {
|
74
|
+
"token" => "TOKEN",
|
75
|
+
"refresh_token" => "REFRESH_TOKEN",
|
76
|
+
"expires_at" => 1496120719,
|
77
|
+
"expires" => true
|
78
|
+
},
|
79
|
+
"extra" => {
|
80
|
+
"raw_info" => {
|
81
|
+
"sites" => {},
|
82
|
+
"myself" => {},
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
Copyright (c) 2019 by Ben Standefer
|
91
|
+
|
92
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
93
|
+
|
94
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
95
|
+
|
96
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'omniauth/strategies/oauth2'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
# Potential scopes: https://developer.atlassian.com/cloud/jira/platform/scopes/
|
7
|
+
# offline_access read:confluence-space.summary read:confluence-props read:confluence-content.all read:confluence-content.summary search:confluence
|
8
|
+
#
|
9
|
+
# Separate scopes with a space (%20)
|
10
|
+
# https://developer.atlassian.com/cloud/confluence/oauth-2-authorization-code-grants-3lo-for-apps/
|
11
|
+
|
12
|
+
module OmniAuth
|
13
|
+
module Strategies
|
14
|
+
# Omniauth strategy for Confluence
|
15
|
+
class ConfluenceOauth2 < OmniAuth::Strategies::OAuth2
|
16
|
+
option :name, 'confluence_oauth2'
|
17
|
+
option :client_options,
|
18
|
+
site: 'https://auth.atlassian.com',
|
19
|
+
authorize_url: 'https://auth.atlassian.com/authorize',
|
20
|
+
token_url: 'https://auth.atlassian.com/oauth/token',
|
21
|
+
audience: 'api.atlassian.com'
|
22
|
+
option :authorize_params,
|
23
|
+
prompt: 'consent',
|
24
|
+
audience: 'api.atlassian.com'
|
25
|
+
|
26
|
+
uid do
|
27
|
+
raw_info['myself']['account_id']
|
28
|
+
end
|
29
|
+
|
30
|
+
info do
|
31
|
+
{
|
32
|
+
name: raw_info['myself']['name'],
|
33
|
+
email: raw_info['myself']['email'],
|
34
|
+
nickname: raw_info['myself']['nickname'],
|
35
|
+
location: raw_info['myself']['zoneinfo'],
|
36
|
+
image: raw_info['myself']['picture']
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
extra do
|
41
|
+
{
|
42
|
+
'raw_info' => raw_info
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def raw_info
|
47
|
+
return @raw_info if @raw_info
|
48
|
+
|
49
|
+
# NOTE: api.atlassian.com, not auth.atlassian.com!
|
50
|
+
accessible_resources_url = 'https://api.atlassian.com/oauth/token/accessible-resources'
|
51
|
+
sites = JSON.parse(access_token.get(accessible_resources_url).body)
|
52
|
+
|
53
|
+
myself_url = "https://api.atlassian.com/me"
|
54
|
+
myself = JSON.parse(access_token.get(myself_url).body)
|
55
|
+
|
56
|
+
@raw_info ||= {
|
57
|
+
'sites' => sites,
|
58
|
+
'myself' => myself
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path(
|
4
|
+
File.join('..', 'lib', 'omniauth', 'confluence_oauth2', 'version'),
|
5
|
+
__FILE__
|
6
|
+
)
|
7
|
+
|
8
|
+
Gem::Specification.new do |gem|
|
9
|
+
gem.name = 'omniauth-confluence-oauth2'
|
10
|
+
gem.version = OmniAuth::ConfluenceOauth2::VERSION
|
11
|
+
gem.license = 'MIT'
|
12
|
+
gem.summary = %(A Confluence OAuth2 strategy for OmniAuth 1.x)
|
13
|
+
gem.description = %(A Confluence OAuth2 strategy for OmniAuth 1.x. This allows you to login to Confluence with your Ruby app.)
|
14
|
+
gem.authors = ['Ben Standefer']
|
15
|
+
gem.email = ['benstandefer@gmail.com']
|
16
|
+
gem.homepage = 'https://github.com/aguynamedben/omniauth-atlassian-oauth2'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split("\n")
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 2.1'
|
22
|
+
|
23
|
+
gem.add_runtime_dependency 'omniauth', '>= 1.1.1'
|
24
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '>= 1.5'
|
25
|
+
|
26
|
+
gem.add_development_dependency 'rake', '~> 12.0'
|
27
|
+
gem.add_development_dependency 'rspec', '~> 3.6'
|
28
|
+
gem.add_development_dependency 'rubocop', '~> 0.49'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-confluence-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Standefer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-20 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.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.1
|
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: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.49'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.49'
|
83
|
+
description: A Confluence OAuth2 strategy for OmniAuth 1.x. This allows you to login
|
84
|
+
to Confluence with your Ruby app.
|
85
|
+
email:
|
86
|
+
- benstandefer@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- README.md
|
97
|
+
- lib/omniauth-confluence-oauth2.rb
|
98
|
+
- lib/omniauth/confluence_oauth2.rb
|
99
|
+
- lib/omniauth/confluence_oauth2/version.rb
|
100
|
+
- lib/omniauth/strategies/confluence_oauth2.rb
|
101
|
+
- omniauth-confluence-oauth2.gemspec
|
102
|
+
homepage: https://github.com/aguynamedben/omniauth-atlassian-oauth2
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '2.1'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: A Confluence OAuth2 strategy for OmniAuth 1.x
|
126
|
+
test_files: []
|