omniauth_cobot 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +10 -0
- data/.github/workflows/ruby.yml +24 -0
- data/Gemfile.lock +46 -21
- data/README.md +16 -8
- data/Rakefile +9 -0
- data/lib/omniauth/cobot/version.rb +1 -1
- data/lib/omniauth/strategies/cobot.rb +21 -0
- data/omniauth_cobot.gemspec +2 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/strategy_spec.rb +63 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c91b6d6f983000b2c8f392cb0532aeb6c5dedf0afbfee30cd3b6adf2b4fb15d
|
4
|
+
data.tar.gz: 6280f53cfe29d745051263c61f0f670ddd124ecfe8ef6b57955182f78fa3cd37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f549df07238edc70eaa9912b633be07d1d5bc63ed0a9b7e28f5000e2703d5f7546b47cd7b654d380bbdb8925f74c14bd3db1c518362fdc1f196c172f43279e9
|
7
|
+
data.tar.gz: 3cbf4da8ef6ebc0dd95c01757bc0ae16fb0f3363a516c02d9c441dbb6b216c8aee82e41d98bf988b61ea05a1c90c2e90eff2ccb51eadd323d405ae5edab89480
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- main
|
6
|
+
pull_request:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby: ["2.7", "3.0", "3.1"]
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v3
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
bundler-cache: true
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rake
|
data/Gemfile.lock
CHANGED
@@ -1,40 +1,65 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
omniauth_cobot (0.0
|
5
|
-
omniauth-oauth2 (~> 1.
|
4
|
+
omniauth_cobot (0.2.0)
|
5
|
+
omniauth-oauth2 (~> 1.8.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
faraday (2.6.0)
|
12
|
+
faraday-net_http (>= 2.0, < 3.1)
|
13
|
+
ruby2_keywords (>= 0.0.4)
|
14
|
+
faraday-net_http (3.0.1)
|
15
|
+
hashie (5.0.0)
|
16
|
+
jwt (2.5.0)
|
15
17
|
multi_xml (0.6.0)
|
16
|
-
|
17
|
-
|
18
|
-
faraday (>= 0.8, < 0.16.0)
|
18
|
+
oauth2 (2.0.9)
|
19
|
+
faraday (>= 0.17.3, < 3.0)
|
19
20
|
jwt (>= 1.0, < 3.0)
|
20
|
-
multi_json (~> 1.3)
|
21
21
|
multi_xml (~> 0.5)
|
22
|
-
rack (>= 1.2, <
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
rack (>= 1.2, < 4)
|
23
|
+
snaky_hash (~> 2.0)
|
24
|
+
version_gem (~> 1.1)
|
25
|
+
omniauth (2.1.0)
|
26
|
+
hashie (>= 3.4.6)
|
27
|
+
rack (>= 2.2.3)
|
28
|
+
rack-protection
|
29
|
+
omniauth-oauth2 (1.8.0)
|
30
|
+
oauth2 (>= 1.4, < 3)
|
31
|
+
omniauth (~> 2.0)
|
32
|
+
rack (3.0.0)
|
33
|
+
rack-protection (3.0.2)
|
34
|
+
rack
|
30
35
|
rake (13.0.1)
|
36
|
+
rspec (3.12.0)
|
37
|
+
rspec-core (~> 3.12.0)
|
38
|
+
rspec-expectations (~> 3.12.0)
|
39
|
+
rspec-mocks (~> 3.12.0)
|
40
|
+
rspec-core (3.12.0)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-expectations (3.12.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-mocks (3.12.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-support (3.12.0)
|
49
|
+
ruby2_keywords (0.0.5)
|
50
|
+
snaky_hash (2.0.1)
|
51
|
+
hashie
|
52
|
+
version_gem (~> 1.1, >= 1.1.1)
|
53
|
+
version_gem (1.1.1)
|
31
54
|
|
32
55
|
PLATFORMS
|
33
|
-
|
56
|
+
arm64-darwin-21
|
57
|
+
x86_64-linux
|
34
58
|
|
35
59
|
DEPENDENCIES
|
36
60
|
omniauth_cobot!
|
37
61
|
rake
|
62
|
+
rspec (~> 3.12)
|
38
63
|
|
39
64
|
BUNDLED WITH
|
40
|
-
|
65
|
+
2.3.20
|
data/README.md
CHANGED
@@ -6,13 +6,21 @@ This gem provides an [OmniAuth](https://github.com/intridea/omniauth) strategy f
|
|
6
6
|
|
7
7
|
Add the following as an initializer:
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
```ruby
|
10
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
11
|
+
provider :cobot, '<client_id>', '<client_secret>', scope: 'read write'
|
12
|
+
end
|
13
|
+
```
|
12
14
|
|
13
|
-
|
15
|
+
To authenticate a user against Cobot, send them to `/auth/cobot`.
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
If authenticating in the context of a Cobot space, e.g. if your app is inside an ifram on Cobot, pass the space's subdomain by sending the user to `/auth/cobot/cobot_space_subdomain=<space-sudbomain>`. This ensures users don't have to log in again for their space on Cobot when that space has a custom domain.
|
18
|
+
|
19
|
+
After the user completed the OAuth flow, they are redirected back to `/auth/cobot/callback`, which should be routed to a controller action.
|
20
|
+
|
21
|
+
In the controller action you have access to a variable `request.env['omniauth.auth']` that looks like this:
|
22
|
+
|
23
|
+
- `uid` - the id of the user
|
24
|
+
- `credentials` - `{'token' => '<access token>'}`
|
25
|
+
- `info` - `{'email' => '<user email>', 'picture' => '<url>'}`
|
26
|
+
- `extra` - `{:raw_info => { "id": "<user id>", "email": "<email>", "picture": "<picture url>", "mac_addresses": ["<mac address>"...], "memberships": [{ "space_link": "<https://www.cobot.me/api/spaces/some-space>", "link": "<https://some-space.cobot.me/api/memberships/some-membership>" } ], "admin_of": [ { "space_link": "<https://www.cobot.me/api/spaces/some-space>", "name": "<admin name>" } ] }`
|
data/Rakefile
CHANGED
@@ -9,6 +9,27 @@ module OmniAuth
|
|
9
9
|
:token_url => 'https://www.cobot.me/oauth/access_token'
|
10
10
|
}
|
11
11
|
|
12
|
+
def client
|
13
|
+
::OAuth2::Client.new(
|
14
|
+
options.client_id,
|
15
|
+
options.client_secret,
|
16
|
+
deep_symbolize(
|
17
|
+
options.client_options.merge(
|
18
|
+
authorize_url: space_subdomain_authorize_url
|
19
|
+
)
|
20
|
+
)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def space_subdomain_authorize_url
|
25
|
+
params = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
26
|
+
if (subdomain = params['cobot_space_subdomain'])
|
27
|
+
options.client_options[:authorize_url].sub('www.', "#{subdomain}.")
|
28
|
+
else
|
29
|
+
options.client_options[:authorize_url]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
12
33
|
uid { raw_info['id'] }
|
13
34
|
|
14
35
|
info do
|
data/omniauth_cobot.gemspec
CHANGED
@@ -15,9 +15,10 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.add_dependency 'omniauth-oauth2', '~>1.8.0'
|
16
16
|
|
17
17
|
s.add_development_dependency 'rake'
|
18
|
+
s.add_development_dependency 'rspec', '~>3.12'
|
18
19
|
|
19
20
|
s.files = `git ls-files`.split("\n")
|
20
|
-
|
21
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
21
22
|
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
23
|
s.require_paths = ["lib"]
|
23
24
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth_cobot'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe OmniAuth::Strategies::Cobot do
|
4
|
+
let(:app) do
|
5
|
+
lambda do |_env|
|
6
|
+
[200, {}, ["Hello."]]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
let(:strategy) { Class.new(OmniAuth::Strategies::Cobot) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
OmniAuth.config.test_mode = true
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
OmniAuth.config.test_mode = false
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
it 'takes the cobot_space_sudomain query param and changes the subdomain of the authorize_url' do
|
21
|
+
subject = strategy
|
22
|
+
.new(app, client_options: {authorize_url: 'https://www.cobot.me'})
|
23
|
+
|
24
|
+
subject.call!(
|
25
|
+
{
|
26
|
+
'rack.session' => {},
|
27
|
+
'QUERY_STRING' => 'cobot_space_subdomain=my-space'
|
28
|
+
}
|
29
|
+
)
|
30
|
+
|
31
|
+
expect(subject.client.authorize_url)
|
32
|
+
.to eq('https://my-space.cobot.me')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not change the subdomain of the authorize_url when no cobot_space_subdomain passed' do
|
36
|
+
subject = strategy
|
37
|
+
.new(app, client_options: {authorize_url: 'https://www.cobot.me'})
|
38
|
+
|
39
|
+
subject.call!(
|
40
|
+
{
|
41
|
+
'rack.session' => {}
|
42
|
+
}
|
43
|
+
)
|
44
|
+
|
45
|
+
expect(subject.client.authorize_url)
|
46
|
+
.to eq('https://www.cobot.me')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'does nothing if no authorize_url configured' do
|
50
|
+
subject = strategy
|
51
|
+
.new(app, {})
|
52
|
+
|
53
|
+
subject.call!(
|
54
|
+
{
|
55
|
+
'rack.session' => {}
|
56
|
+
}
|
57
|
+
)
|
58
|
+
|
59
|
+
expect(subject.client.authorize_url)
|
60
|
+
.to eq('https://www.cobot.me/oauth/authorize')
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth_cobot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
@@ -38,12 +38,28 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
41
55
|
description: OmniAuth strategy for Cobot
|
42
56
|
email: alex@cobot.me
|
43
57
|
executables: []
|
44
58
|
extensions: []
|
45
59
|
extra_rdoc_files: []
|
46
60
|
files:
|
61
|
+
- ".github/dependabot.yml"
|
62
|
+
- ".github/workflows/ruby.yml"
|
47
63
|
- ".gitignore"
|
48
64
|
- Gemfile
|
49
65
|
- Gemfile.lock
|
@@ -54,6 +70,8 @@ files:
|
|
54
70
|
- lib/omniauth/strategies/cobot.rb
|
55
71
|
- lib/omniauth_cobot.rb
|
56
72
|
- omniauth_cobot.gemspec
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/strategy_spec.rb
|
57
75
|
homepage: http://github.com/cobot/omniauth_cobot
|
58
76
|
licenses: []
|
59
77
|
metadata: {}
|
@@ -76,4 +94,6 @@ rubygems_version: 3.2.32
|
|
76
94
|
signing_key:
|
77
95
|
specification_version: 4
|
78
96
|
summary: OmniAuth strategy for Cobot
|
79
|
-
test_files:
|
97
|
+
test_files:
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/strategy_spec.rb
|