omniauth-slack2 1.0.0

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
+ SHA256:
3
+ metadata.gz: 676e8bca1d301129a743833094fc6104e3aa26717b14123463581085575a78bd
4
+ data.tar.gz: 9c19ea41a7fbefbd6883aee1c406b403963d4c530fc986fa7bb0c9c19916e241
5
+ SHA512:
6
+ metadata.gz: b01b0d6b7ba3cf8f74907871dc02f22bf0cea234c5de6866ffbf0677dc24fcb54522e100b1bd32ee3aa45cd4b07773279cd44bfd16fbfbf6fe0e3cb8e9dff4e4
7
+ data.tar.gz: c8e1d88d45f41172b8deffacb0d771b9825b65b0f1d05d6ef726fd251f747a6dd1a8ce0c7e956f39f3d7fcff0fb149294f2edff96b386769a6e708475dddffcc
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Claudio Poli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,193 @@
1
+ # OmniAuth Slack Strategy
2
+
3
+ [![Test](https://github.com/icoretech/omniauth-slack2/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/icoretech/omniauth-slack2/actions/workflows/test.yml?query=branch%3Amain)
4
+ [![Gem Version](https://badge.fury.io/rb/omniauth-slack2.svg)](https://badge.fury.io/rb/omniauth-slack2)
5
+
6
+ `omniauth-slack2` provides a Slack OpenID Connect strategy for OmniAuth.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'omniauth-slack2'
14
+ ```
15
+
16
+ Then run:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Configure OmniAuth in your Rack/Rails app:
25
+
26
+ ```ruby
27
+ Rails.application.config.middleware.use OmniAuth::Builder do
28
+ provider :slack2,
29
+ ENV.fetch('SLACK_CLIENT_ID'),
30
+ ENV.fetch('SLACK_CLIENT_SECRET')
31
+ end
32
+ ```
33
+
34
+ Compatibility alias is available, so you can keep existing callback paths using `slack`:
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :slack,
39
+ ENV.fetch('SLACK_CLIENT_ID'),
40
+ ENV.fetch('SLACK_CLIENT_SECRET')
41
+ end
42
+ ```
43
+
44
+ If you support both names during a migration, register both callback paths in Slack:
45
+
46
+ - `https://your-app.example.com/auth/slack2/callback`
47
+ - `https://your-app.example.com/auth/slack/callback`
48
+
49
+ ## Provider App Setup
50
+
51
+ - Slack API Dashboard: <https://api.slack.com/apps>
52
+ - Enable **Sign in with Slack** under OAuth & Permissions
53
+ - Register the callback URL that matches your provider name:
54
+ - `slack2`: `https://your-app.example.com/auth/slack2/callback`
55
+ - `slack`: `https://your-app.example.com/auth/slack/callback`
56
+ - If your Slack app enforces PKCE, this strategy sends `code_challenge` / `code_verifier`
57
+ with `S256` by default
58
+ - Required scopes: `openid`, `email`, `profile`
59
+
60
+ ## Options
61
+
62
+ Supported request options include:
63
+
64
+ - `scope` (default: `openid email profile`)
65
+ - `nonce` (auto-generated by default)
66
+ - `team` (pre-select a Slack workspace)
67
+ - `pkce` (default: `true` — sends `code_challenge` / `code_verifier` using `S256`)
68
+ - `skip_jwt` (default: `false` — set to `true` to skip id_token RS256 verification)
69
+
70
+ ## Troubleshooting
71
+
72
+ - If Slack rejects a local callback while your app is enforcing PKCE, prefer a real
73
+ HTTPS hostname over `localhost` for interactive testing
74
+ - The same callback/PKCE rules apply to the compat `slack` alias, not just `slack2`
75
+
76
+ ## Auth Hash
77
+
78
+ Example payload from `request.env['omniauth.auth']` (realistic shape, anonymized):
79
+
80
+ ```json
81
+ {
82
+ "uid": "U0R7MFMJM",
83
+ "info": {
84
+ "name": "Sample User",
85
+ "email": "sample@example.test",
86
+ "unverified_email": "sample@example.test",
87
+ "email_verified": true,
88
+ "first_name": "Sample",
89
+ "last_name": "User",
90
+ "image": "https://secure.gravatar.com/avatar/example.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fexample.png",
91
+ "locale": "en-US"
92
+ },
93
+ "credentials": {
94
+ "token": "xoxp-...",
95
+ "refresh_token": "xoxe-1-...",
96
+ "expires_at": 1772691847,
97
+ "expires": true,
98
+ "scope": "openid email profile"
99
+ },
100
+ "extra": {
101
+ "raw_info": {
102
+ "ok": true,
103
+ "sub": "U0R7MFMJM",
104
+ "https://slack.com/user_id": "U0R7MFMJM",
105
+ "https://slack.com/team_id": "T0123ABC456",
106
+ "email": "sample@example.test",
107
+ "email_verified": true,
108
+ "date_email_verified": 1775000482,
109
+ "name": "Sample User",
110
+ "picture": "https://secure.gravatar.com/avatar/example.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fexample.png",
111
+ "given_name": "Sample",
112
+ "family_name": "User",
113
+ "locale": "en-US",
114
+ "https://slack.com/team_name": "Sample Workspace",
115
+ "https://slack.com/team_domain": "sampleworkspace",
116
+ "https://slack.com/user_image_512": "https://secure.gravatar.com/avatar/example.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fexample.png",
117
+ "https://slack.com/team_image_230": "https://avatars.slack-edge.com/example-team_132.jpg",
118
+ "https://slack.com/team_image_default": false
119
+ },
120
+ "id_token": "eyJhbGciOiJSUzI1NiIs...",
121
+ "id_info": {
122
+ "iss": "https://slack.com",
123
+ "sub": "U0R7MFMJM",
124
+ "aud": "your-client-id",
125
+ "exp": 1775009314,
126
+ "iat": 1775009014,
127
+ "auth_time": 1775009014,
128
+ "nonce": "auto-generated-nonce",
129
+ "https://slack.com/team_id": "T0123ABC456",
130
+ "https://slack.com/user_id": "U0R7MFMJM",
131
+ "email": "sample@example.test",
132
+ "email_verified": true,
133
+ "date_email_verified": 1775000482,
134
+ "locale": "en-US",
135
+ "name": "Sample User",
136
+ "picture": "https://secure.gravatar.com/avatar/example.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fexample.png",
137
+ "given_name": "Sample",
138
+ "family_name": "User",
139
+ "https://slack.com/team_name": "Sample Workspace",
140
+ "https://slack.com/team_domain": "sampleworkspace",
141
+ "https://slack.com/team_image_230": "https://avatars.slack-edge.com/example-team_132.jpg",
142
+ "https://slack.com/team_image_default": false
143
+ },
144
+ "team_id": "T0123ABC456",
145
+ "team_name": "Sample Workspace",
146
+ "team_domain": "sampleworkspace"
147
+ }
148
+ }
149
+ ```
150
+
151
+ ## Development
152
+
153
+ ```bash
154
+ bundle install
155
+ bundle exec standardrb --fix
156
+ bundle exec rake
157
+ ```
158
+
159
+ Run Rails integration tests with an explicit Rails version:
160
+
161
+ ```bash
162
+ RAILS_VERSION='~> 8.1.0' bundle install
163
+ RAILS_VERSION='~> 8.1.0' bundle exec rake test_rails_integration
164
+ ```
165
+
166
+ ## Compatibility
167
+
168
+ - Ruby: `>= 3.2` (tested on `3.2`, `3.3`, `3.4`, `4.0`)
169
+ - `omniauth-oauth2`: `>= 1.8`, `< 2.0`
170
+ - Rails integration lanes: `~> 7.1.0`, `~> 7.2.0`, `~> 8.0.0`, `~> 8.1.0`
171
+
172
+ ## Endpoints
173
+
174
+ This gem uses Slack OpenID Connect endpoints:
175
+
176
+ - `https://slack.com/openid/connect/authorize`
177
+ - `https://slack.com/api/openid.connect.token`
178
+ - `https://slack.com/api/openid.connect.userInfo`
179
+ - `https://slack.com/openid/connect/keys` (JWKS for id_token verification)
180
+
181
+ ## Test Structure
182
+
183
+ - `test/omniauth_slack2_test.rb`: strategy/unit behavior
184
+ - `test/rails_integration_test.rb`: full Rack/Rails request+callback flow
185
+ - `test/test_helper.rb`: shared test bootstrap
186
+
187
+ ## Release
188
+
189
+ Tag releases as `vX.Y.Z`; GitHub Actions publishes the gem to RubyGems.
190
+
191
+ ## License
192
+
193
+ MIT
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Slack2
5
+ VERSION = "1.0.0"
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth/slack2/version"
4
+ require "omniauth/strategies/slack2"
@@ -0,0 +1,219 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
4
+ require "jwt"
5
+ require "net/http"
6
+ require "omniauth-oauth2"
7
+ require "securerandom"
8
+ require "uri"
9
+
10
+ module OmniAuth
11
+ module Strategies
12
+ # OmniAuth strategy for Slack OpenID Connect.
13
+ class Slack2 < OmniAuth::Strategies::OAuth2
14
+ ISSUER = "https://slack.com"
15
+ JWKS_URL = "https://slack.com/openid/connect/keys"
16
+ USER_INFO_URL = "https://slack.com/api/openid.connect.userInfo"
17
+ DEFAULT_SCOPE = "openid email profile"
18
+
19
+ option :name, "slack2"
20
+ option :authorize_options, %i[scope state nonce team]
21
+ option :scope, DEFAULT_SCOPE
22
+ option :pkce, true
23
+ option :skip_jwt, false
24
+
25
+ option :client_options,
26
+ site: ISSUER,
27
+ authorize_url: "https://slack.com/openid/connect/authorize",
28
+ token_url: "https://slack.com/api/openid.connect.token",
29
+ connection_opts: {
30
+ headers: {
31
+ user_agent: "icoretech-omniauth-slack2 gem",
32
+ accept: "application/json",
33
+ content_type: "application/json"
34
+ }
35
+ }
36
+
37
+ uid { raw_info["sub"] }
38
+
39
+ info do
40
+ {
41
+ name: raw_info["name"],
42
+ email: raw_info["email_verified"] ? raw_info["email"] : nil,
43
+ unverified_email: raw_info["email"],
44
+ email_verified: raw_info["email_verified"],
45
+ first_name: raw_info["given_name"],
46
+ last_name: raw_info["family_name"],
47
+ image: raw_info["picture"],
48
+ locale: raw_info["locale"]
49
+ }.reject { |_, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) }
50
+ end
51
+
52
+ credentials do
53
+ {
54
+ "token" => access_token.token,
55
+ "refresh_token" => access_token.refresh_token,
56
+ "expires_at" => access_token.expires_at,
57
+ "expires" => access_token.expires?,
58
+ "scope" => token_scope
59
+ }.compact
60
+ end
61
+
62
+ extra do
63
+ data = {
64
+ "raw_info" => raw_info,
65
+ "team_id" => raw_info["https://slack.com/team_id"],
66
+ "team_name" => raw_info["https://slack.com/team_name"],
67
+ "team_domain" => raw_info["https://slack.com/team_domain"]
68
+ }
69
+
70
+ id_token_raw = access_token["id_token"]
71
+ unless blank?(id_token_raw)
72
+ data["id_token"] = id_token_raw
73
+ decoded = verify_and_decode_id_token(id_token_raw)
74
+ data["id_info"] = decoded if decoded
75
+ end
76
+
77
+ data.compact
78
+ end
79
+
80
+ # Error raised when callback validation fails.
81
+ class CallbackError < StandardError; end
82
+
83
+ def authorize_params
84
+ super.tap do |params|
85
+ apply_request_authorize_overrides(params)
86
+ params[:nonce] ||= new_nonce
87
+ end
88
+ end
89
+
90
+ def callback_url
91
+ options[:callback_url] || options[:redirect_uri] || super
92
+ end
93
+
94
+ def query_string
95
+ return "" if request.params["code"]
96
+
97
+ super
98
+ end
99
+
100
+ def raw_info
101
+ @raw_info ||= access_token.get(USER_INFO_URL).parsed
102
+ end
103
+
104
+ private
105
+
106
+ def verify_and_decode_id_token(token)
107
+ return skip_jwt_decode(token) if options[:skip_jwt]
108
+
109
+ decode_and_verify_id_token(token)
110
+ end
111
+
112
+ def skip_jwt_decode(token)
113
+ payload, = JWT.decode(token, nil, false)
114
+ payload
115
+ rescue JWT::DecodeError
116
+ nil
117
+ end
118
+
119
+ def decode_and_verify_id_token(token)
120
+ jwk = fetch_jwk(extract_kid(token))
121
+ payload = decode_payload(token, jwk)
122
+ verify_nonce!(payload)
123
+ payload
124
+ rescue JSON::ParserError, ArgumentError, JWT::DecodeError => e
125
+ raise CallbackError, e.message
126
+ end
127
+
128
+ def verify_nonce!(payload)
129
+ return unless payload.key?("nonce")
130
+
131
+ expected_nonce = stored_nonce
132
+ return if payload["nonce"] == expected_nonce
133
+
134
+ raise CallbackError, "nonce does not match"
135
+ end
136
+
137
+ def fetch_jwk(expected_kid)
138
+ jwks = fetch_jwks_keys
139
+ matching_key = jwks.find { |key| key["kid"] == expected_kid }
140
+ raise CallbackError, "JWKS key not found: #{expected_kid}" unless matching_key
141
+
142
+ JWT::JWK.import(matching_key)
143
+ rescue JSON::ParserError, SocketError, SystemCallError => e
144
+ raise CallbackError, e.message
145
+ end
146
+
147
+ def fetch_jwks_keys
148
+ uri = URI(JWKS_URL)
149
+ response = Net::HTTP.get_response(uri)
150
+ raise CallbackError, "JWKS fetch failed: #{response.code}" unless response.is_a?(Net::HTTPSuccess)
151
+
152
+ JSON.parse(response.body).fetch("keys", [])
153
+ end
154
+
155
+ def extract_kid(token)
156
+ header_segment = token.split(".").first
157
+ decoded_header = Base64.urlsafe_decode64(pad_base64(header_segment))
158
+ JSON.parse(decoded_header)["kid"]
159
+ end
160
+
161
+ def decode_payload(token, jwk)
162
+ payload, = JWT.decode(
163
+ token,
164
+ jwk.public_key,
165
+ true,
166
+ decode_options
167
+ )
168
+ payload
169
+ end
170
+
171
+ def decode_options
172
+ {
173
+ algorithms: ["RS256"],
174
+ iss: ISSUER,
175
+ verify_iss: true,
176
+ aud: options.client_id,
177
+ verify_aud: true,
178
+ verify_iat: true,
179
+ verify_expiration: true
180
+ }
181
+ end
182
+
183
+ def new_nonce
184
+ session["omniauth.nonce"] = SecureRandom.urlsafe_base64(16)
185
+ end
186
+
187
+ def stored_nonce
188
+ session.delete("omniauth.nonce")
189
+ end
190
+
191
+ def apply_request_authorize_overrides(params)
192
+ options[:authorize_options].each do |key|
193
+ request_value = request.params[key.to_s]
194
+ params[key] = request_value unless blank?(request_value)
195
+ end
196
+ end
197
+
198
+ def token_scope
199
+ access_token.params["scope"] || access_token["scope"]
200
+ end
201
+
202
+ def pad_base64(value)
203
+ value + ("=" * ((4 - (value.length % 4)) % 4))
204
+ end
205
+
206
+ def blank?(value)
207
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
208
+ end
209
+ end
210
+
211
+ # Backward-compatible strategy name for existing callback paths.
212
+ class Slack < Slack2
213
+ option :name, "slack"
214
+ end
215
+ end
216
+ end
217
+
218
+ OmniAuth.config.add_camelization "slack2", "Slack2"
219
+ OmniAuth.config.add_camelization "slack", "Slack"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth/slack2"
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "omniauth/slack2/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "omniauth-slack2"
9
+ spec.version = OmniAuth::Slack2::VERSION
10
+ spec.authors = ["Claudio Poli"]
11
+ spec.email = ["masterkain@gmail.com"]
12
+
13
+ spec.summary = "OmniAuth strategy for Slack OpenID Connect authentication."
14
+ spec.description =
15
+ "OpenID Connect strategy for OmniAuth that authenticates users with Slack and exposes profile metadata."
16
+ spec.homepage = "https://github.com/icoretech/omniauth-slack2"
17
+ spec.license = "MIT"
18
+ spec.required_ruby_version = ">= 3.2"
19
+
20
+ spec.metadata["source_code_uri"] = "https://github.com/icoretech/omniauth-slack2"
21
+ spec.metadata["bug_tracker_uri"] = "https://github.com/icoretech/omniauth-slack2/issues"
22
+ spec.metadata["changelog_uri"] = "https://github.com/icoretech/omniauth-slack2/releases"
23
+ spec.metadata["rubygems_mfa_required"] = "true"
24
+
25
+ spec.files = Dir[
26
+ "lib/**/*.rb",
27
+ "README*",
28
+ "LICENSE*",
29
+ "*.gemspec"
30
+ ]
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "cgi", ">= 0.3.6"
34
+ spec.add_dependency "jwt", ">= 2.9.2"
35
+ spec.add_dependency "omniauth-oauth2", ">= 1.8", "< 2.0"
36
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-slack2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Poli
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: cgi
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.3.6
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.3.6
26
+ - !ruby/object:Gem::Dependency
27
+ name: jwt
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.9.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.9.2
40
+ - !ruby/object:Gem::Dependency
41
+ name: omniauth-oauth2
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '1.8'
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '1.8'
57
+ - - "<"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.0'
60
+ description: OpenID Connect strategy for OmniAuth that authenticates users with Slack
61
+ and exposes profile metadata.
62
+ email:
63
+ - masterkain@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - LICENSE.txt
69
+ - README.md
70
+ - lib/omniauth-slack2.rb
71
+ - lib/omniauth/slack2.rb
72
+ - lib/omniauth/slack2/version.rb
73
+ - lib/omniauth/strategies/slack2.rb
74
+ - omniauth-slack2.gemspec
75
+ homepage: https://github.com/icoretech/omniauth-slack2
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ source_code_uri: https://github.com/icoretech/omniauth-slack2
80
+ bug_tracker_uri: https://github.com/icoretech/omniauth-slack2/issues
81
+ changelog_uri: https://github.com/icoretech/omniauth-slack2/releases
82
+ rubygems_mfa_required: 'true'
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '3.2'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.6.9
98
+ specification_version: 4
99
+ summary: OmniAuth strategy for Slack OpenID Connect authentication.
100
+ test_files: []