omniauth-jira-oauth2 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
+ SHA1:
3
+ metadata.gz: afa599ddadab31ffcdd40837e7d09e7da2e1fa29
4
+ data.tar.gz: 4b481dd83796c13a15d411ca32091fff2795940b
5
+ SHA512:
6
+ metadata.gz: 21d924474f3fcec7434a95d12ffc130384f600fbec05f669b9f2f6b6b98706ea1374154a5070775d92ab46563332bd815323034c20618789a455bce27b63c86b
7
+ data.tar.gz: 645f3417d9b4575aea55c24ad44a8f72e2ce44ad645c45231bd9abf82bb4ab3cd96099eac0308bbc6c3ad41bf0ddd6dfdde842e6d4d8f3ae8d3d99cb03d2c95f
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,11 @@
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.1.0 - 2019-09-18
7
+
8
+ ### Added
9
+ - First version released.
10
+ - Docs in README.
11
+ - Supports Jira API, refresh tokens, populating auth hash profile values, etc.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-jira-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-jira-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,114 @@
1
+ # OmniAuth Atlassian OAuth2 Strategy
2
+
3
+ Strategy to authenticate with Atlassian 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 docs about OAuth 2.0 (3LO):
9
+ https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/
10
+
11
+ Note that as of March 2019, the OAuth 2.0 APIs at in "developer preview" mode
12
+ with Atlassian. See
13
+ [ACJIRA-1588](https://ecosystem.atlassian.net/browse/ACJIRA-1588) for updates.
14
+
15
+ ## Installation
16
+
17
+ Add to your `Gemfile`:
18
+
19
+ ```ruby
20
+ gem 'omniauth-jira-oauth2'
21
+ ```
22
+
23
+ Then `bundle install`.
24
+
25
+ ## Atlassian API Setup
26
+
27
+ * Go to 'https://developer.atlassian.com/apps/'
28
+ * Create a new app.
29
+ * Note the Client ID and Secret values in the App Details section.
30
+ * Under APIs and Features, add the "Authorization code grants" feature.
31
+ Configure the feature with your callback URL (something like
32
+ http://localhost:3000/auth/jira_oauth2/callback).
33
+ * Under APIs and Features, add the "Jira platform REST API" API. Configure the
34
+ API by adding the "View Jira issue data" and "View user profiles" scopes. These coincide with the scopes listed in the [Jira scopes](https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/) section of the Atlassian Docs. Add additional scopes in this UI as needed.
35
+
36
+ ## Usage
37
+
38
+ Here's an example for adding the middleware to a Rails app in
39
+ `config/initializers/omniauth.rb`:
40
+
41
+ ```ruby
42
+ Rails.application.config.middleware.use OmniAuth::Builder do
43
+ provider :jira_oauth2, ENV['ATLASSIAN_CLIENT_ID'], ENV['ATLASSIAN_CLIENT_SECRET'],
44
+ scope: "offline_access read:jira-user read:jira-work",
45
+ prompt: "consent"
46
+ end
47
+ ```
48
+
49
+ This OmniAuth strategy makes API calls that require the `read:jira-user` scope,
50
+ so that scope must be included by you in your OmniAuth configuration. The
51
+ `offline_access` scope must be included if you wish to attain a refresh token.
52
+ You may wish to include additional scopes depending on how you've configured
53
+ your app in the Atlassian UI.
54
+
55
+ You can now access the OmniAuth Atlassian OAuth2 URL: `/auth/jira_oauth2`
56
+
57
+ NOTE: While developing your application, if you change the scope in the
58
+ initializer you will need to restart your app server. Remember that either the
59
+ 'email' or 'profile' scope is required!
60
+
61
+ ## Auth Hash
62
+
63
+ Here's an example of an authentication hash available in the callback by
64
+ accessing `request.env['omniauth.auth']`:
65
+
66
+ Note: Atlassian's OAuth2 flow grants access to potentially many Atlassian
67
+ "sites", and each site defines a user on its own. There's no single definitive
68
+ profile of the user. We must loop through the sites and call the
69
+ `/rest/api/3/myself` endpoint for each. `auth_hash['extra']['raw_info']['site']`
70
+ is the site that was used to populate `auth_hash['info']` and
71
+ `auth_hash['uid']`. `auth_hash['extra']['raw_info']['sites']` is the data for
72
+ all the sites available for the user.
73
+
74
+ After authing a user, when you make API calls over time, you should follow the
75
+ [Atlassian OAuth 2.0 docs](https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/)
76
+ and continue to check the `accessible-resources` endpoint to ensure your app
77
+ continues to have access to the sites you expect.
78
+
79
+ ```ruby
80
+ {
81
+ "provider" => "jira_oauth2",
82
+ "uid" => "100000000000000000000",
83
+ "info" => {
84
+ "name" => "John Smith",
85
+ "email" => "john@example.com",
86
+ "nickname" => "john_smith", # username
87
+ "location" => "Australia/Sydney", # time zone
88
+ "image" => "https://whatever.atlassiancdn.com/photo_48x48.jpg", # 48x48 pixels
89
+ },
90
+ "credentials" => {
91
+ "token" => "TOKEN",
92
+ "refresh_token" => "REFRESH_TOKEN",
93
+ "expires_at" => 1496120719,
94
+ "expires" => true
95
+ },
96
+ "extra" => {
97
+ "raw_info" => {
98
+ "site" => {},
99
+ "sites" => {},
100
+ "myself" => {},
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ ## License
107
+
108
+ Copyright (c) 2019 by Ben Standefer
109
+
110
+ 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:
111
+
112
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
113
+
114
+ 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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module JiraOauth2
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/jira_oauth2'
@@ -0,0 +1,78 @@
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:jira-user read:jira-work write:jira-work manage:jira-project manage:jira-configuration
8
+ #
9
+ # Separate scopes with a space (%20)
10
+ # https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/
11
+
12
+ module OmniAuth
13
+ module Strategies
14
+ # Omniauth strategy for Atlassian
15
+ class JiraOauth2 < OmniAuth::Strategies::OAuth2
16
+ option :name, 'jira_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']['accountId']
28
+ end
29
+
30
+ info do
31
+ {
32
+ name: raw_info['myself']['displayName'],
33
+ email: raw_info['myself']['emailAddress'],
34
+ nickname: raw_info['myself']['name'],
35
+ location: raw_info['myself']['timeZone'],
36
+ image: raw_info['myself']['avatarUrls']['48x48']
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
+ # Jira's OAuth gives us many potential sites. To request information
54
+ # about the user for the OmniAuth hash, pick the first one that has the
55
+ # necessary 'read:jira-user' scope.
56
+ jira_user_scope = 'read:jira-user'
57
+ site = sites.find do |candidate_site|
58
+ candidate_site['scopes'].include?(jira_user_scope)
59
+ end
60
+ unless site
61
+ raise "No site found with scope #{jira_user_scope}, please ensure the scope ${jira_user_scope} is added to your OmniAuth config"
62
+ end
63
+
64
+ cloud_id = site['id']
65
+ base_url = "https://api.atlassian.com/ex/jira/#{cloud_id}"
66
+ myself_url = "#{base_url}/rest/api/3/myself"
67
+
68
+ myself = JSON.parse(access_token.get(myself_url).body)
69
+
70
+ @raw_info ||= {
71
+ 'site' => site,
72
+ 'sites' => sites,
73
+ 'myself' => myself
74
+ }
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/jira_oauth2'
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(
4
+ File.join('..', 'lib', 'omniauth', 'jira_oauth2', 'version'),
5
+ __FILE__
6
+ )
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'omniauth-jira-oauth2'
10
+ gem.version = OmniAuth::JiraOauth2::VERSION
11
+ gem.license = 'MIT'
12
+ gem.summary = %(A Jira OAuth2 strategy for OmniAuth 1.x)
13
+ gem.description = %(An Jira OAuth2 strategy for OmniAuth 1.x. This allows you to login to Jira 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-jira-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: An Jira OAuth2 strategy for OmniAuth 1.x. This allows you to login to
84
+ Jira 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-jira-oauth2.rb
98
+ - lib/omniauth/jira_oauth2.rb
99
+ - lib/omniauth/jira_oauth2/version.rb
100
+ - lib/omniauth/strategies/jira_oauth2.rb
101
+ - omniauth-jira-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 Jira OAuth2 strategy for OmniAuth 1.x
126
+ test_files: []