omniauth_cobot 0.1.0 → 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 +4 -4
- data/.github/dependabot.yml +10 -0
- data/.github/workflows/ruby.yml +23 -0
- data/.github/workflows/test.yml +25 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +13 -0
- data/CHANGES.md +8 -0
- data/Gemfile +9 -1
- data/README.md +23 -8
- data/Rakefile +14 -0
- data/lib/omniauth/cobot/version.rb +3 -1
- data/lib/omniauth/strategies/cobot.rb +27 -4
- data/lib/omniauth_cobot.rb +2 -0
- data/omniauth_cobot.gemspec +14 -13
- data/spec/omni_auth/strategies/cobot_spec.rb +63 -0
- data/spec/spec_helper.rb +3 -0
- metadata +18 -25
- data/Gemfile.lock +0 -40
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5695363dcc7584d437846dd02f9a110f125071d47b1ad63d8443d1c321b81e74
|
|
4
|
+
data.tar.gz: d4f5b08566889f9492f4b19f7445560d373723d4b9d893e21e04ee1277b35c6d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41f36efe8d264df83f3e4ef41c3d9fe7d84de120448afffa2fd72124a03bf51db9260a8c83af6ef73d52c300ad29c0fa4a507db70c00b757918d9da33490be87
|
|
7
|
+
data.tar.gz: c0f8189ba29bfa270a5a1088a28fdb6532044620d88cd9cfe7ccd89d8188662eed3207360ac3a3ba0907b74ef1a9ba71fffefdef354deb5f8607c7b06b33c2e9
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Push gem
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
jobs:
|
|
8
|
+
release:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
contents: write
|
|
12
|
+
id-token: write
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v5
|
|
15
|
+
with:
|
|
16
|
+
persist-credentials: false
|
|
17
|
+
- name: Set up Ruby
|
|
18
|
+
uses: ruby/setup-ruby@v1
|
|
19
|
+
with:
|
|
20
|
+
bundler-cache: true
|
|
21
|
+
ruby-version: ruby
|
|
22
|
+
- name: Release gem
|
|
23
|
+
uses: rubygems/release-gem@v1
|
|
@@ -0,0 +1,25 @@
|
|
|
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: ["4.0", "3.4", "3.3"]
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v5
|
|
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
|
|
25
|
+
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/CHANGES.md
ADDED
data/Gemfile
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'http://rubygems.org'
|
|
2
4
|
|
|
3
5
|
# Specify your gem's dependencies in omniauth_cobot.gemspec
|
|
4
6
|
gemspec
|
|
7
|
+
|
|
8
|
+
gem 'rake'
|
|
9
|
+
gem 'rspec', '~>3.12'
|
|
10
|
+
gem 'rubocop'
|
|
11
|
+
gem 'rubocop-rake'
|
|
12
|
+
gem 'rubocop-rspec'
|
data/README.md
CHANGED
|
@@ -4,15 +4,30 @@ This gem provides an [OmniAuth](https://github.com/intridea/omniauth) strategy f
|
|
|
4
4
|
|
|
5
5
|
### Rails
|
|
6
6
|
|
|
7
|
+
Add the following to your Gemfile:
|
|
8
|
+
|
|
9
|
+
````ruby
|
|
10
|
+
gem 'omniauth_cobot'
|
|
11
|
+
gem 'omniauth-rails_csrf_protection', '~>1.0.0'
|
|
12
|
+
``
|
|
13
|
+
|
|
7
14
|
Add the following as an initializer:
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
```ruby
|
|
17
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
18
|
+
provider :cobot, '<client_id>', '<client_secret>', scope: 'read write'
|
|
19
|
+
end
|
|
20
|
+
````
|
|
21
|
+
|
|
22
|
+
To authenticate a user against Cobot, send them to `/auth/cobot`.
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
After the user completed the OAuth flow, they are redirected back to `/auth/cobot/callback`, which should be routed to a controller action.
|
|
12
27
|
|
|
13
|
-
|
|
28
|
+
In the controller action you have access to a variable `request.env['omniauth.auth']` that looks like this:
|
|
14
29
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
30
|
+
- `uid` - the id of the user
|
|
31
|
+
- `credentials` - `{'token' => '<access token>'}`
|
|
32
|
+
- `info` - `{'email' => '<user email>', 'picture' => '<url>'}`
|
|
33
|
+
- `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
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'bundler'
|
|
2
4
|
Bundler::GemHelper.install_tasks
|
|
5
|
+
|
|
6
|
+
require 'rspec/core/rake_task'
|
|
7
|
+
require 'rubocop/rake_task'
|
|
8
|
+
|
|
9
|
+
task default: %i[spec rubocop]
|
|
10
|
+
|
|
11
|
+
desc 'Run the specs.'
|
|
12
|
+
RSpec::Core::RakeTask.new do |t|
|
|
13
|
+
t.pattern = 'spec/**/*_spec.rb'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
@@ -1,14 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'omniauth/strategies/oauth2'
|
|
2
4
|
|
|
3
5
|
module OmniAuth
|
|
4
6
|
module Strategies
|
|
5
7
|
class Cobot < OmniAuth::Strategies::OAuth2
|
|
6
8
|
option :client_options, {
|
|
7
|
-
:
|
|
8
|
-
:
|
|
9
|
-
:
|
|
9
|
+
site: 'https://www.cobot.me',
|
|
10
|
+
authorize_url: 'https://www.cobot.me/oauth/authorize',
|
|
11
|
+
token_url: 'https://www.cobot.me/oauth/access_token'
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
def client
|
|
15
|
+
::OAuth2::Client.new(
|
|
16
|
+
options.client_id,
|
|
17
|
+
options.client_secret,
|
|
18
|
+
deep_symbolize(
|
|
19
|
+
options.client_options.merge(
|
|
20
|
+
authorize_url: space_subdomain_authorize_url
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def space_subdomain_authorize_url
|
|
27
|
+
params = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
|
28
|
+
if (subdomain = params['cobot_space_subdomain'])
|
|
29
|
+
options.client_options[:authorize_url].sub('www.', "#{subdomain}.")
|
|
30
|
+
else
|
|
31
|
+
options.client_options[:authorize_url]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
12
35
|
uid { raw_info['id'] }
|
|
13
36
|
|
|
14
37
|
info do
|
|
@@ -19,7 +42,7 @@ module OmniAuth
|
|
|
19
42
|
end
|
|
20
43
|
|
|
21
44
|
extra do
|
|
22
|
-
{:raw_info
|
|
45
|
+
{ raw_info: raw_info }
|
|
23
46
|
end
|
|
24
47
|
|
|
25
48
|
def raw_info
|
data/lib/omniauth_cobot.rb
CHANGED
data/omniauth_cobot.gemspec
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
|
4
|
+
require 'omniauth/cobot/version'
|
|
4
5
|
|
|
5
6
|
Gem::Specification.new do |s|
|
|
6
|
-
s.name =
|
|
7
|
-
s.summary =
|
|
8
|
-
s.email =
|
|
9
|
-
s.homepage =
|
|
10
|
-
s.description =
|
|
11
|
-
s.authors = [
|
|
7
|
+
s.name = 'omniauth_cobot'
|
|
8
|
+
s.summary = 'OmniAuth strategy for Cobot'
|
|
9
|
+
s.email = 'alex@cobot.me'
|
|
10
|
+
s.homepage = 'http://github.com/cobot/omniauth_cobot'
|
|
11
|
+
s.description = 'OmniAuth strategy for Cobot'
|
|
12
|
+
s.authors = ['Alexander Lang']
|
|
12
13
|
s.version = OmniAuth::Cobot::VERSION
|
|
13
14
|
s.platform = Gem::Platform::RUBY
|
|
14
15
|
|
|
15
|
-
s.
|
|
16
|
+
s.required_ruby_version = ['>=3.2', '<5']
|
|
16
17
|
|
|
17
|
-
s.
|
|
18
|
+
s.add_dependency 'omniauth-oauth2', '~>1.8'
|
|
18
19
|
|
|
19
20
|
s.files = `git ls-files`.split("\n")
|
|
20
|
-
# s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
21
|
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
22
|
-
s.require_paths = [
|
|
22
|
+
s.require_paths = ['lib']
|
|
23
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
23
24
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe OmniAuth::Strategies::Cobot do
|
|
6
|
+
let(:app) do
|
|
7
|
+
lambda do |_env|
|
|
8
|
+
[200, {}, ['Hello.']]
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
let(:strategy) { Class.new(described_class) }
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
OmniAuth.config.test_mode = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
after do
|
|
18
|
+
OmniAuth.config.test_mode = false
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'takes the cobot_space_sudomain query param and changes the subdomain of the authorize_url' do
|
|
22
|
+
subject = strategy
|
|
23
|
+
.new(app, client_options: { authorize_url: 'https://www.cobot.me' })
|
|
24
|
+
|
|
25
|
+
subject.call!(
|
|
26
|
+
{
|
|
27
|
+
'rack.session' => {},
|
|
28
|
+
'QUERY_STRING' => 'cobot_space_subdomain=my-space'
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
expect(subject.client.authorize_url)
|
|
33
|
+
.to eq('https://my-space.cobot.me')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'does not change the subdomain of the authorize_url when no cobot_space_subdomain passed' do
|
|
37
|
+
subject = strategy
|
|
38
|
+
.new(app, client_options: { authorize_url: 'https://www.cobot.me' })
|
|
39
|
+
|
|
40
|
+
subject.call!(
|
|
41
|
+
{
|
|
42
|
+
'rack.session' => {}
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
expect(subject.client.authorize_url)
|
|
47
|
+
.to eq('https://www.cobot.me')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'does nothing if no authorize_url configured' do
|
|
51
|
+
subject = strategy
|
|
52
|
+
.new(app, {})
|
|
53
|
+
|
|
54
|
+
subject.call!(
|
|
55
|
+
{
|
|
56
|
+
'rack.session' => {}
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
expect(subject.client.authorize_url)
|
|
61
|
+
.to eq('https://www.cobot.me/oauth/authorize')
|
|
62
|
+
end
|
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omniauth_cobot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Lang
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: omniauth-oauth2
|
|
@@ -16,37 +15,27 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.8
|
|
18
|
+
version: '1.8'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.8
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rake
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
25
|
+
version: '1.8'
|
|
41
26
|
description: OmniAuth strategy for Cobot
|
|
42
27
|
email: alex@cobot.me
|
|
43
28
|
executables: []
|
|
44
29
|
extensions: []
|
|
45
30
|
extra_rdoc_files: []
|
|
46
31
|
files:
|
|
32
|
+
- ".github/dependabot.yml"
|
|
33
|
+
- ".github/workflows/ruby.yml"
|
|
34
|
+
- ".github/workflows/test.yml"
|
|
47
35
|
- ".gitignore"
|
|
36
|
+
- ".rubocop.yml"
|
|
37
|
+
- CHANGES.md
|
|
48
38
|
- Gemfile
|
|
49
|
-
- Gemfile.lock
|
|
50
39
|
- MIT_LICENSE.txt
|
|
51
40
|
- README.md
|
|
52
41
|
- Rakefile
|
|
@@ -54,10 +43,12 @@ files:
|
|
|
54
43
|
- lib/omniauth/strategies/cobot.rb
|
|
55
44
|
- lib/omniauth_cobot.rb
|
|
56
45
|
- omniauth_cobot.gemspec
|
|
46
|
+
- spec/omni_auth/strategies/cobot_spec.rb
|
|
47
|
+
- spec/spec_helper.rb
|
|
57
48
|
homepage: http://github.com/cobot/omniauth_cobot
|
|
58
49
|
licenses: []
|
|
59
|
-
metadata:
|
|
60
|
-
|
|
50
|
+
metadata:
|
|
51
|
+
rubygems_mfa_required: 'true'
|
|
61
52
|
rdoc_options: []
|
|
62
53
|
require_paths:
|
|
63
54
|
- lib
|
|
@@ -65,15 +56,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
65
56
|
requirements:
|
|
66
57
|
- - ">="
|
|
67
58
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
59
|
+
version: '3.2'
|
|
60
|
+
- - "<"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '5'
|
|
69
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
64
|
requirements:
|
|
71
65
|
- - ">="
|
|
72
66
|
- !ruby/object:Gem::Version
|
|
73
67
|
version: '0'
|
|
74
68
|
requirements: []
|
|
75
|
-
rubygems_version:
|
|
76
|
-
signing_key:
|
|
69
|
+
rubygems_version: 4.0.10
|
|
77
70
|
specification_version: 4
|
|
78
71
|
summary: OmniAuth strategy for Cobot
|
|
79
72
|
test_files: []
|
data/Gemfile.lock
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
omniauth_cobot (0.0.3)
|
|
5
|
-
omniauth-oauth2 (~> 1.6.0)
|
|
6
|
-
|
|
7
|
-
GEM
|
|
8
|
-
remote: http://rubygems.org/
|
|
9
|
-
specs:
|
|
10
|
-
faraday (0.15.4)
|
|
11
|
-
multipart-post (>= 1.2, < 3)
|
|
12
|
-
hashie (3.6.0)
|
|
13
|
-
jwt (2.1.0)
|
|
14
|
-
multi_json (1.13.1)
|
|
15
|
-
multi_xml (0.6.0)
|
|
16
|
-
multipart-post (2.0.0)
|
|
17
|
-
oauth2 (1.4.1)
|
|
18
|
-
faraday (>= 0.8, < 0.16.0)
|
|
19
|
-
jwt (>= 1.0, < 3.0)
|
|
20
|
-
multi_json (~> 1.3)
|
|
21
|
-
multi_xml (~> 0.5)
|
|
22
|
-
rack (>= 1.2, < 3)
|
|
23
|
-
omniauth (1.9.0)
|
|
24
|
-
hashie (>= 3.4.6, < 3.7.0)
|
|
25
|
-
rack (>= 1.6.2, < 3)
|
|
26
|
-
omniauth-oauth2 (1.6.0)
|
|
27
|
-
oauth2 (~> 1.1)
|
|
28
|
-
omniauth (~> 1.9)
|
|
29
|
-
rack (2.2.3.1)
|
|
30
|
-
rake (13.0.1)
|
|
31
|
-
|
|
32
|
-
PLATFORMS
|
|
33
|
-
ruby
|
|
34
|
-
|
|
35
|
-
DEPENDENCIES
|
|
36
|
-
omniauth_cobot!
|
|
37
|
-
rake
|
|
38
|
-
|
|
39
|
-
BUNDLED WITH
|
|
40
|
-
1.16.1
|