workos 0.2.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -1
- data/.semaphore/semaphore.yml +13 -6
- data/Gemfile.lock +6 -6
- data/README.md +1 -1
- data/lib/workos.rb +2 -0
- data/lib/workos/audit_trail.rb +0 -16
- data/lib/workos/client.rb +43 -4
- data/lib/workos/connection.rb +48 -0
- data/lib/workos/directory_sync.rb +128 -0
- data/lib/workos/profile.rb +6 -7
- data/lib/workos/sso.rb +48 -35
- data/lib/workos/types.rb +2 -2
- data/lib/workos/types/connection_struct.rb +15 -0
- data/lib/workos/types/profile_struct.rb +2 -3
- data/lib/workos/types/provider_enum.rb +0 -1
- data/lib/workos/version.rb +1 -1
- data/sorbet/rbi/hidden-definitions/errors.txt +1416 -321
- data/sorbet/rbi/hidden-definitions/hidden.rbi +2490 -597
- data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +36 -14
- data/sorbet/rbi/todo.rbi +1 -6
- data/spec/lib/workos/directory_sync_spec.rb +139 -0
- data/spec/lib/workos/sso_spec.rb +50 -4
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group_with_invalid_id.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user_with_invalid_id.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +63 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups.yml +64 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups_with_directory_param.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users.yml +64 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users_with_directory_param.yml +62 -0
- data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_invalid_source.yml +58 -0
- data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +63 -0
- data/workos.gemspec +14 -11
- metadata +35 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 773cbb5edfa2433922650417a8b487513bc197fa72b758fd4423bea67bf87f49
|
4
|
+
data.tar.gz: 72f573248a97132d57117718e811242b6be36ad15025eeec9f311a3477186bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fe620f43ec9b30ed8a885c08d157bfc5f0da091d820306fcba3e9dee9ba7b6d69d3f5b5cad8b74882a3080058ede66da47af228c2ccd761715ee4c8a7d82eac
|
7
|
+
data.tar.gz: 442b32e6bdc38579e21937c7da371d4b6f767027c021620f538d468d0e8ac9ca31cd226778c7b5f10f419f3d1c0d21cb402e846738abd871a67c95ac315130d4
|
data/.rubocop.yml
CHANGED
@@ -10,6 +10,8 @@ Layout/LineLength:
|
|
10
10
|
- '(\A|\s)/.*?/'
|
11
11
|
Metrics/BlockLength:
|
12
12
|
ExcludedMethods: ['describe', 'context']
|
13
|
+
Metrics/ModuleLength:
|
14
|
+
Max: 150
|
13
15
|
Style/TrailingCommaInArguments:
|
14
16
|
EnforcedStyleForMultiline: 'consistent_comma'
|
15
17
|
Style/TrailingCommaInHashLiteral:
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.1
|
data/.semaphore/semaphore.yml
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
version: v1.0
|
2
2
|
name: Ruby
|
3
|
+
|
3
4
|
agent:
|
4
5
|
machine:
|
5
6
|
type: e1-standard-2
|
6
7
|
os_image: ubuntu1804
|
8
|
+
|
7
9
|
blocks:
|
8
10
|
- name: Run Sorbet 🍦
|
9
11
|
task:
|
@@ -11,19 +13,18 @@ blocks:
|
|
11
13
|
- name: srb tc
|
12
14
|
commands:
|
13
15
|
- checkout
|
14
|
-
- sem-version ruby 2.6.5
|
15
|
-
- gem install bundler
|
16
16
|
- bundle install
|
17
17
|
- bundle exec srb tc
|
18
|
+
|
18
19
|
- name: Run Rubocop 🚔
|
19
20
|
task:
|
20
21
|
jobs:
|
21
22
|
- name: rubocop
|
22
23
|
commands:
|
23
24
|
- checkout
|
24
|
-
- sem-version ruby 2.6.5
|
25
25
|
- bundle install
|
26
26
|
- bundle exec rubocop
|
27
|
+
|
27
28
|
- name: Run Tests 👩🏽🔬
|
28
29
|
task:
|
29
30
|
secrets:
|
@@ -40,7 +41,7 @@ blocks:
|
|
40
41
|
- checkout
|
41
42
|
- sem-version ruby 2.0.0
|
42
43
|
- bundle install
|
43
|
-
- bundle exec rspec
|
44
|
+
- bundle exec rspec
|
44
45
|
- name: Ruby 2.3.4
|
45
46
|
commands:
|
46
47
|
- checkout
|
@@ -58,7 +59,13 @@ blocks:
|
|
58
59
|
- checkout
|
59
60
|
- sem-version ruby 2.6.5
|
60
61
|
- bundle install
|
61
|
-
- bundle exec rspec
|
62
|
+
- bundle exec rspec
|
63
|
+
- name: Ruby 2.7.1
|
64
|
+
commands:
|
65
|
+
- checkout
|
66
|
+
- sem-version ruby 2.7.1
|
67
|
+
- bundle install
|
68
|
+
- bundle exec rspec
|
62
69
|
promotions:
|
63
70
|
- name: Deploy workos-rb to rubygems
|
64
|
-
pipeline_file: rubygems.yml
|
71
|
+
pipeline_file: rubygems.yml
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
workos (0.
|
4
|
+
workos (0.3.3)
|
5
5
|
sorbet-runtime (~> 0.5)
|
6
6
|
|
7
7
|
GEM
|
@@ -54,10 +54,10 @@ GEM
|
|
54
54
|
json (>= 1.8, < 3)
|
55
55
|
simplecov-html (~> 0.10.0)
|
56
56
|
simplecov-html (0.10.2)
|
57
|
-
sorbet (0.5.
|
58
|
-
sorbet-static (= 0.5.
|
59
|
-
sorbet-runtime (0.5.
|
60
|
-
sorbet-static (0.5.
|
57
|
+
sorbet (0.5.5560)
|
58
|
+
sorbet-static (= 0.5.5560)
|
59
|
+
sorbet-runtime (0.5.5815)
|
60
|
+
sorbet-static (0.5.5560-universal-darwin-14)
|
61
61
|
unicode-display_width (1.6.0)
|
62
62
|
url (0.3.2)
|
63
63
|
vcr (5.0.0)
|
@@ -83,4 +83,4 @@ DEPENDENCIES
|
|
83
83
|
yard
|
84
84
|
|
85
85
|
BUNDLED WITH
|
86
|
-
2.1.
|
86
|
+
2.1.4
|
data/README.md
CHANGED
@@ -80,7 +80,7 @@ WorkOS::AuditTrail.create_event(event: payload, idempotency_key: 'key123456')
|
|
80
80
|
```
|
81
81
|
|
82
82
|
See our [API
|
83
|
-
Reference](https://docs.workos.com/api-reference#idempotency)
|
83
|
+
Reference](https://docs.workos.com/audit-trail/api-reference#idempotency)
|
84
84
|
for more information on idempotency keys.
|
85
85
|
|
86
86
|
## The SSO Module
|
data/lib/workos.rb
CHANGED
@@ -29,6 +29,8 @@ module WorkOS
|
|
29
29
|
autoload :Base, 'workos/base'
|
30
30
|
autoload :Client, 'workos/client'
|
31
31
|
autoload :AuditTrail, 'workos/audit_trail'
|
32
|
+
autoload :Connection, 'workos/connection'
|
33
|
+
autoload :DirectorySync, 'workos/directory_sync'
|
32
34
|
autoload :Profile, 'workos/profile'
|
33
35
|
autoload :SSO, 'workos/sso'
|
34
36
|
|
data/lib/workos/audit_trail.rb
CHANGED
@@ -57,22 +57,6 @@ module WorkOS
|
|
57
57
|
|
58
58
|
execute_request(request: request)
|
59
59
|
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
sig do
|
64
|
-
params(
|
65
|
-
path: String,
|
66
|
-
idempotency_key: T.nilable(String),
|
67
|
-
body: T.nilable(Hash),
|
68
|
-
).returns(Net::HTTP::Post)
|
69
|
-
end
|
70
|
-
def post_request(path:, idempotency_key: nil, body: nil)
|
71
|
-
request = super(path: path, body: body)
|
72
|
-
request['Authorization'] = "Bearer #{WorkOS.key}"
|
73
|
-
request['Idempotency-Key'] = idempotency_key if idempotency_key
|
74
|
-
request
|
75
|
-
end
|
76
60
|
end
|
77
61
|
end
|
78
62
|
end
|
data/lib/workos/client.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# typed: true
|
3
3
|
|
4
|
-
|
5
4
|
module WorkOS
|
6
5
|
# A Net::HTTP based API client for interacting with the WorkOS API
|
7
6
|
module Client
|
@@ -18,7 +17,11 @@ module WorkOS
|
|
18
17
|
@client
|
19
18
|
end
|
20
19
|
|
21
|
-
sig
|
20
|
+
sig do
|
21
|
+
params(
|
22
|
+
request: T.any(Net::HTTP::Get, Net::HTTP::Post),
|
23
|
+
).returns(::T.untyped)
|
24
|
+
end
|
22
25
|
def execute_request(request:)
|
23
26
|
response = client.request(request)
|
24
27
|
|
@@ -28,10 +31,40 @@ module WorkOS
|
|
28
31
|
response
|
29
32
|
end
|
30
33
|
|
31
|
-
sig
|
32
|
-
|
34
|
+
sig do
|
35
|
+
params(
|
36
|
+
path: String,
|
37
|
+
auth: T.nilable(T::Boolean),
|
38
|
+
params: T.nilable(Hash),
|
39
|
+
).returns(Net::HTTP::Get)
|
40
|
+
end
|
41
|
+
def get_request(path:, auth: false, params: {})
|
42
|
+
uri = URI(path)
|
43
|
+
uri.query = URI.encode_www_form(params) if params
|
44
|
+
|
45
|
+
request = Net::HTTP::Get.new(
|
46
|
+
uri.to_s,
|
47
|
+
'Content-Type' => 'application/json',
|
48
|
+
)
|
49
|
+
|
50
|
+
request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
|
51
|
+
request['User-Agent'] = user_agent
|
52
|
+
request
|
53
|
+
end
|
54
|
+
|
55
|
+
sig do
|
56
|
+
params(
|
57
|
+
path: String,
|
58
|
+
auth: T.nilable(T::Boolean),
|
59
|
+
idempotency_key: T.nilable(String),
|
60
|
+
body: T.nilable(Hash),
|
61
|
+
).returns(Net::HTTP::Post)
|
62
|
+
end
|
63
|
+
def post_request(path:, auth: false, idempotency_key: nil, body: nil)
|
33
64
|
request = Net::HTTP::Post.new(path, 'Content-Type' => 'application/json')
|
34
65
|
request.body = body.to_json if body
|
66
|
+
request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
|
67
|
+
request['Idempotency-Key'] = idempotency_key if idempotency_key
|
35
68
|
request['User-Agent'] = user_agent
|
36
69
|
request
|
37
70
|
end
|
@@ -68,6 +101,12 @@ module WorkOS
|
|
68
101
|
http_status: http_status,
|
69
102
|
request_id: response['x-request-id'],
|
70
103
|
)
|
104
|
+
when 404
|
105
|
+
raise APIError.new(
|
106
|
+
message: json['message'],
|
107
|
+
http_status: http_status,
|
108
|
+
request_id: response['x-request-id'],
|
109
|
+
)
|
71
110
|
when 422
|
72
111
|
errors = json['errors'].map do |error|
|
73
112
|
"#{error['field']}: #{error['code']}"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module WorkOS
|
7
|
+
# The Connection class provides a lightweight wrapper around
|
8
|
+
# a WorkOS Connection resource. This class is not meant to be instantiated
|
9
|
+
# in user space, and is instantiated internally but exposed.
|
10
|
+
class Connection
|
11
|
+
extend T::Sig
|
12
|
+
|
13
|
+
attr_accessor :id, :name, :connection_type, :domains
|
14
|
+
|
15
|
+
sig { params(json: String).void }
|
16
|
+
def initialize(json)
|
17
|
+
raw = parse_json(json)
|
18
|
+
|
19
|
+
@id = T.let(raw.id, String)
|
20
|
+
@name = T.let(raw.name, String)
|
21
|
+
@connection_type = T.let(raw.connection_type, String)
|
22
|
+
@domains = T.let(raw.domains, Array)
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_json(*)
|
26
|
+
{
|
27
|
+
id: id,
|
28
|
+
name: name,
|
29
|
+
connection_type: connection_type,
|
30
|
+
domains: domains,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
sig { params(json_string: String).returns(WorkOS::Types::ConnectionStruct) }
|
37
|
+
def parse_json(json_string)
|
38
|
+
hash = JSON.parse(json_string, symbolize_names: true)
|
39
|
+
|
40
|
+
WorkOS::Types::ConnectionStruct.new(
|
41
|
+
id: hash[:id],
|
42
|
+
name: hash[:name],
|
43
|
+
connection_type: hash[:connection_type],
|
44
|
+
domains: hash[:domains],
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module WorkOS
|
5
|
+
# The Directory Sync module provides convenience methods for working with the
|
6
|
+
# WorkOS Directory Sync platform. You'll need a valid API key and to have
|
7
|
+
# created a Directory Sync connection on your WorkOS dashboard.
|
8
|
+
#
|
9
|
+
# @see https://docs.workos.com/directory-sync/overview
|
10
|
+
module DirectorySync
|
11
|
+
class << self
|
12
|
+
extend T::Sig
|
13
|
+
include Base
|
14
|
+
include Client
|
15
|
+
|
16
|
+
# Retrieve directories.
|
17
|
+
#
|
18
|
+
# @param [Hash] options An options hash
|
19
|
+
# @option options [String] domain The domain of the directory to be
|
20
|
+
# retrieved.
|
21
|
+
# @option options [String] search A search term for direcory names.
|
22
|
+
#
|
23
|
+
# @return [Hash]
|
24
|
+
sig do
|
25
|
+
params(
|
26
|
+
options: T::Hash[Symbol, String],
|
27
|
+
).returns(T::Array[T::Hash[String, T.nilable(String)]])
|
28
|
+
end
|
29
|
+
def list_directories(options = {})
|
30
|
+
response = execute_request(
|
31
|
+
request: get_request(
|
32
|
+
path: '/directories',
|
33
|
+
auth: true,
|
34
|
+
params: options,
|
35
|
+
),
|
36
|
+
)
|
37
|
+
|
38
|
+
JSON.parse(response.body)['data']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Retrieve directory groups.
|
42
|
+
#
|
43
|
+
# @param [Hash] options An options hash
|
44
|
+
# @option options [String] directory The ID of the directory whose
|
45
|
+
# directory groups will be retrieved.
|
46
|
+
# @option options [String] user The ID of the directory user whose
|
47
|
+
# directory groups will be retrieved.
|
48
|
+
#
|
49
|
+
# @return [Hash]
|
50
|
+
sig do
|
51
|
+
params(
|
52
|
+
options: T::Hash[Symbol, String],
|
53
|
+
).returns(T::Array[T::Hash[String, T.nilable(String)]])
|
54
|
+
end
|
55
|
+
def list_groups(options = {})
|
56
|
+
response = execute_request(
|
57
|
+
request: get_request(
|
58
|
+
path: '/directory_groups',
|
59
|
+
auth: true,
|
60
|
+
params: options,
|
61
|
+
),
|
62
|
+
)
|
63
|
+
|
64
|
+
JSON.parse(response.body)['data']
|
65
|
+
end
|
66
|
+
|
67
|
+
# Retrieve directory users.
|
68
|
+
#
|
69
|
+
# @param [Hash] options An options hash
|
70
|
+
# @option options [String] directory The ID of the directory whose
|
71
|
+
# directory users will be retrieved.
|
72
|
+
# @option options [String] user The ID of the directory group whose
|
73
|
+
# directory users will be retrieved.
|
74
|
+
#
|
75
|
+
# @return [Hash]
|
76
|
+
sig do
|
77
|
+
params(
|
78
|
+
options: T::Hash[Symbol, String],
|
79
|
+
).returns(T::Array[T::Hash[String, T.untyped]])
|
80
|
+
end
|
81
|
+
def list_users(options = {})
|
82
|
+
response = execute_request(
|
83
|
+
request: get_request(
|
84
|
+
path: '/directory_users',
|
85
|
+
auth: true,
|
86
|
+
params: options,
|
87
|
+
),
|
88
|
+
)
|
89
|
+
|
90
|
+
JSON.parse(response.body)['data']
|
91
|
+
end
|
92
|
+
|
93
|
+
# Retrieve the directory group with the given ID.
|
94
|
+
#
|
95
|
+
# @param [String] id The ID of the directory group.
|
96
|
+
#
|
97
|
+
# @return Hash
|
98
|
+
sig { params(id: String).returns(T::Hash[String, T.untyped]) }
|
99
|
+
def get_group(id)
|
100
|
+
response = execute_request(
|
101
|
+
request: get_request(
|
102
|
+
path: "/directory_groups/#{id}",
|
103
|
+
auth: true,
|
104
|
+
),
|
105
|
+
)
|
106
|
+
|
107
|
+
JSON.parse(response.body)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Retrieve the directory user with the given ID.
|
111
|
+
#
|
112
|
+
# @param [String] id The ID of the directory user.
|
113
|
+
#
|
114
|
+
# @return Hash
|
115
|
+
sig { params(id: String).returns(T::Hash[String, T.untyped]) }
|
116
|
+
def get_user(id)
|
117
|
+
response = execute_request(
|
118
|
+
request: get_request(
|
119
|
+
path: "/directory_users/#{id}",
|
120
|
+
auth: true,
|
121
|
+
),
|
122
|
+
)
|
123
|
+
|
124
|
+
JSON.parse(response.body)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/workos/profile.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# typed: true
|
3
3
|
|
4
|
-
|
5
4
|
require 'json'
|
6
5
|
|
7
6
|
module WorkOS
|
8
7
|
# The Profile class provides a lighweight wrapper around
|
9
8
|
# a normalized response from the various IDPs WorkOS
|
10
9
|
# supports as part of the SSO integration. This class
|
11
|
-
# is not meant
|
10
|
+
# is not meant to be instantiated in user space, and
|
12
11
|
# is instantiated internally but exposed.
|
13
12
|
class Profile
|
14
13
|
extend T::Sig
|
@@ -21,12 +20,12 @@ module WorkOS
|
|
21
20
|
def initialize(profile_json)
|
22
21
|
raw = parse_json(profile_json)
|
23
22
|
|
24
|
-
@id
|
25
|
-
@email
|
26
|
-
@first_name
|
27
|
-
@last_name
|
23
|
+
@id = T.let(raw.id, String)
|
24
|
+
@email = T.let(raw.email, String)
|
25
|
+
@first_name = raw.first_name
|
26
|
+
@last_name = raw.last_name
|
28
27
|
@connection_type = T.let(raw.connection_type, String)
|
29
|
-
@idp_id
|
28
|
+
@idp_id = T.let(raw.idp_id, String)
|
30
29
|
end
|
31
30
|
|
32
31
|
sig { returns(String) }
|
data/lib/workos/sso.rb
CHANGED
@@ -18,16 +18,6 @@ module WorkOS
|
|
18
18
|
|
19
19
|
PROVIDERS = WorkOS::Types::Provider.values.map(&:serialize).freeze
|
20
20
|
|
21
|
-
sig do
|
22
|
-
params(
|
23
|
-
project_id: String,
|
24
|
-
redirect_uri: String,
|
25
|
-
domain: T.nilable(String),
|
26
|
-
provider: T.nilable(String),
|
27
|
-
state: Hash,
|
28
|
-
).returns(String)
|
29
|
-
end
|
30
|
-
|
31
21
|
# Generate an Oauth2 authorization URL where your users will
|
32
22
|
# authenticate using the configured SSO Identity Provider.
|
33
23
|
#
|
@@ -41,7 +31,7 @@ module WorkOS
|
|
41
31
|
# @param [String] redirect_uri The URI where users are directed
|
42
32
|
# after completing the authentication step. Must match a
|
43
33
|
# configured redirect URI on your WorkOS dashboard.
|
44
|
-
# @param [
|
34
|
+
# @param [String] state An aribtrary state object
|
45
35
|
# that is preserved and available to the client in the response.
|
46
36
|
# @example
|
47
37
|
# WorkOS::SSO.authorization_url(
|
@@ -50,7 +40,7 @@ module WorkOS
|
|
50
40
|
# redirect_uri: 'https://workos.com/callback',
|
51
41
|
# state: {
|
52
42
|
# next_page: '/docs'
|
53
|
-
# }
|
43
|
+
# }.to_s
|
54
44
|
# )
|
55
45
|
#
|
56
46
|
# => "https://api.workos.com/sso/authorize?domain=acme.com" \
|
@@ -59,8 +49,17 @@ module WorkOS
|
|
59
49
|
# "response_type=code&state=%7B%3Anext_page%3D%3E%22%2Fdocs%22%7D"
|
60
50
|
#
|
61
51
|
# @return [String]
|
52
|
+
sig do
|
53
|
+
params(
|
54
|
+
project_id: String,
|
55
|
+
redirect_uri: String,
|
56
|
+
domain: T.nilable(String),
|
57
|
+
provider: T.nilable(String),
|
58
|
+
state: T.nilable(String),
|
59
|
+
).returns(String)
|
60
|
+
end
|
62
61
|
def authorization_url(
|
63
|
-
project_id:, redirect_uri:, domain: nil, provider: nil, state:
|
62
|
+
project_id:, redirect_uri:, domain: nil, provider: nil, state: ''
|
64
63
|
)
|
65
64
|
validate_domain_and_provider(provider: provider, domain: domain)
|
66
65
|
|
@@ -76,13 +75,6 @@ module WorkOS
|
|
76
75
|
"https://#{WorkOS::API_HOSTNAME}/sso/authorize?#{query}"
|
77
76
|
end
|
78
77
|
|
79
|
-
sig do
|
80
|
-
params(
|
81
|
-
code: String,
|
82
|
-
project_id: String,
|
83
|
-
).returns(WorkOS::Profile)
|
84
|
-
end
|
85
|
-
|
86
78
|
# Fetch the profile details for the authenticated SSO user.
|
87
79
|
#
|
88
80
|
# @param [String] code The authorization code provided in the callback URL
|
@@ -105,6 +97,7 @@ module WorkOS
|
|
105
97
|
# >
|
106
98
|
#
|
107
99
|
# @return [WorkOS::Profile]
|
100
|
+
sig { params(code: String, project_id: String).returns(WorkOS::Profile) }
|
108
101
|
def profile(code:, project_id:)
|
109
102
|
body = {
|
110
103
|
client_id: project_id,
|
@@ -119,17 +112,11 @@ module WorkOS
|
|
119
112
|
WorkOS::Profile.new(response.body)
|
120
113
|
end
|
121
114
|
|
122
|
-
sig do
|
123
|
-
params(
|
124
|
-
token: String,
|
125
|
-
).returns(T::Boolean)
|
126
|
-
end
|
127
|
-
|
128
115
|
# Promote a DraftConnection created via the WorkOS.js embed such that the
|
129
116
|
# Enterprise users can begin signing into your application.
|
130
117
|
#
|
131
|
-
# @param [String] token The
|
132
|
-
# you by the WorkOS.js
|
118
|
+
# @param [String] token The Draft Connection token that's been provided to
|
119
|
+
# you by the WorkOS.js
|
133
120
|
#
|
134
121
|
# @example
|
135
122
|
# WorkOS::SSO.promote_draft_connection(
|
@@ -139,8 +126,10 @@ module WorkOS
|
|
139
126
|
#
|
140
127
|
# @return [Bool] - returns `true` if successful, `false` otherwise.
|
141
128
|
# @see https://github.com/workos-inc/ruby-idp-link-example
|
129
|
+
sig { params(token: String).returns(T::Boolean) }
|
142
130
|
def promote_draft_connection(token:)
|
143
|
-
request =
|
131
|
+
request = post_request(
|
132
|
+
auth: true,
|
144
133
|
path: "/draft_connections/#{token}/activate",
|
145
134
|
)
|
146
135
|
|
@@ -149,6 +138,36 @@ module WorkOS
|
|
149
138
|
response.is_a? Net::HTTPSuccess
|
150
139
|
end
|
151
140
|
|
141
|
+
# Create a Connection
|
142
|
+
#
|
143
|
+
# @param [String] source The Draft Connection token that's been provided
|
144
|
+
# to you by WorkOS.js
|
145
|
+
#
|
146
|
+
# @example
|
147
|
+
# WorkOS::SSO.create_connection(source: 'draft_conn_429u59js')
|
148
|
+
# => #<WorkOS::Connection:0x00007fb6e4193d20
|
149
|
+
# @id="conn_02DRA1XNSJDZ19A31F183ECQW9",
|
150
|
+
# @name="Foo Corp",
|
151
|
+
# @connection_type="OktaSAML",
|
152
|
+
# @domains=
|
153
|
+
# [{:object=>"connection_domain",
|
154
|
+
# :id=>"domain_01E6PK9N3XMD8RHWF7S66380AR",
|
155
|
+
# :domain=>"example.com"}]>
|
156
|
+
#
|
157
|
+
# @return [WorkOS::Connection]
|
158
|
+
sig { params(source: String).returns(WorkOS::Connection) }
|
159
|
+
def create_connection(source:)
|
160
|
+
request = post_request(
|
161
|
+
auth: true,
|
162
|
+
path: '/connections',
|
163
|
+
body: { source: source },
|
164
|
+
)
|
165
|
+
|
166
|
+
response = execute_request(request: request)
|
167
|
+
|
168
|
+
WorkOS::Connection.new(response.body)
|
169
|
+
end
|
170
|
+
|
152
171
|
private
|
153
172
|
|
154
173
|
sig do
|
@@ -188,12 +207,6 @@ module WorkOS
|
|
188
207
|
)
|
189
208
|
end
|
190
209
|
# rubocop:enable Metrics/MethodLength
|
191
|
-
|
192
|
-
def bearer_post_request(path:, body: nil)
|
193
|
-
request = post_request(path: path, body: body)
|
194
|
-
request['Authorization'] = "Bearer #{WorkOS.key!}"
|
195
|
-
request
|
196
|
-
end
|
197
210
|
end
|
198
211
|
end
|
199
212
|
end
|