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:

  • external_auth_id (String)

    Identifier provided when AuthKit redirected to your login page.

  • user (WorkOS::UserObject)

    The user to create or update in AuthKit.

  • user_consent_options (Array<WorkOS::UserConsentOption>, nil) (defaults to: nil)

    Array of User Consent Options to store with the session.

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

    (see WorkOS::Types::RequestOptions)

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: WorkOS::OMIT, scopes: WorkOS::OMIT, redirect_uris: WorkOS::OMIT, uses_pkce: WorkOS::OMIT, is_first_party: nil, organization_id: WorkOS::OMIT, 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: WorkOS::OMIT)

    A description for the application.

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

    The OAuth scopes granted to the application.

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

    Redirect URIs for the application.

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

    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: WorkOS::OMIT)

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
133
134
135
136
# File 'lib/workos/connect.rb', line 105

def create_application(
  name:,
  application_type:,
  description: WorkOS::OMIT,
  scopes: WorkOS::OMIT,
  redirect_uris: WorkOS::OMIT,
  uses_pkce: WorkOS::OMIT,
  is_first_party: nil,
  organization_id: WorkOS::OMIT,
  request_options: {}
)
  body = {
    "name" => name,
    "application_type" => application_type,
    "is_first_party" => is_first_party
  }.compact
  body["description"] = description unless description.equal?(WorkOS::OMIT)
  body["scopes"] = scopes unless scopes.equal?(WorkOS::OMIT)
  body["redirect_uris"] = redirect_uris unless redirect_uris.equal?(WorkOS::OMIT)
  body["uses_pkce"] = uses_pkce unless uses_pkce.equal?(WorkOS::OMIT)
  body["organization_id"] = organization_id unless organization_id.equal?(WorkOS::OMIT)
  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:



301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/workos/connect.rb', line 301

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:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/workos/connect.rb', line 185

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:



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
173
174
175
176
# File 'lib/workos/connect.rb', line 148

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)



266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/workos/connect.rb', line 266

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)



320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/workos/connect.rb', line 320

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:



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/workos/connect.rb', line 213

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:



283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/workos/connect.rb', line 283

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: 10, order: "desc", registration_types: nil, 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: 10)

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

  • order (WorkOS::Types::PaginationOrder, 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).

  • registration_types (Array<WorkOS::Types::ApplicationsRegistrationTypes>, nil) (defaults to: nil)

    Filter Connect Applications by registration type. Specify multiple as a comma-separated list (e.g. registration_types=dynamic,authenticated). Defaults to authenticated only when not specified.

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

    Filter Connect Applications by organization ID.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
89
90
91
92
# File 'lib/workos/connect.rb', line 51

def list_applications(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  registration_types: nil,
  organization_id: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "registration_types" => registration_types,
    "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,
      registration_types: registration_types,
      organization_id: organization_id,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::ConnectApplication,
    filters: {before: before, limit: limit, order: order, registration_types: registration_types, organization_id: organization_id},
    fetch_next: fetch_next
  )
end

#update_application(id:, name: nil, description: WorkOS::OMIT, scopes: WorkOS::OMIT, redirect_uris: WorkOS::OMIT, 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: WorkOS::OMIT)

    A description for the application.

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

    The OAuth scopes granted to the application.

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

    Updated redirect URIs for the application. OAuth applications only.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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

def update_application(
  id:,
  name: nil,
  description: WorkOS::OMIT,
  scopes: WorkOS::OMIT,
  redirect_uris: WorkOS::OMIT,
  request_options: {}
)
  body = {
    "name" => name
  }.compact
  body["description"] = description unless description.equal?(WorkOS::OMIT)
  body["scopes"] = scopes unless scopes.equal?(WorkOS::OMIT)
  body["redirect_uris"] = redirect_uris unless redirect_uris.equal?(WorkOS::OMIT)
  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