Class: WorkOS::SSO

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

Defined Under Namespace

Classes: CreateProtocolOptionsOIDC, CreateProtocolOptionsSAML, PatchProtocolOptionsOIDC, PatchProtocolOptionsSAML

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SSO

Returns a new instance of SSO.



34
35
36
# File 'lib/workos/sso.rb', line 34

def initialize(client)
  @client = client
end

Instance Method Details

#authorize_logout(profile_id:, request_options: {}) ⇒ WorkOS::SSOLogoutAuthorizeResponse

Logout Authorize

Parameters:

  • profile_id (String) —

    The unique ID of the profile to log out.

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

    (see WorkOS::Types::RequestOptions)

Returns:



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/workos/sso.rb', line 478

def authorize_logout(
  profile_id:,
  request_options: {}
)
  body = {
    "profile_id" => profile_id
  }
  response = @client.request(
    method: :post,
    path: "/sso/logout/authorize",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::SSOLogoutAuthorizeResponse.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

#build_logout_url(token:) ⇒ Object

H17 — Build the SSO logout redirect URL (no HTTP call).



587
588
589
# File 'lib/workos/sso.rb', line 587

def build_logout_url(token:)
  build_url("/sso/logout", {"token" => token})
end

#create_connection(organization_id:, protocol_options:, name: nil, external_id: nil, connection_type: nil, attribute_maps: nil, request_options: {}) ⇒ WorkOS::Connection

Create a Connection

Parameters:

  • organization_id (String) —

    Unique identifier for the Organization in which the Connection resides.

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

    A human-readable name for the Connection. This will most commonly be the organization's name.

  • external_id (String, nil) (defaults to: nil) —

    The customer-owned identifier for the Connection.

  • connection_type (String, nil) (defaults to: nil) —

    The type of the Connection. Only SAML and OIDC connection types may be created. When omitted, the type is inferred from the provided options.

  • attribute_maps (WorkOS::CreateConnectionAttributeMaps, nil) (defaults to: nil) —

    How IdP attributes or claims map onto WorkOS profile fields. Provided fields override the defaults for the connection type.

  • protocol_options (WorkOS::SSO::CreateProtocolOptionsSAML, WorkOS::SSO::CreateProtocolOptionsOIDC) —

    Identifies the protocol options.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
137
138
139
140
141
142
143
144
145
# File 'lib/workos/sso.rb', line 111

def create_connection(
  organization_id:,
  protocol_options:,
  name: nil,
  external_id: nil,
  connection_type: nil,
  attribute_maps: nil,
  request_options: {}
)
  body = {
    "organization_id" => organization_id,
    "name" => name,
    "external_id" => external_id,
    "connection_type" => connection_type,
    "attribute_maps" => attribute_maps
  }.compact
  case protocol_options
  when WorkOS::SSO::CreateProtocolOptionsSAML
    body["saml_options"] = protocol_options.saml_options
  when WorkOS::SSO::CreateProtocolOptionsOIDC
    body["oidc_options"] = protocol_options.oidc_options
  else
    raise ArgumentError, "expected protocol_options to be one of: WorkOS::SSO::CreateProtocolOptionsSAML, WorkOS::SSO::CreateProtocolOptionsOIDC, got #{protocol_options.class}"
  end
  response = @client.request(
    method: :post,
    path: "/connections",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Connection.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_connection_saml_idp_signing_cert(connection_id:, value:, request_options: {}) ⇒ WorkOS::SAMLIdpSigningCertificate

Create an IdP signing certificate

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

  • value (String) —

    The PEM-encoded X.509 certificate.

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

    (see WorkOS::Types::RequestOptions)

Returns:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/workos/sso.rb', line 171

def create_connection_saml_idp_signing_cert(
  connection_id:,
  value:,
  request_options: {}
)
  body = {
    "value" => value
  }
  response = @client.request(
    method: :post,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_idp_signing_certs",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::SAMLIdpSigningCertificate.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_connection_saml_sp_encryption_cert(connection_id:, request_options: {}) ⇒ WorkOS::SAMLSpEncryptionCertificate

Create an SP encryption certificate

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

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

    (see WorkOS::Types::RequestOptions)

Returns:



233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/workos/sso.rb', line 233

def create_connection_saml_sp_encryption_cert(
  connection_id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_sp_encryption_certs",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::SAMLSpEncryptionCertificate.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_connection_saml_sp_signing_cert(connection_id:, request_options: {}) ⇒ WorkOS::SAMLSpSigningCertificate

Create an SP signing certificate

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

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

    (see WorkOS::Types::RequestOptions)

Returns:



290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/workos/sso.rb', line 290

def create_connection_saml_sp_signing_cert(
  connection_id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_sp_signing_cert",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::SAMLSpSigningCertificate.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

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

This method returns an undefined value.

Delete a Connection

Parameters:

  • id (String) —

    Unique identifier for the Connection.

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

    (see WorkOS::Types::RequestOptions)



393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/workos/sso.rb', line 393

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

#delete_connection_saml_idp_signing_cert(connection_id:, certificate_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an IdP signing certificate

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

  • certificate_id (String) —

    Unique identifier for the Identity Provider signing certificate.

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

    (see WorkOS::Types::RequestOptions)



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/workos/sso.rb', line 196

def delete_connection_saml_idp_signing_cert(
  connection_id:,
  certificate_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_idp_signing_certs/#{WorkOS::Util.encode_path(certificate_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_connection_saml_sp_encryption_cert(connection_id:, certificate_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an SP encryption certificate

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

  • certificate_id (String) —

    Unique identifier for the Service Provider encryption key pair. WorkOS holds the corresponding private key, which is never exposed.

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

    (see WorkOS::Types::RequestOptions)



253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/workos/sso.rb', line 253

def delete_connection_saml_sp_encryption_cert(
  connection_id:,
  certificate_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_sp_encryption_certs/#{WorkOS::Util.encode_path(certificate_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_connection_saml_sp_signing_cert(connection_id:, certificate_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete the SP signing certificate

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

  • certificate_id (String) —

    Unique identifier for the Service Provider signing key pair. WorkOS holds the corresponding private key, which is never exposed.

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

    (see WorkOS::Types::RequestOptions)



310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/workos/sso.rb', line 310

def delete_connection_saml_sp_signing_cert(
  connection_id:,
  certificate_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_sp_signing_cert/#{WorkOS::Util.encode_path(certificate_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#get_authorization_url(redirect_uri:, provider_scopes: nil, provider_query_params: nil, client_id: nil, domain: nil, provider: nil, state: nil, connection: nil, organization: nil, domain_hint: nil, login_hint: nil, nonce: nil, prompt: nil) ⇒ String

Initiate SSO Builds the URL client-side; no HTTP request is made.

Parameters:

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

    Additional scopes to request from the identity provider. Applicable when using OAuth or OpenID Connect connections.

  • provider_query_params (Hash{String => String}, nil) (defaults to: nil) —

    Key/value pairs of query parameters to pass to the OAuth provider. Only applicable when using OAuth connections.

  • client_id (String, nil) (defaults to: nil) —

    The unique identifier of the WorkOS environment client. Defaults to the client's configured client_id.

  • domain (String, nil) (defaults to: nil) —

    Deprecated. Use connection or organization instead. Used to initiate SSO for a connection by domain. The domain must be associated with a connection in your WorkOS environment.

  • provider (WorkOS::Types::SSOProvider, nil) (defaults to: nil) —

    Used to initiate OAuth authentication with various providers.

  • redirect_uri (String) —

    Where to redirect the user after they complete the authentication process. You must use one of the redirect URIs configured via the Redirects page on the dashboard.

  • state (String, nil) (defaults to: nil) —

    An optional parameter that can be used to encode arbitrary information to help restore application state between redirects. If included, the redirect URI received from WorkOS will contain the exact state that was passed.

  • connection (String, nil) (defaults to: nil) —

    Used to initiate SSO for a connection. The value should be a WorkOS connection ID. You can persist the WorkOS connection ID with application user or team identifiers. WorkOS will use the connection indicated by the connection parameter to direct the user to the corresponding IdP for authentication.

  • organization (String, nil) (defaults to: nil) —

    Used to initiate SSO for an organization. The value should be a WorkOS organization ID. You can persist the WorkOS organization ID with application user or team identifiers. WorkOS will use the organization ID to determine the appropriate connection and the IdP to direct the user to for authentication.

  • domain_hint (String, nil) (defaults to: nil) —

    Can be used to pre-fill the domain field when initiating authentication with Microsoft OAuth or with a Google SAML connection type.

  • login_hint (String, nil) (defaults to: nil) —

    Can be used to pre-fill the username/email address field of the IdP sign-in page for the user, if you know their username ahead of time. Currently supported for OAuth, OpenID Connect, Okta, Entra ID, and custom SAML connections.

  • nonce (String, nil) (defaults to: nil) —

    A random string generated by the client that is used to mitigate replay attacks.

  • prompt (String, nil) (defaults to: nil) —

    If set to login, forces re-authentication at the identity provider. For supported SAML providers this sets ForceAuthn="true" in the SAML request; providers that don't support it are unaffected.

Returns:

  • (String)


422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/workos/sso.rb', line 422

def get_authorization_url(
  redirect_uri:,
  provider_scopes: nil,
  provider_query_params: nil,
  client_id: nil,
  domain: nil,
  provider: nil,
  state: nil,
  connection: nil,
  organization: nil,
  domain_hint: nil,
  login_hint: nil,
  nonce: nil,
  prompt: nil
)
  params = {
    "provider_scopes" => provider_scopes,
    "provider_query_params" => provider_query_params,
    "client_id" => client_id,
    "domain" => domain,
    "provider" => provider,
    "redirect_uri" => redirect_uri,
    "state" => state,
    "connection" => connection,
    "organization" => organization,
    "domain_hint" => domain_hint,
    "login_hint" => ,
    "nonce" => nonce,
    "prompt" => prompt
  }.compact
  params["provider_scopes"] = provider_scopes.join(",") unless provider_scopes.nil?
  params["provider_query_params"] = JSON.generate(provider_query_params) unless provider_query_params.nil?
  params["response_type"] = "code"
  params["client_id"] = @client.client_id if !params.key?("client_id") && !@client.client_id.nil?
  uri = URI.join(@client.base_url, "/sso/authorize")
  uri.query = URI.encode_www_form(params) unless params.empty?
  uri.to_s
end

#get_authorization_url_with_pkce(redirect_uri:, client_id: nil, **opts) ⇒ Object

H15 — SSO authorization URL with auto-generated PKCE pair + state. Returns [url, code_verifier, state].



558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/workos/sso.rb', line 558

def get_authorization_url_with_pkce(redirect_uri:, client_id: nil, **opts)
  pair = WorkOS::PKCE.generate_pair
  state = opts.delete(:state) || WorkOS::PKCE.generate_code_verifier
  url = get_authorization_url(
    redirect_uri: redirect_uri,
    client_id: client_id,
    state: state,
    **opts
  )
  url = append_query(url, {"code_challenge" => pair[:code_challenge], "code_challenge_method" => "S256"})
  [url, pair[:code_verifier], state]
end

#get_connection(id:, request_options: {}) ⇒ WorkOS::Connection

Get a Connection

Parameters:

  • id (String) —

    Unique identifier for the Connection.

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

    (see WorkOS::Types::RequestOptions)

Returns:



328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/workos/sso.rb', line 328

def get_connection(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/connections/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Connection.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

#get_logout_url(token:) ⇒ String

Logout Redirect Builds the URL client-side; no HTTP request is made.

Parameters:

  • token (String) —

    The logout token returned from the Logout Authorize endpoint.

Returns:

  • (String)


465
466
467
468
469
470
471
472
# File 'lib/workos/sso.rb', line 465

def get_logout_url(token:)
  params = {
    "token" => token
  }
  uri = URI.join(@client.base_url, "/sso/logout")
  uri.query = URI.encode_www_form(params) unless params.empty?
  uri.to_s
end

#get_profile(request_options: {}) ⇒ WorkOS::Profile

Get a User Profile

Parameters:

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

    (see WorkOS::Types::RequestOptions)

Returns:



500
501
502
503
504
505
506
507
508
509
510
# File 'lib/workos/sso.rb', line 500

def get_profile(request_options: {})
  response = @client.request(
    method: :get,
    path: "/sso/profile",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Profile.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

#get_profile_and_token(code: nil, code_verifier: nil, subject_token: nil, subject_token_type: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::SSOTokenResponse

Get a Profile and Token

Parameters:

  • code (String, nil) (defaults to: nil) —

    The authorization code received from the authorization callback. Required when grant_type is authorization_code.

  • code_verifier (String, nil) (defaults to: nil) —

    The PKCE code verifier matching the code_challenge sent with the authorization request. Required when the authorization request included a code_challenge. Must be sent in the request body.

  • subject_token (String, nil) (defaults to: nil) —

    The OIDC ID token to exchange. Required when grant_type is urn:ietf:params:oauth:grant-type:token-exchange. Must be sent in the request body.

  • subject_token_type (String, nil) (defaults to: nil) —

    The type of the subject token. Required when grant_type is urn:ietf:params:oauth:grant-type:token-exchange. Must be sent in the request body.

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

    The ID of the organization whose connection the subject token is validated against. Required when grant_type is urn:ietf:params:oauth:grant-type:token-exchange. Must be sent in the request body.

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

    (see WorkOS::Types::RequestOptions)

Returns:



520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/workos/sso.rb', line 520

def get_profile_and_token(
  code: nil,
  code_verifier: nil,
  subject_token: nil,
  subject_token_type: nil,
  organization_id: nil,
  request_options: {}
)
  body = {
    "grant_type" => "authorization_code",
    "client_id" => request_options[:client_id] || @client.client_id,
    "client_secret" => request_options[:api_key] || @client.api_key,
    "code" => code,
    "code_verifier" => code_verifier,
    "subject_token" => subject_token,
    "subject_token_type" => subject_token_type,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/sso/token",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::SSOTokenResponse.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

#get_profile_and_token_with_pkce(code:, code_verifier:, client_id: nil, request_options: {}) ⇒ Object

H16 — Exchange an SSO authorization code for a profile/token, with PKCE support for public clients (no client_secret).

Raises:

  • (ArgumentError)


573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/workos/sso.rb', line 573

def get_profile_and_token_with_pkce(code:, code_verifier:, client_id: nil, request_options: {})
  cid = client_id || @client.client_id
  raise ArgumentError, "client_id is required" if cid.nil? || cid.empty?
  body = {
    "grant_type" => "authorization_code",
    "client_id" => cid,
    "code" => code,
    "code_verifier" => code_verifier
  }
  response = @client.request(method: :post, path: "/sso/token", auth: false, body: body, request_options: request_options)
  WorkOS::SSOTokenResponse.new(response.body)
end

#list_connection_saml_idp_signing_certs(connection_id:, request_options: {}) ⇒ WorkOS::SAMLIdpSigningCertificateList

List IdP signing certificates

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

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

    (see WorkOS::Types::RequestOptions)

Returns:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/workos/sso.rb', line 151

def list_connection_saml_idp_signing_certs(
  connection_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_idp_signing_certs",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::SAMLIdpSigningCertificateList.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_connection_saml_sp_encryption_certs(connection_id:, request_options: {}) ⇒ WorkOS::SAMLSpEncryptionCertificateList

List SP encryption certificates

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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

def list_connection_saml_sp_encryption_certs(
  connection_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_sp_encryption_certs",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::SAMLSpEncryptionCertificateList.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_connection_saml_sp_signing_cert(connection_id:, request_options: {}) ⇒ WorkOS::SAMLSpSigningCertificate

Get the SP signing certificate

Parameters:

  • connection_id (String) —

    Unique identifier for the Connection.

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

    (see WorkOS::Types::RequestOptions)

Returns:



271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/workos/sso.rb', line 271

def list_connection_saml_sp_signing_cert(
  connection_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/connections/#{WorkOS::Util.encode_path(connection_id)}/saml_sp_signing_cert",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::SAMLSpSigningCertificate.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_connections(before: nil, after: nil, limit: 10, order: "desc", connection_type: nil, domain: nil, organization_id: nil, search: nil, state: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Connection>

List Connections

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.

  • 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.

  • 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.

  • connection_type (WorkOS::Types::ConnectionsConnectionType, nil) (defaults to: nil) —

    Filter Connections by their type.

  • domain (String, nil) (defaults to: nil) —

    Filter Connections by their associated domain.

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

    Filter Connections by their associated organization.

  • search (String, nil) (defaults to: nil) —

    Searchable text to match against Connection names.

  • state (WorkOS::Types::ConnectionsState, nil) (defaults to: nil) —

    Filter Connections by their state.

  • 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
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/workos/sso.rb', line 50

def list_connections(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  connection_type: nil,
  domain: nil,
  organization_id: nil,
  search: nil,
  state: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "connection_type" => connection_type,
    "domain" => domain,
    "organization_id" => organization_id,
    "search" => search,
    "state" => state
  }.compact
  response = @client.request(
    method: :get,
    path: "/connections",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_connections(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      connection_type: connection_type,
      domain: domain,
      organization_id: organization_id,
      search: search,
      state: state,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Connection,
    filters: {before: before, limit: limit, order: order, connection_type: connection_type, domain: domain, organization_id: organization_id, search: search, state: state},
    fetch_next: fetch_next
  )
end

#update_connection(id:, name: nil, external_id: WorkOS::OMIT, connection_type: nil, attribute_maps: nil, protocol_options: nil, request_options: {}) ⇒ WorkOS::Connection

Update a Connection

Parameters:

  • id (String) —

    Unique identifier for the Connection.

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

    A human-readable name for the Connection.

  • external_id (String, nil) (defaults to: WorkOS::OMIT) —

    The customer-owned identifier for the Connection. Set to null to stop tracking one.

  • connection_type (String, nil) (defaults to: nil) —

    The type of the Connection. Immutable after creation — it may be sent, but only with the Connection current type.

  • attribute_maps (WorkOS::PatchConnectionAttributeMaps, nil) (defaults to: nil) —

    How IdP attributes or claims map onto WorkOS profile fields. Only the provided fields are updated.

  • protocol_options (WorkOS::SSO::PatchProtocolOptionsSAML, WorkOS::SSO::PatchProtocolOptionsOIDC, nil) (defaults to: nil) —

    Identifies the protocol options.

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

    (see WorkOS::Types::RequestOptions)

Returns:



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/workos/sso.rb', line 352

def update_connection(
  id:,
  name: nil,
  external_id: WorkOS::OMIT,
  connection_type: nil,
  attribute_maps: nil,
  protocol_options: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "connection_type" => connection_type,
    "attribute_maps" => attribute_maps
  }.compact
  body["external_id"] = external_id unless external_id.equal?(WorkOS::OMIT)
  if protocol_options
    case protocol_options
    when WorkOS::SSO::PatchProtocolOptionsSAML
      body["saml_options"] = protocol_options.saml_options
    when WorkOS::SSO::PatchProtocolOptionsOIDC
      body["oidc_options"] = protocol_options.oidc_options
    else
      raise ArgumentError, "expected protocol_options to be one of: WorkOS::SSO::PatchProtocolOptionsSAML, WorkOS::SSO::PatchProtocolOptionsOIDC, got #{protocol_options.class}"
    end
  end
  response = @client.request(
    method: :patch,
    path: "/connections/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Connection.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