Class: WorkOS::Connect

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/connect.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Connect

Returns a new instance of Connect.



9
10
11
# File 'lib/workos/connect.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#complete_oauth2(external_auth_id:, user:, user_consent_options: nil, request_options: {}) ⇒ WorkOS::ExternalAuthCompleteResponse

Complete external authentication

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/workos/connect.rb', line 19

def complete_oauth2(
  external_auth_id:,
  user:,
  user_consent_options: nil,
  request_options: {}
)
  body = {
    "external_auth_id" => external_auth_id,
    "user" => user,
    "user_consent_options" => user_consent_options
  }.compact
  response = @client.request(
    method: :post,
    path: "/authkit/oauth2/complete",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ExternalAuthCompleteResponse.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_application(name:, application_type:, description: nil, scopes: nil, redirect_uris: nil, uses_pkce: nil, is_first_party: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectApplication

Create a Connect Application

Parameters:

  • name (String)

    The name of the application.

  • application_type (String)

    The type of application to create.

  • description (String, nil) (defaults to: nil)

    A description for the application.

  • scopes (Array<String>, nil) (defaults to: nil)

    The OAuth scopes granted to the application.

  • redirect_uris (Array<WorkOS::RedirectUriInput>, nil) (defaults to: nil)

    Redirect URIs for the application.

  • uses_pkce (Boolean, nil) (defaults to: nil)

    Whether the application uses PKCE (Proof Key for Code Exchange).

  • is_first_party (Boolean, nil) (defaults to: nil)

    Whether this is a first-party application. Third-party applications require an organization_id.

  • organization_id (String, nil) (defaults to: nil)

    The organization ID this application belongs to. Required when is_first_party is false.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/workos/connect.rb', line 101

def create_application(
  name:,
  application_type:,
  description: nil,
  scopes: nil,
  redirect_uris: nil,
  uses_pkce: nil,
  is_first_party: nil,
  organization_id: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "application_type" => application_type,
    "description" => description,
    "scopes" => scopes,
    "redirect_uris" => redirect_uris,
    "uses_pkce" => uses_pkce,
    "is_first_party" => is_first_party,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/connect/applications",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectApplication.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_application_client_secret(id:, request_options: {}) ⇒ WorkOS::NewConnectApplicationSecret

Create a new client secret for a Connect Application

Parameters:

  • id (String)

    The application ID or client ID of the Connect Application.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/workos/connect.rb', line 297

def create_application_client_secret(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/connect/applications/#{WorkOS::Util.encode_path(id)}/client_secrets",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::NewConnectApplicationSecret.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_m2m_application(name:, organization_id:, description: nil, scopes: nil, request_options: {}) ⇒ WorkOS::ConnectApplication

Create m2m application.

Parameters:

  • name (String)
  • organization_id (String)
  • description (String, nil) (defaults to: nil)
  • scopes (Array<String>, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/workos/connect.rb', line 181

def create_m2m_application(
  name:,
  organization_id:,
  description: nil,
  scopes: nil,
  request_options: {}
)
  body = {
    "application_type" => "m2m",
    "name" => name,
    "organization_id" => organization_id,
    "description" => description,
    "scopes" => scopes
  }.compact
  response = @client.request(
    method: :post,
    path: "/connect/applications",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::ConnectApplication.new(response.body)
end

#create_oauth_application(name:, is_first_party:, description: nil, scopes: nil, redirect_uris: nil, uses_pkce: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectApplication

Create oauth application.

Parameters:

  • name (String)
  • is_first_party (Boolean)
  • description (String, nil) (defaults to: nil)
  • scopes (Array<String>, nil) (defaults to: nil)
  • redirect_uris (Array<WorkOS::RedirectUriInput>, nil) (defaults to: nil)
  • uses_pkce (Boolean, nil) (defaults to: nil)
  • organization_id (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/workos/connect.rb', line 144

def create_oauth_application(
  name:,
  is_first_party:,
  description: nil,
  scopes: nil,
  redirect_uris: nil,
  uses_pkce: nil,
  organization_id: nil,
  request_options: {}
)
  body = {
    "application_type" => "oauth",
    "name" => name,
    "is_first_party" => is_first_party,
    "description" => description,
    "scopes" => scopes,
    "redirect_uris" => redirect_uris,
    "uses_pkce" => uses_pkce,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/connect/applications",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::ConnectApplication.new(response.body)
end

#delete_application(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a Connect Application

Parameters:

  • id (String)

    The application ID or client ID of the Connect Application.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/workos/connect.rb', line 262

def delete_application(
  id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/connect/applications/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_client_secret(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a Client Secret

Parameters:

  • id (String)

    The unique ID of the client secret.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/workos/connect.rb', line 316

def delete_client_secret(
  id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/connect/client_secrets/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#get_application(id:, request_options: {}) ⇒ WorkOS::ConnectApplication

Get a Connect Application

Parameters:

  • id (String)

    The application ID or client ID of the Connect Application.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/workos/connect.rb', line 209

def get_application(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/connect/applications/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::ConnectApplication.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#list_application_client_secrets(id:, request_options: {}) ⇒ Array<WorkOS::ApplicationCredentialsListItem>

List Client Secrets for a Connect Application

Parameters:

  • id (String)

    The application ID or client ID of the Connect Application.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/workos/connect.rb', line 279

def list_application_client_secrets(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/connect/applications/#{WorkOS::Util.encode_path(id)}/client_secrets",
    auth: true,
    request_options: request_options
  )
  parsed = JSON.parse(response.body)
  (parsed || []).map { |item| WorkOS::ApplicationCredentialsListItem.new(item) }
end

#list_applications(before: nil, after: nil, limit: nil, order: "desc", organization_id: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::ConnectApplication>

List Connect Applications

Parameters:

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with ‘“obj_123”`, your subsequent call can include `before=“obj_123”` to fetch a new batch of objects before `“obj_123”`.

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with ‘“obj_123”`, your subsequent call can include `after=“obj_123”` to fetch a new batch of objects after `“obj_123”`.

  • limit (Integer, nil) (defaults to: nil)

    Upper limit on the number of objects to return, between ‘1` and `100`.

  • order (WorkOS::Types::ApplicationsOrder, nil) (defaults to: "desc")

    Order the results by the creation time. Supported values are ‘“asc”` (ascending), `“desc”` (descending), and `“normal”` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending.

  • organization_id (String, nil) (defaults to: nil)

    Filter Connect Applications by organization ID.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/workos/connect.rb', line 50

def list_applications(
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  organization_id: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/connect/applications",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_applications(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      organization_id: organization_id,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::ConnectApplication,
    filters: {before: before, limit: limit, order: order, organization_id: organization_id},
    fetch_next: fetch_next
  )
end

#update_application(id:, name: nil, description: nil, scopes: nil, redirect_uris: nil, request_options: {}) ⇒ WorkOS::ConnectApplication

Update a Connect Application

Parameters:

  • id (String)

    The application ID or client ID of the Connect Application.

  • name (String, nil) (defaults to: nil)

    The name of the application.

  • description (String, nil) (defaults to: nil)

    A description for the application.

  • scopes (Array<String>, nil) (defaults to: nil)

    The OAuth scopes granted to the application.

  • redirect_uris (Array<WorkOS::RedirectUriInput>, nil) (defaults to: nil)

    Updated redirect URIs for the application. OAuth applications only.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/workos/connect.rb', line 232

def update_application(
  id:,
  name: nil,
  description: nil,
  scopes: nil,
  redirect_uris: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description,
    "scopes" => scopes,
    "redirect_uris" => redirect_uris
  }.compact
  response = @client.request(
    method: :put,
    path: "/connect/applications/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectApplication.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end