omniauth-slack_signin 0.1.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 +7 -0
- data/.gitignore +82 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +8 -0
- data/lib/omniauth-slack_signin.rb +2 -0
- data/lib/omniauth-slack_signin/version.rb +6 -0
- data/lib/omniauth/strategies/slack_signin.rb +69 -0
- data/omniauth-slack_signin.gemspec +25 -0
- data/test/helper.rb +56 -0
- data/test/support/shared_examples.rb +85 -0
- data/test/test.rb +100 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eeb5f4995a2c816d515a65d12a4cef6200db8a23
|
4
|
+
data.tar.gz: a2bf12ef2222e922cb36962e376874e2123ecc9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed31d4c046b02548626fa026a735cdd4dac16ddac578829f5cee7455dd56bc075a973e42e5b3694934368a89aa475ebeb8509f4d11605f3881e88e62b124888e
|
7
|
+
data.tar.gz: 328609e8a9fefac2adae32850a628a978abce1864dbb59d72f9364cdb908e0363ade451c2165ba19d1790804258ed6247cf0887d450c424a350891f8f3ec47e4
|
data/.gitignore
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Created by https://www.gitignore.io/api/osx,ruby
|
2
|
+
|
3
|
+
### OSX ###
|
4
|
+
*.DS_Store
|
5
|
+
.AppleDouble
|
6
|
+
.LSOverride
|
7
|
+
|
8
|
+
# Icon must end with two \r
|
9
|
+
Icon
|
10
|
+
|
11
|
+
|
12
|
+
# Thumbnails
|
13
|
+
._*
|
14
|
+
|
15
|
+
# Files that might appear in the root of a volume
|
16
|
+
.DocumentRevisions-V100
|
17
|
+
.fseventsd
|
18
|
+
.Spotlight-V100
|
19
|
+
.TemporaryItems
|
20
|
+
.Trashes
|
21
|
+
.VolumeIcon.icns
|
22
|
+
.com.apple.timemachine.donotpresent
|
23
|
+
|
24
|
+
# Directories potentially created on remote AFP share
|
25
|
+
.AppleDB
|
26
|
+
.AppleDesktop
|
27
|
+
Network Trash Folder
|
28
|
+
Temporary Items
|
29
|
+
.apdisk
|
30
|
+
|
31
|
+
|
32
|
+
### Ruby ###
|
33
|
+
*.gem
|
34
|
+
*.rbc
|
35
|
+
/.config
|
36
|
+
/coverage/
|
37
|
+
/InstalledFiles
|
38
|
+
/pkg/
|
39
|
+
/spec/reports/
|
40
|
+
/spec/examples.txt
|
41
|
+
/test/tmp/
|
42
|
+
/test/version_tmp/
|
43
|
+
/tmp/
|
44
|
+
|
45
|
+
# Used by dotenv library to load environment variables.
|
46
|
+
# .env
|
47
|
+
|
48
|
+
## Specific to RubyMotion:
|
49
|
+
.dat*
|
50
|
+
.repl_history
|
51
|
+
build/
|
52
|
+
*.bridgesupport
|
53
|
+
build-iPhoneOS/
|
54
|
+
build-iPhoneSimulator/
|
55
|
+
|
56
|
+
## Specific to RubyMotion (use of CocoaPods):
|
57
|
+
#
|
58
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
59
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
60
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
61
|
+
#
|
62
|
+
# vendor/Pods/
|
63
|
+
|
64
|
+
## Documentation cache and generated files:
|
65
|
+
/.yardoc/
|
66
|
+
/_yardoc/
|
67
|
+
/doc/
|
68
|
+
/rdoc/
|
69
|
+
|
70
|
+
## Environment normalization:
|
71
|
+
/.bundle/
|
72
|
+
/vendor/bundle
|
73
|
+
/lib/bundler/man/
|
74
|
+
|
75
|
+
# for a library or gem, you might want to ignore these files since the code is
|
76
|
+
# intended to run in multiple environments; otherwise, check them in:
|
77
|
+
# Gemfile.lock
|
78
|
+
# .ruby-version
|
79
|
+
# .ruby-gemset
|
80
|
+
|
81
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
82
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-slack_signin (0.1.0)
|
5
|
+
omniauth-oauth2 (~> 1.3.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
faraday (0.9.2)
|
11
|
+
multipart-post (>= 1.2, < 3)
|
12
|
+
hashie (3.4.4)
|
13
|
+
jwt (1.5.1)
|
14
|
+
metaclass (0.0.4)
|
15
|
+
minitest (5.8.4)
|
16
|
+
mocha (1.1.0)
|
17
|
+
metaclass (~> 0.0.1)
|
18
|
+
multi_json (1.12.0)
|
19
|
+
multi_xml (0.5.5)
|
20
|
+
multipart-post (2.0.0)
|
21
|
+
oauth2 (1.1.0)
|
22
|
+
faraday (>= 0.8, < 0.10)
|
23
|
+
jwt (~> 1.0, < 1.5.2)
|
24
|
+
multi_json (~> 1.3)
|
25
|
+
multi_xml (~> 0.5)
|
26
|
+
rack (>= 1.2, < 3)
|
27
|
+
omniauth (1.3.1)
|
28
|
+
hashie (>= 1.2, < 4)
|
29
|
+
rack (>= 1.0, < 3)
|
30
|
+
omniauth-oauth2 (1.3.1)
|
31
|
+
oauth2 (~> 1.0)
|
32
|
+
omniauth (~> 1.2)
|
33
|
+
rack (1.6.4)
|
34
|
+
rake (10.5.0)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.3)
|
41
|
+
minitest
|
42
|
+
mocha
|
43
|
+
omniauth-slack_signin!
|
44
|
+
rake
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.12.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 shia
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Omniauth::SlackSignin
|
2
|
+
|
3
|
+
This Gem contains the Signin with Slack strategy for OmniAuth.
|
4
|
+
|
5
|
+
We already have [good strategy for slack](https://github.com/kmrshntr/omniauth-slack), however, this gem is not work well.
|
6
|
+
|
7
|
+
In addition, if we want to implement that, we need to be blind. Meaning to say, we should assume `identify.basic` scope is applied or not by returned params. One more thing. Maybe some clever developer handle this problem in the future, but I can't bear to retrieve user name with `auth.info.nickname.name` with `identify` scope. lol.
|
8
|
+
|
9
|
+
so this gem only support about Sign-In feature with Slack. If you want another api, then just go [origin gem](https://github.com/kmrshntr/omniauth-slack) and use it. It is not hard as you know, isn't it?
|
10
|
+
|
11
|
+
## How to use
|
12
|
+
|
13
|
+
First start by adding this gem to your Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'omniauth-slack_signin', github: 'riseshia/omniauth-slack_signin'
|
17
|
+
```
|
18
|
+
|
19
|
+
Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
23
|
+
provider :slack_signin, "AUTH_KEY", "AUTH_SECRET", scope: "identity:basic"
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Replace `"AUTH_KEY"` and `"AUTH_SECRET"` with the appropriate values you obtained from [weirdx](not yet).
|
28
|
+
|
29
|
+
If you are using [Devise](https://github.com/plataformatec/devise) then it will look like this:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Devise.setup do |config|
|
33
|
+
# ...
|
34
|
+
config.omniauth :slack, ENV["AUTH_KEY"], ENV["AUTH_SECRET"], scope: 'identity:basic'
|
35
|
+
# ...
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## About API
|
40
|
+
|
41
|
+
Follow this [link](https://api.slack.com/methods/users.identity).
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "omniauth/strategies/oauth2"
|
2
|
+
require "uri"
|
3
|
+
require "rack/utils"
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class SlackSignin < OmniAuth::Strategies::OAuth2
|
8
|
+
option :name, "slack_signin"
|
9
|
+
|
10
|
+
option :authorize_options, [:scope, :team]
|
11
|
+
|
12
|
+
option :client_options, {
|
13
|
+
site: "https://slack.com",
|
14
|
+
token_url: "/api/oauth.access"
|
15
|
+
}
|
16
|
+
|
17
|
+
option :auth_token_params, {
|
18
|
+
mode: :query,
|
19
|
+
param_name: "token"
|
20
|
+
}
|
21
|
+
|
22
|
+
uid { raw_info["user"]["id"] }
|
23
|
+
|
24
|
+
info do
|
25
|
+
{
|
26
|
+
team: team_info,
|
27
|
+
user: user_info
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def user_info
|
32
|
+
return nil if raw_info["user"].nil?
|
33
|
+
{
|
34
|
+
id: raw_info["user"]["id"],
|
35
|
+
name: raw_info["user"]["name"],
|
36
|
+
email: raw_info["user"]["email"],
|
37
|
+
image_24: raw_info["user"]["image_24"],
|
38
|
+
image_32: raw_info["user"]["image_32"],
|
39
|
+
image_48: raw_info["user"]["image_48"],
|
40
|
+
image_72: raw_info["user"]["image_72"],
|
41
|
+
image_192: raw_info["user"]["image_192"],
|
42
|
+
image_512: raw_info["user"]["image_512"]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def team_info
|
47
|
+
return nil if raw_info["user"].nil?
|
48
|
+
{
|
49
|
+
id: raw_info["team"]["id"],
|
50
|
+
name: raw_info["team"]["name"]
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def raw_info
|
55
|
+
@raw_info ||= access_token.get("/api/users.identity").parsed
|
56
|
+
end
|
57
|
+
|
58
|
+
def authorize_params
|
59
|
+
super.tap do |params|
|
60
|
+
%w[scope team].each do |v|
|
61
|
+
if request.params[v]
|
62
|
+
params[v.to_sym] = request.params[v]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/omniauth-slack_signin/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'omniauth-slack_signin'
|
6
|
+
spec.version = Omniauth::SlackSignin::VERSION
|
7
|
+
spec.authors = ['Shia']
|
8
|
+
spec.email = ['rise.shia@gmail.com']
|
9
|
+
spec.description = 'OmniAuth strategy for Signin with Slack'
|
10
|
+
spec.summary = 'OmniAuth strategy for Signin with Slack'
|
11
|
+
spec.homepage = 'https://github.com/riseshia/omniauth-slack_signin.git'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.3.1'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'minitest'
|
24
|
+
spec.add_development_dependency 'mocha'
|
25
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "mocha/setup"
|
4
|
+
require "omniauth/strategies/slack_signin"
|
5
|
+
|
6
|
+
OmniAuth.config.test_mode = true
|
7
|
+
|
8
|
+
module BlockTestHelper
|
9
|
+
def test(name, &blk)
|
10
|
+
method_name = "test_#{name.gsub(/\s+/, "_")}"
|
11
|
+
fail "Method already defined: #{method_name}" if instance_methods.include?(method_name.to_sym)
|
12
|
+
define_method method_name, &blk
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module CustomAssertions
|
17
|
+
def assert_has_key(key, hash, msg = nil)
|
18
|
+
msg = message(msg) { "Expected #{hash.inspect} to have key #{key.inspect}" }
|
19
|
+
assert hash.has_key?(key), msg
|
20
|
+
end
|
21
|
+
|
22
|
+
def refute_has_key(key, hash, msg = nil)
|
23
|
+
msg = message(msg) { "Expected #{hash.inspect} not to have key #{key.inspect}" }
|
24
|
+
refute hash.has_key?(key), msg
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class TestCase < Minitest::Test
|
29
|
+
extend BlockTestHelper
|
30
|
+
include CustomAssertions
|
31
|
+
end
|
32
|
+
|
33
|
+
class StrategyTestCase < TestCase
|
34
|
+
def setup
|
35
|
+
@request = stub("Request")
|
36
|
+
@request.stubs(:params).returns({})
|
37
|
+
@request.stubs(:cookies).returns({})
|
38
|
+
@request.stubs(:env).returns({})
|
39
|
+
@request.stubs(:scheme).returns({})
|
40
|
+
@request.stubs(:ssl?).returns(false)
|
41
|
+
|
42
|
+
@client_id = "cid"
|
43
|
+
@client_secret = "1fndn123nadfa"
|
44
|
+
end
|
45
|
+
|
46
|
+
def strategy
|
47
|
+
@strategy ||= begin
|
48
|
+
args = [@client_id, @client_secret, @options].compact
|
49
|
+
OmniAuth::Strategies::SlackSignin.new(nil, *args).tap do |strategy|
|
50
|
+
strategy.stubs(:request).returns(@request)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Dir[File.expand_path("../support/**/*", __FILE__)].each &method(:require)
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# NOTE it would be useful if this lived in omniauth-oauth2 eventually
|
2
|
+
module OAuth2StrategyTests
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
include ClientTests
|
6
|
+
include AuthorizeParamsTests
|
7
|
+
include CSRFAuthorizeParamsTests
|
8
|
+
include TokenParamsTests
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClientTests
|
13
|
+
extend BlockTestHelper
|
14
|
+
|
15
|
+
test "should be initialized with symbolized client_options" do
|
16
|
+
@options = { client_options: { "authorize_url" => "https://example.com" } }
|
17
|
+
assert_equal "https://example.com", strategy.client.options[:authorize_url]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module AuthorizeParamsTests
|
22
|
+
extend BlockTestHelper
|
23
|
+
|
24
|
+
test "should include any authorize params passed in the :authorize_params option" do
|
25
|
+
@options = { authorize_params: { foo: "bar", baz: "zip" } }
|
26
|
+
assert_equal "bar", strategy.authorize_params["foo"]
|
27
|
+
assert_equal "zip", strategy.authorize_params["baz"]
|
28
|
+
end
|
29
|
+
|
30
|
+
test "should include top-level options that are marked as :authorize_options" do
|
31
|
+
@options = { authorize_options: [:scope, :foo], scope: "bar", foo: "baz" }
|
32
|
+
assert_equal "bar", strategy.authorize_params["scope"]
|
33
|
+
assert_equal "baz", strategy.authorize_params["foo"]
|
34
|
+
end
|
35
|
+
|
36
|
+
test "should exclude top-level options that are not passed" do
|
37
|
+
@options = { authorize_options: [:bar] }
|
38
|
+
refute_has_key :bar, strategy.authorize_params
|
39
|
+
refute_has_key "bar", strategy.authorize_params
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module CSRFAuthorizeParamsTests
|
44
|
+
extend BlockTestHelper
|
45
|
+
|
46
|
+
test "should store random state in the session when none is present in authorize or request params" do
|
47
|
+
assert_includes strategy.authorize_params.keys, "state"
|
48
|
+
refute_empty strategy.authorize_params["state"]
|
49
|
+
refute_empty strategy.session["omniauth.state"]
|
50
|
+
assert_equal strategy.authorize_params["state"], strategy.session["omniauth.state"]
|
51
|
+
end
|
52
|
+
|
53
|
+
test "should not store state in the session when present in authorize params vs. a random one" do
|
54
|
+
@options = { authorize_params: { state: "bar" } }
|
55
|
+
refute_empty strategy.authorize_params["state"]
|
56
|
+
refute_equal "bar", strategy.authorize_params[:state]
|
57
|
+
refute_empty strategy.session["omniauth.state"]
|
58
|
+
refute_equal "bar", strategy.session["omniauth.state"]
|
59
|
+
end
|
60
|
+
|
61
|
+
test "should not store state in the session when present in request params vs. a random one" do
|
62
|
+
@request.stubs(:params).returns("state" => "foo")
|
63
|
+
refute_empty strategy.authorize_params["state"]
|
64
|
+
refute_equal "foo", strategy.authorize_params[:state]
|
65
|
+
refute_empty strategy.session["omniauth.state"]
|
66
|
+
refute_equal "foo", strategy.session["omniauth.state"]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module TokenParamsTests
|
71
|
+
extend BlockTestHelper
|
72
|
+
|
73
|
+
test "should include any authorize params passed in the :token_params option" do
|
74
|
+
@options = { token_params: { foo: "bar", baz: "zip" } }
|
75
|
+
assert_equal "bar", strategy.token_params["foo"]
|
76
|
+
assert_equal "zip", strategy.token_params["baz"]
|
77
|
+
end
|
78
|
+
|
79
|
+
test "should include top-level options that are marked as :token_options" do
|
80
|
+
@options = { token_options: [:scope, :foo], scope: "bar", foo: "baz" }
|
81
|
+
assert_equal "bar", strategy.token_params["scope"]
|
82
|
+
assert_equal "baz", strategy.token_params["foo"]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "omniauth-slack_signin"
|
3
|
+
|
4
|
+
class StrategyTest < StrategyTestCase
|
5
|
+
include OAuth2StrategyTests
|
6
|
+
end
|
7
|
+
|
8
|
+
class ClientTest < StrategyTestCase
|
9
|
+
test "has correct Slack site" do
|
10
|
+
assert_equal "https://slack.com", strategy.client.site
|
11
|
+
end
|
12
|
+
|
13
|
+
test "has correct authorize url" do
|
14
|
+
assert_equal "/oauth/authorize", strategy.client.options[:authorize_url]
|
15
|
+
end
|
16
|
+
|
17
|
+
test "has correct token url" do
|
18
|
+
assert_equal "/api/oauth.access", strategy.client.options[:token_url]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class CallbackUrlTest < StrategyTestCase
|
23
|
+
test "returns the default callback url" do
|
24
|
+
url_base = "http://auth.request.com"
|
25
|
+
@request.stubs(:url).returns("#{url_base}/some/page")
|
26
|
+
strategy.stubs(:script_name).returns("") # as not to depend on Rack env
|
27
|
+
assert_equal "#{url_base}/auth/slack_signin/callback", strategy.callback_url
|
28
|
+
end
|
29
|
+
|
30
|
+
test "returns path from callback_path option" do
|
31
|
+
@options = { :callback_path => "/auth/slack_signin/done"}
|
32
|
+
url_base = "http://auth.request.com"
|
33
|
+
@request.stubs(:url).returns("#{url_base}/page/path")
|
34
|
+
strategy.stubs(:script_name).returns("") # as not to depend on Rack env
|
35
|
+
assert_equal "#{url_base}/auth/slack_signin/done", strategy.callback_url
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class UidTest < StrategyTestCase
|
40
|
+
def setup
|
41
|
+
super
|
42
|
+
strategy.stubs(:raw_info).returns("user" => { "id" => "misha" })
|
43
|
+
end
|
44
|
+
|
45
|
+
test "returns the user ID from raw_info" do
|
46
|
+
assert_equal "misha", strategy.uid
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class CredentialsTest < StrategyTestCase
|
51
|
+
def setup
|
52
|
+
super
|
53
|
+
@access_token = stub("OAuth2::AccessToken")
|
54
|
+
@access_token.stubs(:token)
|
55
|
+
@access_token.stubs(:expires?)
|
56
|
+
@access_token.stubs(:expires_at)
|
57
|
+
@access_token.stubs(:refresh_token)
|
58
|
+
strategy.stubs(:access_token).returns(@access_token)
|
59
|
+
end
|
60
|
+
|
61
|
+
test "returns a Hash" do
|
62
|
+
assert_kind_of Hash, strategy.credentials
|
63
|
+
end
|
64
|
+
|
65
|
+
test "returns the token" do
|
66
|
+
@access_token.stubs(:token).returns("tooooken")
|
67
|
+
assert_equal "tooooken", strategy.credentials["token"]
|
68
|
+
end
|
69
|
+
|
70
|
+
test "returns the expiry status" do
|
71
|
+
@access_token.stubs(:expires?).returns(true)
|
72
|
+
assert strategy.credentials["expires"]
|
73
|
+
|
74
|
+
@access_token.stubs(:expires?).returns(false)
|
75
|
+
refute strategy.credentials["expires"]
|
76
|
+
end
|
77
|
+
|
78
|
+
test "returns the refresh token and expiry time when expiring" do
|
79
|
+
ten_mins_from_now = (Time.now + 600).to_i
|
80
|
+
@access_token.stubs(:expires?).returns(true)
|
81
|
+
@access_token.stubs(:refresh_token).returns("re_toooooken")
|
82
|
+
@access_token.stubs(:expires_at).returns(ten_mins_from_now)
|
83
|
+
assert_equal "re_toooooken", strategy.credentials["refresh_token"]
|
84
|
+
assert_equal ten_mins_from_now, strategy.credentials["expires_at"]
|
85
|
+
end
|
86
|
+
|
87
|
+
test "does not return the refresh token when test is nil and expiring" do
|
88
|
+
@access_token.stubs(:expires?).returns(true)
|
89
|
+
@access_token.stubs(:refresh_token).returns(nil)
|
90
|
+
assert_nil strategy.credentials["refresh_token"]
|
91
|
+
refute_has_key "refresh_token", strategy.credentials
|
92
|
+
end
|
93
|
+
|
94
|
+
test "does not return the refresh token when not expiring" do
|
95
|
+
@access_token.stubs(:expires?).returns(false)
|
96
|
+
@access_token.stubs(:refresh_token).returns("XXX")
|
97
|
+
assert_nil strategy.credentials["refresh_token"]
|
98
|
+
refute_has_key "refresh_token", strategy.credentials
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-slack_signin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shia
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth-oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.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.3.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
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: mocha
|
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
|
+
description: OmniAuth strategy for Signin with Slack
|
84
|
+
email:
|
85
|
+
- rise.shia@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/omniauth-slack_signin.rb
|
97
|
+
- lib/omniauth-slack_signin/version.rb
|
98
|
+
- lib/omniauth/strategies/slack_signin.rb
|
99
|
+
- omniauth-slack_signin.gemspec
|
100
|
+
- test/helper.rb
|
101
|
+
- test/support/shared_examples.rb
|
102
|
+
- test/test.rb
|
103
|
+
homepage: https://github.com/riseshia/omniauth-slack_signin.git
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: OmniAuth strategy for Signin with Slack
|
127
|
+
test_files:
|
128
|
+
- test/helper.rb
|
129
|
+
- test/support/shared_examples.rb
|
130
|
+
- test/test.rb
|