omniauth_cobot 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd04fd27faf858cb8ee7d25e9d1c93402b28f87b34550dc542203fc873495b4f
4
- data.tar.gz: e3ea2d9f917c5d67f743a449394ee29b9f517cd7ce297e8d3ae78652324e3038
3
+ metadata.gz: 3c91b6d6f983000b2c8f392cb0532aeb6c5dedf0afbfee30cd3b6adf2b4fb15d
4
+ data.tar.gz: 6280f53cfe29d745051263c61f0f670ddd124ecfe8ef6b57955182f78fa3cd37
5
5
  SHA512:
6
- metadata.gz: 86c1325dae2bddd3aed060f980c6e353e71d51604cef3216c33b7e9808d22692daac63a55ef99f36806936595b71eb57ac93cfebe16032dca2ed67a4d0973704
7
- data.tar.gz: d34796ce330e318b1872e74e3e17cd5044fd2ec5abcbda71d089821da685c0142f4d33cdd34eba6296cbefe2f4218d4b1cb70db92f8e02a5761d08d4f21cd300
6
+ metadata.gz: 0f549df07238edc70eaa9912b633be07d1d5bc63ed0a9b7e28f5000e2703d5f7546b47cd7b654d380bbdb8925f74c14bd3db1c518362fdc1f196c172f43279e9
7
+ data.tar.gz: 3cbf4da8ef6ebc0dd95c01757bc0ae16fb0f3363a516c02d9c441dbb6b216c8aee82e41d98bf988b61ea05a1c90c2e90eff2ccb51eadd323d405ae5edab89480
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "weekly"
@@ -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.3)
5
- omniauth-oauth2 (~> 1.6.0)
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
- 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)
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
- multipart-post (2.0.0)
17
- oauth2 (1.4.1)
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, < 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)
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
- ruby
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
- 1.16.1
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
- Rails.application.config.middleware.use OmniAuth::Builder do
10
- provider :cobot, '<client_id>', '<client_secret>', scope: 'read write'
11
- end
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
- This gives you access to a variable `request.env['omniauth.auth']` in your authentication callback that looks like this:
15
+ To authenticate a user against Cobot, send them to `/auth/cobot`.
14
16
 
15
- * `uid` - the id of the user
16
- * `credentials` - `{'token' => '<access token>'}`
17
- * `info` - `{'email' => '<user email>', 'picture' => '<url>'}`
18
- * `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>" } ] }`
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
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ task default: [:spec]
7
+
8
+ desc "Run the specs."
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = "spec/**/*_spec.rb"
11
+ end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Cobot
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -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
@@ -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
- # s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
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
@@ -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.1.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-10-15 00:00:00.000000000 Z
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