omniauth-slack-openid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.md +21 -0
- data/README.md +60 -0
- data/lib/omniauth/slack_openid/version.rb +5 -0
- data/lib/omniauth/slack_openid.rb +2 -0
- data/lib/omniauth/strategies/slack_openid.rb +79 -0
- data/lib/omniauth-slack-openid.rb +1 -0
- data/omniauth-slack-openid.gemspec +43 -0
- data/spec/omniauth/strategies/slack_openid_spec.rb +71 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f5fb3e5f96c832e24bbd7dc23c9e4ee0e1f8858a78beebdfdd7b0fe172c3a32e
|
4
|
+
data.tar.gz: ec3f3ae44d759f1a40f34fe5e5a953b1bc120e9c9fd93678834c54f4c4d202ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 132b6519d589788e032f2994fb23663eb0765ec97efc11aa218ea98774aca4a1b6faa776ae4c492062876698ae3e6f3730d4bc3cfc8ecc6c2290719dc1defdbe
|
7
|
+
data.tar.gz: a58d54b112c70ae11395f19a1fca400bee3a5f3ad9a22b2fef67f0b48e50f2f930a77e97e2b4d49bdc9b55d3d374255a1536667b60989e43b4400b5a6cdb11ee
|
data/CHANGELOG.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 amkisko
|
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,60 @@
|
|
1
|
+
# omniauth_slack_openid.rb
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/omniauth-slack-openid.svg)](https://badge.fury.io/rb/omniauth-slack-openid) [![Test Status](https://github.com/amkisko/omniauth_slack_openid.rb/actions/workflows/test.yml/badge.svg)](https://github.com/amkisko/omniauth_slack_openid.rb/actions/workflows/test.yml)
|
4
|
+
|
5
|
+
An OmniAuth strategy for Slack's OAuth2 API.
|
6
|
+
|
7
|
+
Sponsored by [Kisko Labs](https://www.kiskolabs.com).
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
Using Bundler:
|
12
|
+
```sh
|
13
|
+
bundle add omniauth-slack-openid
|
14
|
+
```
|
15
|
+
|
16
|
+
Using RubyGems:
|
17
|
+
```sh
|
18
|
+
gem install omniauth-slack-openid
|
19
|
+
```
|
20
|
+
|
21
|
+
## Gemfile
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'omniauth-slack-openid'
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage with Devise
|
28
|
+
|
29
|
+
Add the following to your `config/initializers/devise.rb`:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
config.omniauth(
|
33
|
+
:slack_openid,
|
34
|
+
ENV.fetch("SLACK_CLIENT_ID"),
|
35
|
+
ENV.fetch("SLACK_CLIENT_SECRET"),
|
36
|
+
{
|
37
|
+
scope: "openid,email,profile",
|
38
|
+
redirect_uri: Rails.env.development? ? "https://localhost:3000/user/auth/slack_openid/callback" : nil,
|
39
|
+
provider_ignores_state: Rails.env.development?
|
40
|
+
}
|
41
|
+
)
|
42
|
+
```
|
43
|
+
|
44
|
+
In order to test the callback in development, try logging in and then manually update URL to use http instead of https.
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/amkisko/omniauth_slack_openid.rb
|
49
|
+
|
50
|
+
## Publishing
|
51
|
+
|
52
|
+
```sh
|
53
|
+
rm omniauth-slack-openid-*.gem
|
54
|
+
gem build omniauth-slack-openid.gemspec
|
55
|
+
gem push omniauth-slack-openid-*.gem
|
56
|
+
```
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class SlackOpenid < OmniAuth::Strategies::OAuth2
|
6
|
+
AUTH_OPTIONS = %i[scope user_scope team team_domain].freeze
|
7
|
+
|
8
|
+
INFO_DATA =
|
9
|
+
Data.define(
|
10
|
+
:user_id,
|
11
|
+
:team_id,
|
12
|
+
:email,
|
13
|
+
:email_verified,
|
14
|
+
:name,
|
15
|
+
:picture,
|
16
|
+
:given_name,
|
17
|
+
:family_name,
|
18
|
+
:locale,
|
19
|
+
:team_name,
|
20
|
+
:team_domain
|
21
|
+
)
|
22
|
+
|
23
|
+
option :name, "slack_openid"
|
24
|
+
option :client_options,
|
25
|
+
{
|
26
|
+
site: "https://slack.com",
|
27
|
+
authorize_url: "/openid/connect/authorize",
|
28
|
+
token_url: "/api/openid.connect.token"
|
29
|
+
}
|
30
|
+
|
31
|
+
option :redirect_uri
|
32
|
+
|
33
|
+
def self.generate_uid(team_id, user_id)
|
34
|
+
"#{team_id}-#{user_id}"
|
35
|
+
end
|
36
|
+
|
37
|
+
uid do
|
38
|
+
self.class.generate_uid(
|
39
|
+
raw_info["https://slack.com/team_id"],
|
40
|
+
raw_info["https://slack.com/user_id"]
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
info do {
|
45
|
+
name: raw_info["name"],
|
46
|
+
email: raw_info["email"],
|
47
|
+
image: raw_info["picture"]
|
48
|
+
} end
|
49
|
+
|
50
|
+
extra do
|
51
|
+
{
|
52
|
+
data:
|
53
|
+
INFO_DATA.new(
|
54
|
+
user_id: raw_info["https://slack.com/user_id"],
|
55
|
+
team_id: raw_info["https://slack.com/team_id"],
|
56
|
+
email: raw_info["email"],
|
57
|
+
email_verified: raw_info["email_verified"],
|
58
|
+
name: raw_info["name"],
|
59
|
+
picture: raw_info["picture"],
|
60
|
+
given_name: raw_info["given_name"],
|
61
|
+
family_name: raw_info["family_name"],
|
62
|
+
locale: raw_info["locale"],
|
63
|
+
team_name: raw_info["https://slack.com/team_name"],
|
64
|
+
team_domain: raw_info["https://slack.com/team_domain"]
|
65
|
+
),
|
66
|
+
raw_info: raw_info
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def callback_url
|
71
|
+
options.redirect_uri || (full_host + script_name + callback_path)
|
72
|
+
end
|
73
|
+
|
74
|
+
def raw_info
|
75
|
+
@raw_info ||= access_token.get("/api/openid.connect.userInfo").parsed
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/slack_openid'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth/slack_openid/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "omniauth-slack-openid"
|
6
|
+
gem.version = OmniAuth::SlackOpenid::VERSION
|
7
|
+
|
8
|
+
repository_url = "https://github.com/amkisko/omniauth-slack-openid.rb"
|
9
|
+
root_files = %w(CHANGELOG.md LICENSE.md README.md)
|
10
|
+
root_files << "#{gem.name}.gemspec"
|
11
|
+
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.platform = Gem::Platform::RUBY
|
15
|
+
|
16
|
+
gem.authors = ["Andrei Makarov"]
|
17
|
+
gem.email = ["andrei@kiskolabs.com"]
|
18
|
+
gem.homepage = repository_url
|
19
|
+
gem.summary = %q{Slack OAuth2 strategy for OmniAuth}
|
20
|
+
gem.description = gem.summary
|
21
|
+
gem.metadata = {
|
22
|
+
"homepage" => repository_url,
|
23
|
+
"source_code_uri" => repository_url,
|
24
|
+
"bug_tracker_uri" => "#{repository_url}/issues",
|
25
|
+
"changelog_uri" => "#{repository_url}/blob/main/CHANGELOG.md",
|
26
|
+
"rubygems_mfa_required" => "true"
|
27
|
+
}
|
28
|
+
|
29
|
+
gem.executables = Dir.glob("bin/*").map{ |f| File.basename(f) }
|
30
|
+
gem.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + root_files
|
31
|
+
gem.test_files = Dir.glob("spec/**/*_spec.rb")
|
32
|
+
|
33
|
+
gem.required_ruby_version = ">= 1.9.3"
|
34
|
+
gem.require_paths = ["lib"]
|
35
|
+
|
36
|
+
gem.add_runtime_dependency 'omniauth', '~> 2'
|
37
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1'
|
38
|
+
|
39
|
+
gem.add_development_dependency 'bundler', '~> 2'
|
40
|
+
gem.add_development_dependency 'rake', '~> 13'
|
41
|
+
gem.add_development_dependency 'pry-byebug'
|
42
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
43
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::SlackOpenid do
|
4
|
+
let(:user_name) { 'brent' }
|
5
|
+
let(:user_email) { 'bront@slack-corp.com' }
|
6
|
+
let(:raw_info) {
|
7
|
+
{
|
8
|
+
"ok" => true,
|
9
|
+
"sub" => "U0R7JM",
|
10
|
+
"https://slack.com/user_id" => "U0R7JM",
|
11
|
+
"https://slack.com/team_id" => "T0R7GR",
|
12
|
+
"email" => user_email,
|
13
|
+
"email_verified" => true,
|
14
|
+
"date_email_verified" => 1622128723,
|
15
|
+
"name" => user_name,
|
16
|
+
"picture" => "https://secure.gravatar.com/....png",
|
17
|
+
"given_name" => "Bront",
|
18
|
+
"family_name" => "Labradoodle",
|
19
|
+
"locale" => "en-US",
|
20
|
+
"https://slack.com/team_name" => "kraneflannel",
|
21
|
+
"https://slack.com/team_domain" => "kraneflannel",
|
22
|
+
"https://slack.com/user_image_24" => "...",
|
23
|
+
"https://slack.com/user_image_32" => "...",
|
24
|
+
"https://slack.com/user_image_48" => "...",
|
25
|
+
"https://slack.com/user_image_72" => "...",
|
26
|
+
"https://slack.com/user_image_192" => "...",
|
27
|
+
"https://slack.com/user_image_512" => "...",
|
28
|
+
"https://slack.com/team_image_34" => "...",
|
29
|
+
"https://slack.com/team_image_44" => "...",
|
30
|
+
"https://slack.com/team_image_68" => "...",
|
31
|
+
"https://slack.com/team_image_88" => "...",
|
32
|
+
"https://slack.com/team_image_102" => "...",
|
33
|
+
"https://slack.com/team_image_132" => "...",
|
34
|
+
"https://slack.com/team_image_230" => "...",
|
35
|
+
"https://slack.com/team_image_default" => true
|
36
|
+
}
|
37
|
+
}
|
38
|
+
let(:dummy_rack_app) { [200, {}, ['dummy']] }
|
39
|
+
let(:options) { {} }
|
40
|
+
|
41
|
+
subject(:strategy) { OmniAuth::Strategies::SlackOpenid.new(dummy_rack_app, options) }
|
42
|
+
|
43
|
+
describe 'options' do
|
44
|
+
subject { strategy.options }
|
45
|
+
|
46
|
+
it { expect(subject.client_options.site).to eq('https://slack.com') }
|
47
|
+
it { expect(subject.client_options.authorize_url).to eq('/openid/connect/authorize') }
|
48
|
+
it { expect(subject.client_options.token_url).to eq('/api/openid.connect.token') }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#info' do
|
52
|
+
before do
|
53
|
+
allow(strategy).to receive(:raw_info) { raw_info }
|
54
|
+
end
|
55
|
+
|
56
|
+
subject { strategy.info }
|
57
|
+
|
58
|
+
it { expect(subject[:name]).to eq(user_name) }
|
59
|
+
it { expect(subject[:email]).to eq(user_email) }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#uid' do
|
63
|
+
before do
|
64
|
+
allow(strategy).to receive(:raw_info) { raw_info }
|
65
|
+
end
|
66
|
+
|
67
|
+
subject { strategy.uid }
|
68
|
+
|
69
|
+
it { expect(subject).to eq('T0R7GR-U0R7JM') }
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-slack-openid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrei Makarov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-28 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: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
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'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
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: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3'
|
97
|
+
description: Slack OAuth2 strategy for OmniAuth
|
98
|
+
email:
|
99
|
+
- andrei@kiskolabs.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CHANGELOG.md
|
105
|
+
- LICENSE.md
|
106
|
+
- README.md
|
107
|
+
- lib/omniauth-slack-openid.rb
|
108
|
+
- lib/omniauth/slack_openid.rb
|
109
|
+
- lib/omniauth/slack_openid/version.rb
|
110
|
+
- lib/omniauth/strategies/slack_openid.rb
|
111
|
+
- omniauth-slack-openid.gemspec
|
112
|
+
- spec/omniauth/strategies/slack_openid_spec.rb
|
113
|
+
homepage: https://github.com/amkisko/omniauth-slack-openid.rb
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata:
|
117
|
+
homepage: https://github.com/amkisko/omniauth-slack-openid.rb
|
118
|
+
source_code_uri: https://github.com/amkisko/omniauth-slack-openid.rb
|
119
|
+
bug_tracker_uri: https://github.com/amkisko/omniauth-slack-openid.rb/issues
|
120
|
+
changelog_uri: https://github.com/amkisko/omniauth-slack-openid.rb/blob/main/CHANGELOG.md
|
121
|
+
rubygems_mfa_required: 'true'
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.9.3
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubygems_version: 3.4.19
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Slack OAuth2 strategy for OmniAuth
|
141
|
+
test_files:
|
142
|
+
- spec/omniauth/strategies/slack_openid_spec.rb
|