Class: WorkOS::UserManagement

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

Defined Under Namespace

Classes: PasswordHashed, PasswordPlaintext

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ UserManagement

Returns a new instance of UserManagement.



30
31
32
# File 'lib/workos/user_management.rb', line 30

def initialize(client)
  @client = client
end

Instance Method Details

#accept_invitation(id:, request_options: {}) ⇒ WorkOS::Invitation

Accept an invitation

Parameters:

  • id (String)

    The unique ID of the invitation.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'lib/workos/user_management.rb', line 1385

def accept_invitation(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/user_management/invitations/#{WorkOS::Util.encode_path(id)}/accept",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Invitation.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

#authenticate_with_code(code:, code_verifier: nil, invitation_token: nil, ip_address: nil, device_id: nil, user_agent: nil, signals_id: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with code.

Parameters:

  • code (String)
  • code_verifier (String, nil) (defaults to: nil)
  • invitation_token (String, nil) (defaults to: nil)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • signals_id (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/workos/user_management.rb', line 191

def authenticate_with_code(
  code:,
  code_verifier: nil,
  invitation_token: nil,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  signals_id: nil,
  request_options: {}
)
  body = {
    "grant_type" => "authorization_code",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "code" => code,
    "code_verifier" => code_verifier,
    "invitation_token" => invitation_token,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent,
    "signals_id" => signals_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_code_pkce(code:, code_verifier:, client_id: nil, ip_address: nil, user_agent: nil, request_options: {}) ⇒ Object

H11 — Exchange a code for tokens with PKCE support (public client; no secret). NOTE: Unlike the other authenticate_with_* helpers, this does NOT delegate to create_authenticate because PKCE is a public-client flow that requires auth: false (no Bearer token / API key in the Authorization header).

Raises:

  • (ArgumentError)


1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
# File 'lib/workos/user_management.rb', line 1816

def authenticate_with_code_pkce(code:, code_verifier:, client_id: nil, ip_address: nil, user_agent: 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,
    "ip_address" => ip_address,
    "user_agent" => user_agent
  }.compact
  response = @client.request(method: :post, path: "/user_management/authenticate", auth: false, body: body, request_options: request_options)
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_device_code(device_code:, ip_address: nil, device_id: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with device code.

Parameters:

  • device_code (String)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/workos/user_management.rb', line 419

def authenticate_with_device_code(
  device_code:,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "grant_type" => "urn:ietf:params:oauth:grant-type:device_code",
    "client_id" => @client.client_id,
    "device_code" => device_code,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_email_verification(code:, pending_authentication_token:, ip_address: nil, device_id: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with email verification.

Parameters:

  • code (String)
  • pending_authentication_token (String)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/workos/user_management.rb', line 309

def authenticate_with_email_verification(
  code:,
  pending_authentication_token:,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "grant_type" => "urn:workos:oauth:grant-type:email-verification:code",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "code" => code,
    "pending_authentication_token" => pending_authentication_token,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_magic_auth(code:, email:, invitation_token: nil, ip_address: nil, device_id: nil, user_agent: nil, radar_auth_attempt_id: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with magic auth.

Parameters:

  • code (String)
  • email (String)
  • invitation_token (String, nil) (defaults to: nil)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • radar_auth_attempt_id (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/workos/user_management.rb', line 269

def authenticate_with_magic_auth(
  code:,
  email:,
  invitation_token: nil,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  radar_auth_attempt_id: nil,
  request_options: {}
)
  body = {
    "grant_type" => "urn:workos:oauth:grant-type:magic-auth:code",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "code" => code,
    "email" => email,
    "invitation_token" => invitation_token,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent,
    "radar_auth_attempt_id" => radar_auth_attempt_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_organization_selection(pending_authentication_token:, organization_id:, ip_address: nil, device_id: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with organization selection.

Parameters:

  • pending_authentication_token (String)
  • organization_id (String)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/workos/user_management.rb', line 384

def authenticate_with_organization_selection(
  pending_authentication_token:,
  organization_id:,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "grant_type" => "urn:workos:oauth:grant-type:organization-selection",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "pending_authentication_token" => pending_authentication_token,
    "organization_id" => organization_id,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_password(email:, password:, invitation_token: nil, ip_address: nil, device_id: nil, user_agent: nil, signals_id: nil, radar_auth_attempt_id: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with password.

Parameters:

  • email (String)
  • password (String)
  • invitation_token (String, nil) (defaults to: nil)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • signals_id (String, nil) (defaults to: nil)
  • radar_auth_attempt_id (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



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
173
174
175
176
177
178
179
# File 'lib/workos/user_management.rb', line 147

def authenticate_with_password(
  email:,
  password:,
  invitation_token: nil,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  signals_id: nil,
  radar_auth_attempt_id: nil,
  request_options: {}
)
  body = {
    "grant_type" => "password",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "email" => email,
    "password" => password,
    "invitation_token" => invitation_token,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent,
    "signals_id" => signals_id,
    "radar_auth_attempt_id" => radar_auth_attempt_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_radar_email_challenge(code:, radar_challenge_id:, pending_authentication_token:, ip_address: nil, device_id: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with radar email challenge.

Parameters:

  • code (String)
  • radar_challenge_id (String)
  • pending_authentication_token (String)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/workos/user_management.rb', line 453

def authenticate_with_radar_email_challenge(
  code:,
  radar_challenge_id:,
  pending_authentication_token:,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "grant_type" => "urn:workos:oauth:grant-type:radar-email-challenge:code",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "code" => code,
    "radar_challenge_id" => radar_challenge_id,
    "pending_authentication_token" => pending_authentication_token,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_radar_sms_challenge(code:, pending_authentication_token:, verification_id: nil, phone_number: nil, ip_address: nil, device_id: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with radar sms challenge.

Parameters:

  • code (String)
  • verification_id (String, nil) (defaults to: nil)
  • phone_number (String, nil) (defaults to: nil)
  • pending_authentication_token (String)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/workos/user_management.rb', line 493

def authenticate_with_radar_sms_challenge(
  code:,
  pending_authentication_token:,
  verification_id: nil,
  phone_number: nil,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "grant_type" => "urn:workos:oauth:grant-type:radar-sms-challenge:code",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "code" => code,
    "verification_id" => verification_id,
    "phone_number" => phone_number,
    "pending_authentication_token" => pending_authentication_token,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_refresh_token(refresh_token:, organization_id: nil, ip_address: nil, device_id: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with refresh token.

Parameters:

  • refresh_token (String)
  • organization_id (String, nil) (defaults to: nil)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



231
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
257
# File 'lib/workos/user_management.rb', line 231

def authenticate_with_refresh_token(
  refresh_token:,
  organization_id: nil,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "grant_type" => "refresh_token",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "refresh_token" => refresh_token,
    "organization_id" => organization_id,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authenticate_with_totp(code:, pending_authentication_token:, authentication_challenge_id:, ip_address: nil, device_id: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate with totp.

Parameters:

  • code (String)
  • pending_authentication_token (String)
  • authentication_challenge_id (String)
  • ip_address (String, nil) (defaults to: nil)
  • device_id (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    Per-request overrides.

Returns:



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/workos/user_management.rb', line 346

def authenticate_with_totp(
  code:,
  pending_authentication_token:,
  authentication_challenge_id:,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "grant_type" => "urn:workos:oauth:grant-type:mfa-totp",
    "client_id" => @client.client_id,
    "client_secret" => @client.api_key,
    "code" => code,
    "pending_authentication_token" => pending_authentication_token,
    "authentication_challenge_id" => authentication_challenge_id,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::AuthenticateResponse.new(response.body)
end

#authorize_device(client_id: nil, request_options: {}) ⇒ WorkOS::DeviceAuthorizationResponse

H12 — Initiate the OAuth 2.0 device authorization flow.

Returns:

Raises:

  • (ArgumentError)


1833
1834
1835
1836
1837
1838
1839
# File 'lib/workos/user_management.rb', line 1833

def authorize_device(client_id: nil, request_options: {})
  cid = client_id || @client.client_id
  raise ArgumentError, "client_id is required" if cid.nil? || cid.empty?
  body = {"client_id" => cid}
  response = @client.request(method: :post, path: "/oauth2/device_authorization", auth: false, body: body, request_options: request_options)
  WorkOS::DeviceAuthorizationResponse.new(response.body)
end

#confirm_email_change(id:, code:, request_options: {}) ⇒ WorkOS::EmailChangeConfirmation

Confirm email change

Parameters:

  • id (String)

    The unique ID of the user.

  • code (String)

    The one-time code used to confirm the email change.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
# File 'lib/workos/user_management.rb', line 1099

def confirm_email_change(
  id:,
  code:,
  request_options: {}
)
  body = {
    "code" => code
  }
  response = @client.request(
    method: :post,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}/email_change/confirm",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::EmailChangeConfirmation.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

#confirm_password_reset(token:, new_password:, request_options: {}) ⇒ WorkOS::ResetPasswordResponse

Reset the password

Parameters:

  • token (String)

    The password reset token.

  • new_password (String)

    The new password to set for the user.

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

    (see WorkOS::Types::RequestOptions)

Returns:



819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
# File 'lib/workos/user_management.rb', line 819

def confirm_password_reset(
  token:,
  new_password:,
  request_options: {}
)
  body = {
    "token" => token,
    "new_password" => new_password
  }
  response = @client.request(
    method: :post,
    path: "/user_management/password_reset/confirm",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ResetPasswordResponse.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_authenticate(client_id:, grant_type:, client_secret: nil, code: nil, code_verifier: nil, invitation_token: nil, ip_address: nil, device_id: nil, user_agent: nil, signals_id: nil, email: nil, password: nil, radar_auth_attempt_id: nil, refresh_token: nil, organization_id: nil, pending_authentication_token: nil, authentication_challenge_id: nil, radar_challenge_id: nil, verification_id: nil, phone_number: nil, device_code: nil, request_options: {}) ⇒ WorkOS::AuthenticateResponse

Authenticate

Parameters:

  • client_id (String)

    The client ID of the application.

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

    The client secret of the application. May be omitted by public clients that authenticate through other means, such as a PKCE code_verifier.

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

    The authorization code received from the redirect.

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

    The PKCE code verifier used to derive the code challenge passed to the authorization URL.

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

    An invitation token to accept during authentication.

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

    The IP address of the user's request.

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

    A unique identifier for the device.

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

    The user agent string from the user's browser.

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

    An optional Radar signals ID to correlate client-side signals with this authentication attempt.

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

    The user's email address.

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

    The user's password.

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

    The ID of an existing Radar authentication attempt to associate with this authentication.

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

    The refresh token to exchange for new tokens.

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

    The ID of the organization to scope the session to.

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

    The pending authentication token from a previous authentication attempt.

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

    The ID of the MFA authentication challenge.

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

    The ID of the Radar email challenge being verified.

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

    The ID of the Radar SMS verification being confirmed. Required for sign-up challenges; omitted for sign-in challenges, where the verification is resolved server-side.

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

    The phone number the Radar SMS challenge was sent to. Required for sign-up challenges; omitted for sign-in challenges, where the phone number on file is resolved server-side.

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

    The device verification code.

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

    (see WorkOS::Types::RequestOptions)

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
133
134
# File 'lib/workos/user_management.rb', line 77

def create_authenticate(
  client_id:,
  grant_type:,
  client_secret: nil,
  code: nil,
  code_verifier: nil,
  invitation_token: nil,
  ip_address: nil,
  device_id: nil,
  user_agent: nil,
  signals_id: nil,
  email: nil,
  password: nil,
  radar_auth_attempt_id: nil,
  refresh_token: nil,
  organization_id: nil,
  pending_authentication_token: nil,
  authentication_challenge_id: nil,
  radar_challenge_id: nil,
  verification_id: nil,
  phone_number: nil,
  device_code: nil,
  request_options: {}
)
  body = {
    "client_id" => client_id,
    "client_secret" => client_secret,
    "grant_type" => grant_type,
    "code" => code,
    "code_verifier" => code_verifier,
    "invitation_token" => invitation_token,
    "ip_address" => ip_address,
    "device_id" => device_id,
    "user_agent" => user_agent,
    "signals_id" => signals_id,
    "email" => email,
    "password" => password,
    "radar_auth_attempt_id" => radar_auth_attempt_id,
    "refresh_token" => refresh_token,
    "organization_id" => organization_id,
    "pending_authentication_token" => pending_authentication_token,
    "authentication_challenge_id" => authentication_challenge_id,
    "radar_challenge_id" => radar_challenge_id,
    "verification_id" => verification_id,
    "phone_number" => phone_number,
    "device_code" => device_code
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/authenticate",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuthenticateResponse.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_cors_origin(origin:, request_options: {}) ⇒ WorkOS::CORSOriginResponse

Create a CORS origin

Parameters:

  • origin (String)

    The origin URL to allow for CORS requests.

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

    (see WorkOS::Types::RequestOptions)

Returns:



753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/workos/user_management.rb', line 753

def create_cors_origin(
  origin:,
  request_options: {}
)
  body = {
    "origin" => origin
  }
  response = @client.request(
    method: :post,
    path: "/user_management/cors_origins",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::CORSOriginResponse.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_device(client_id:, request_options: {}) ⇒ WorkOS::DeviceAuthorizationResponse

Get device authorization URL

Parameters:

  • client_id (String)

    The WorkOS client ID for your application.

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

    (see WorkOS::Types::RequestOptions)

Returns:



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/workos/user_management.rb', line 593

def create_device(
  client_id:,
  request_options: {}
)
  body = {
    "client_id" => client_id
  }
  response = @client.request(
    method: :post,
    path: "/user_management/authorize/device",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DeviceAuthorizationResponse.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_magic_auth(email:, invitation_token: nil, ip_address: nil, user_agent: nil, radar_auth_attempt_id: nil, signals_id: nil, request_options: {}) ⇒ WorkOS::MagicAuthSendMagicAuthCodeAndReturnResponse

Create a Magic Auth code

Parameters:

  • email (String)

    The email address to send the magic code to.

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

    The invitation token to associate with this magic code.

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

    The IP address of the user's request.

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

    The user agent string from the user's request.

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

    The ID of an existing Radar authentication attempt to associate with this request.

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

    An optional Radar signals ID to correlate client-side signals with this request.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
# File 'lib/workos/user_management.rb', line 1491

def create_magic_auth(
  email:,
  invitation_token: nil,
  ip_address: nil,
  user_agent: nil,
  radar_auth_attempt_id: nil,
  signals_id: nil,
  request_options: {}
)
  body = {
    "email" => email,
    "invitation_token" => invitation_token,
    "ip_address" => ip_address,
    "user_agent" => user_agent,
    "radar_auth_attempt_id" => radar_auth_attempt_id,
    "signals_id" => signals_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/magic_auth",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::MagicAuthSendMagicAuthCodeAndReturnResponse.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_radar_challenge(user_id:, pending_authentication_token:, phone_number:, ip_address: nil, user_agent: nil, request_options: {}) ⇒ WorkOS::SendRadarSmsChallengeResponse

Send a Radar SMS challenge

Parameters:

  • user_id (String)

    The ID of the user to send the SMS challenge to.

  • pending_authentication_token (String)

    The pending authentication token from a previous authentication attempt that triggered the Radar challenge.

  • phone_number (String)

    The phone number to send the SMS verification code to.

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

    The IP address of the user's request.

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

    The user agent string from the user's request.

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

    (see WorkOS::Types::RequestOptions)

Returns:



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/workos/user_management.rb', line 620

def create_radar_challenge(
  user_id:,
  pending_authentication_token:,
  phone_number:,
  ip_address: nil,
  user_agent: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "pending_authentication_token" => pending_authentication_token,
    "phone_number" => phone_number,
    "ip_address" => ip_address,
    "user_agent" => user_agent
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/radar_challenges",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::SendRadarSmsChallengeResponse.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_redirect_uri(uri:, request_options: {}) ⇒ WorkOS::RedirectUri

Create a redirect URI

Parameters:

  • uri (String)

    The redirect URI to create.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
# File 'lib/workos/user_management.rb', line 1587

def create_redirect_uri(
  uri:,
  request_options: {}
)
  body = {
    "uri" => uri
  }
  response = @client.request(
    method: :post,
    path: "/user_management/redirect_uris",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::RedirectUri.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_user(email:, first_name: WorkOS::OMIT, last_name: WorkOS::OMIT, name: WorkOS::OMIT, email_verified: WorkOS::OMIT, metadata: WorkOS::OMIT, external_id: WorkOS::OMIT, ip_address: WorkOS::OMIT, user_agent: WorkOS::OMIT, signals_id: nil, password: nil, request_options: {}) ⇒ WorkOS::UserCreateResponse

Create a user

Parameters:

  • email (String)

    The email address of the user.

  • first_name (String, nil) (defaults to: WorkOS::OMIT)

    The first name of the user.

  • last_name (String, nil) (defaults to: WorkOS::OMIT)

    The last name of the user.

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

    The user's full name.

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

    Whether the user's email has been verified.

  • metadata (Hash{String => String}, nil) (defaults to: WorkOS::OMIT)

    Object containing metadata key/value pairs associated with the user.

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

    The external ID of the user.

  • ip_address (String, nil) (defaults to: WorkOS::OMIT)

    The IP address of the user's request.

  • user_agent (String, nil) (defaults to: WorkOS::OMIT)

    The user agent string from the user's request.

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

    An optional Radar signals ID to correlate client-side signals with this request.

  • password (WorkOS::UserManagement::PasswordPlaintext, WorkOS::UserManagement::PasswordHashed, nil) (defaults to: nil)

    Identifies the password.

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

    (see WorkOS::Types::RequestOptions)

Returns:



929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
# File 'lib/workos/user_management.rb', line 929

def create_user(
  email:,
  first_name: WorkOS::OMIT,
  last_name: WorkOS::OMIT,
  name: WorkOS::OMIT,
  email_verified: WorkOS::OMIT,
  metadata: WorkOS::OMIT,
  external_id: WorkOS::OMIT,
  ip_address: WorkOS::OMIT,
  user_agent: WorkOS::OMIT,
  signals_id: nil,
  password: nil,
  request_options: {}
)
  body = {
    "email" => email,
    "signals_id" => signals_id
  }.compact
  body["first_name"] = first_name unless first_name.equal?(WorkOS::OMIT)
  body["last_name"] = last_name unless last_name.equal?(WorkOS::OMIT)
  body["name"] = name unless name.equal?(WorkOS::OMIT)
  body["email_verified"] = email_verified unless email_verified.equal?(WorkOS::OMIT)
  body["metadata"] =  unless .equal?(WorkOS::OMIT)
  body["external_id"] = external_id unless external_id.equal?(WorkOS::OMIT)
  body["ip_address"] = ip_address unless ip_address.equal?(WorkOS::OMIT)
  body["user_agent"] = user_agent unless user_agent.equal?(WorkOS::OMIT)
  if password
    case password
    when WorkOS::UserManagement::PasswordPlaintext
      body["password"] = password.password
    when WorkOS::UserManagement::PasswordHashed
      body["password_hash"] = password.password_hash
      body["password_hash_type"] = password.password_hash_type
      body["password_salt_position"] = password.password_salt_position unless password.password_salt_position.nil?
    else
      raise ArgumentError, "expected password to be one of: WorkOS::UserManagement::PasswordPlaintext, WorkOS::UserManagement::PasswordHashed, got #{password.class}"
    end
  end
  response = @client.request(
    method: :post,
    path: "/user_management/users",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::UserCreateResponse.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_user_api_key(user_id:, name:, organization_id:, permissions: nil, expires_at: nil, request_options: {}) ⇒ WorkOS::UserApiKeyWithValue

Create an API key for a user

Parameters:

  • user_id (String)

    Unique identifier of the user.

  • name (String)

    A descriptive name for the API key.

  • organization_id (String)

    The ID of the organization the user API key is associated with. The user must have an active membership in this organization.

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

    The permission slugs to assign to the API key. Each permission must be enabled for user API keys.

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

    The timestamp when the API key should expire. Must be a future timestamp. If omitted, the key does not expire.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
# File 'lib/workos/user_management.rb', line 1748

def create_user_api_key(
  user_id:,
  name:,
  organization_id:,
  permissions: nil,
  expires_at: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "organization_id" => organization_id,
    "permissions" => permissions,
    "expires_at" => expires_at
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/api_keys",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::UserApiKeyWithValue.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_redirect_uris(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a redirect URI

Parameters:

  • id (String)

    The ID of the redirect URI to delete.

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

    (see WorkOS::Types::RequestOptions)



1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
# File 'lib/workos/user_management.rb', line 1610

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

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

This method returns an undefined value.

Delete a user

Parameters:

  • id (String)

    The unique ID of the user.

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

    (see WorkOS::Types::RequestOptions)



1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
# File 'lib/workos/user_management.rb', line 1081

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

#delete_user_authorized_application(application_id:, user_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an authorized application

Parameters:

  • application_id (String)

    The ID or client ID of the application.

  • user_id (String)

    The ID of the user.

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

    (see WorkOS::Types::RequestOptions)



1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
# File 'lib/workos/user_management.rb', line 1675

def delete_user_authorized_application(
  application_id:,
  user_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/authorized_applications/#{WorkOS::Util.encode_path(application_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#find_invitation_by_token(token:, request_options: {}) ⇒ WorkOS::UserInvite

Find an invitation by token

Parameters:

  • token (String)

    The token used to accept the invitation.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
# File 'lib/workos/user_management.rb', line 1347

def find_invitation_by_token(
  token:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/invitations/by_token/#{WorkOS::Util.encode_path(token)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::UserInvite.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_authorization_url(redirect_uri:, code_challenge_method: nil, code_challenge: nil, domain_hint: nil, connection_id: nil, provider_query_params: nil, provider_scopes: nil, invitation_token: nil, max_age: nil, screen_hint: nil, login_hint: nil, provider: nil, prompt: nil, state: nil, organization_id: nil, client_id: nil) ⇒ String

Get an authorization URL Builds the URL client-side; no HTTP request is made.

Parameters:

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

    The only valid PKCE code challenge method is "S256". Required when specifying a code_challenge.

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

    Code challenge derived from the code verifier used for the PKCE flow.

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

    A domain hint for SSO connection lookup.

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

    The ID of an SSO connection to use for authentication.

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

    Key/value pairs of query parameters to pass to the OAuth provider.

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

    Additional OAuth scopes to request from the identity provider.

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

    A token representing a user invitation to redeem during authentication.

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

    Maximum allowable elapsed time, in seconds, since the user last actively authenticated. If the last authentication is older than this value, the user is prompted to re-authenticate; a value of 0 forces re-authentication. Only supported when the provider is authkit.

  • screen_hint (WorkOS::Types::UserManagementAuthenticationScreenHint, nil) (defaults to: nil)

    Used to specify which screen to display when the provider is authkit.

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

    A hint to the authorization server about the login identifier the user might use.

  • provider (WorkOS::Types::UserManagementAuthenticationProvider, nil) (defaults to: nil)

    The OAuth provider to authenticate with (e.g., GoogleOAuth, MicrosoftOAuth, GitHubOAuth).

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

    Controls the authentication flow behavior for the user.

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

    An opaque value used to maintain state between the request and the callback.

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

    The ID of the organization to authenticate the user against.

  • redirect_uri (String)

    The callback URI where the authorization code will be sent after authentication.

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

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

Returns:

  • (String)


544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/workos/user_management.rb', line 544

def get_authorization_url(
  redirect_uri:,
  code_challenge_method: nil,
  code_challenge: nil,
  domain_hint: nil,
  connection_id: nil,
  provider_query_params: nil,
  provider_scopes: nil,
  invitation_token: nil,
  max_age: nil,
  screen_hint: nil,
  login_hint: nil,
  provider: nil,
  prompt: nil,
  state: nil,
  organization_id: nil,
  client_id: nil
)
  params = {
    "code_challenge_method" => code_challenge_method,
    "code_challenge" => code_challenge,
    "domain_hint" => domain_hint,
    "connection_id" => connection_id,
    "provider_query_params" => provider_query_params,
    "provider_scopes" => provider_scopes,
    "invitation_token" => invitation_token,
    "max_age" => max_age,
    "screen_hint" => screen_hint,
    "login_hint" => ,
    "provider" => provider,
    "prompt" => prompt,
    "state" => state,
    "organization_id" => organization_id,
    "redirect_uri" => redirect_uri,
    "client_id" => client_id
  }.compact
  params["provider_query_params"] = JSON.generate(provider_query_params) unless provider_query_params.nil?
  params["provider_scopes"] = provider_scopes.join(",") unless provider_scopes.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, "/user_management/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

H10 — AuthKit authorization URL with auto-generated PKCE + state. Returns [url, code_verifier, state].



1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
# File 'lib/workos/user_management.rb', line 1791

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
  # Strip caller-supplied PKCE params: this helper exists specifically
  # to generate them, so a caller-provided value would either silently
  # override our freshly-generated challenge (defeating the helper) or
  # collide with the keyword args below and raise. Mirror the existing
  # opts.delete(:state) pattern.
  opts.delete(:code_challenge)
  opts.delete(:code_challenge_method)
  url = get_authorization_url(
    redirect_uri: redirect_uri,
    client_id: client_id,
    state: state,
    code_challenge: pair[:code_challenge],
    code_challenge_method: "S256",
    **opts
  )
  [url, pair[:code_verifier], state]
end

#get_email_verification(id:, request_options: {}) ⇒ WorkOS::EmailVerification

Get an email verification code

Parameters:

  • id (String)

    The ID of the email verification code.

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

    (see WorkOS::Types::RequestOptions)

Returns:



776
777
778
779
780
781
782
783
784
785
786
787
788
789
# File 'lib/workos/user_management.rb', line 776

def get_email_verification(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/email_verification/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::EmailVerification.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_invitation(id:, request_options: {}) ⇒ WorkOS::UserInvite

Get an invitation

Parameters:

  • id (String)

    The unique ID of the invitation.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
# File 'lib/workos/user_management.rb', line 1366

def get_invitation(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/invitations/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::UserInvite.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_jwks(client_id:, request_options: {}) ⇒ WorkOS::JwksResponse

Get JWKS

Parameters:

  • client_id (String)

    Identifies the application making the request to the WorkOS server. You can obtain your client ID from the API Keys page in the dashboard.

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

    (see WorkOS::Types::RequestOptions)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/workos/user_management.rb', line 38

def get_jwks(
  client_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/sso/jwks/#{WorkOS::Util.encode_path(client_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::JwksResponse.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_jwks_url(client_id: nil) ⇒ Object

@oagen-ignore-start — non-spec helpers (hand-maintained) H13 — Build the JWKS URL for a given client_id (no HTTP call). Pair with #get_jwks (generated) to fetch the keyset.

Raises:

  • (ArgumentError)


1777
1778
1779
1780
1781
1782
# File 'lib/workos/user_management.rb', line 1777

def get_jwks_url(client_id: nil)
  cid = client_id || @client.client_id
  raise ArgumentError, "client_id is required" if cid.nil? || cid.empty?
  base = @client.base_url
  URI.join(base, "/sso/jwks/#{WorkOS::Util.encode_path(cid)}").to_s
end

#get_logout_url(session_id:, return_to: nil) ⇒ String

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

Parameters:

  • session_id (String)

    The ID of the session. This can be extracted from the sid claim of the access token.

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

    The URL to redirect the user to after logout.

Returns:

  • (String)


671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/workos/user_management.rb', line 671

def get_logout_url(
  session_id:,
  return_to: nil
)
  params = {
    "session_id" => session_id,
    "return_to" => return_to
  }.compact
  uri = URI.join(@client.base_url, "/user_management/sessions/logout")
  uri.query = URI.encode_www_form(params) unless params.empty?
  uri.to_s
end

#get_magic_auth(id:, request_options: {}) ⇒ WorkOS::MagicAuth

Get Magic Auth code details

Parameters:

  • id (String)

    The unique ID of the Magic Auth code.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
# File 'lib/workos/user_management.rb', line 1524

def get_magic_auth(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/magic_auth/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::MagicAuth.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_password_reset(id:, request_options: {}) ⇒ WorkOS::PasswordReset

Get a password reset token

Parameters:

  • id (String)

    The ID of the password reset token.

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

    (see WorkOS::Types::RequestOptions)

Returns:



844
845
846
847
848
849
850
851
852
853
854
855
856
857
# File 'lib/workos/user_management.rb', line 844

def get_password_reset(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/password_reset/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::PasswordReset.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_radar_challenge(id:, request_options: {}) ⇒ WorkOS::RadarChallenge

Get Radar Challenge details

Parameters:

  • id (String)

    The unique ID of the Radar Challenge.

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

    (see WorkOS::Types::RequestOptions)

Returns:



651
652
653
654
655
656
657
658
659
660
661
662
663
664
# File 'lib/workos/user_management.rb', line 651

def get_radar_challenge(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/radar_challenges/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::RadarChallenge.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_user(id:, request_options: {}) ⇒ WorkOS::User

Get a user

Parameters:

  • id (String)

    The unique ID of the user.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/workos/user_management.rb', line 1002

def get_user(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::User.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_user_by_external_id(external_id:, request_options: {}) ⇒ WorkOS::User

Get a user by external ID

Parameters:

  • external_id (String)

    The external ID of the user.

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

    (see WorkOS::Types::RequestOptions)

Returns:



983
984
985
986
987
988
989
990
991
992
993
994
995
996
# File 'lib/workos/user_management.rb', line 983

def get_user_by_external_id(
  external_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/users/external_id/#{WorkOS::Util.encode_path(external_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::User.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_user_identities(id:, request_options: {}) ⇒ Array<WorkOS::UserIdentitiesGetItem>

Get user identities

Parameters:

  • id (String)

    The unique ID of the user.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
# File 'lib/workos/user_management.rb', line 1192

def get_user_identities(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}/identities",
    auth: true,
    request_options: request_options
  )
  parsed = JSON.parse(response.body)
  (parsed || []).map { |item| WorkOS::UserIdentitiesGetItem.new(item) }
end

#list_cors_origins(before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::CORSOriginResponse>

List CORS origins

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/workos/user_management.rb', line 712

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

#list_invitations(before: nil, after: nil, limit: 10, order: "desc", organization_id: nil, email: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserInvite>

List invitations

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

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

    The ID of the organization that the recipient will join.

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

    The email address of the recipient.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
# File 'lib/workos/user_management.rb', line 1262

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

#list_jwt_template(request_options: {}) ⇒ WorkOS::JWTTemplateResponse

Get JWT template

Parameters:

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

    (see WorkOS::Types::RequestOptions)

Returns:



1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
# File 'lib/workos/user_management.rb', line 1447

def list_jwt_template(request_options: {})
  response = @client.request(
    method: :get,
    path: "/user_management/jwt_template",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::JWTTemplateResponse.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_redirect_uris(before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::RedirectUri>

List redirect URIs

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
# File 'lib/workos/user_management.rb', line 1546

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

#list_sessions(id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserSessionsListItem>

List sessions

Parameters:

  • id (String)

    The ID of the user.

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
# File 'lib/workos/user_management.rb', line 1214

def list_sessions(
  id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}/sessions",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_sessions(
      id: id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserSessionsListItem,
    filters: {id: id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_user_api_keys(user_id:, before: nil, after: nil, limit: 10, order: "desc", organization_id: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserApiKey>

List API keys for a user

Parameters:

  • user_id (String)

    Unique identifier of the user.

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

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

    The ID of the organization to filter user API keys by. When provided, only API keys created against that organization membership are returned.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
# File 'lib/workos/user_management.rb', line 1698

def list_user_api_keys(
  user_id:,
  before: nil,
  after: nil,
  limit: 10,
  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: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/api_keys",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_user_api_keys(
      user_id: user_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      organization_id: organization_id,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserApiKey,
    filters: {user_id: user_id, before: before, limit: limit, order: order, organization_id: organization_id},
    fetch_next: fetch_next
  )
end

#list_user_authorized_applications(user_id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuthorizedConnectApplicationListData>

List authorized applications

Parameters:

  • user_id (String)

    The ID of the user.

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
# File 'lib/workos/user_management.rb', line 1631

def list_user_authorized_applications(
  user_id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/authorized_applications",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_user_authorized_applications(
      user_id: user_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::AuthorizedConnectApplicationListData,
    filters: {user_id: user_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_users(before: nil, after: nil, limit: 10, order: "desc", organization: nil, organization_id: nil, email: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::User>

List users

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

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

    (deprecated) Filter users by the organization they are a member of. Deprecated in favor of organization_id.

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

    Filter users by the organization they are a member of.

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

    Filter users by their email address.

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

    (see WorkOS::Types::RequestOptions)

Returns:



869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
# File 'lib/workos/user_management.rb', line 869

def list_users(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  organization: nil,
  organization_id: nil,
  email: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "organization" => organization,
    "organization_id" => organization_id,
    "email" => email
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_users(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      organization: organization,
      organization_id: organization_id,
      email: email,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::User,
    filters: {before: before, limit: limit, order: order, organization: organization, organization_id: organization_id, email: email},
    fetch_next: fetch_next
  )
end

#resend_invitation(id:, locale: nil, request_options: {}) ⇒ WorkOS::UserInvite

Resend an invitation

Parameters:

Returns:



1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'lib/workos/user_management.rb', line 1405

def resend_invitation(
  id:,
  locale: nil,
  request_options: {}
)
  body = {
    "locale" => locale
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/invitations/#{WorkOS::Util.encode_path(id)}/resend",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::UserInvite.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

#reset_password(email:, request_options: {}) ⇒ WorkOS::PasswordReset

Create a password reset token

Parameters:

  • email (String)

    The email address of the user requesting a password reset.

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

    (see WorkOS::Types::RequestOptions)

Returns:



795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
# File 'lib/workos/user_management.rb', line 795

def reset_password(
  email:,
  request_options: {}
)
  body = {
    "email" => email
  }
  response = @client.request(
    method: :post,
    path: "/user_management/password_reset",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::PasswordReset.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

#revoke_invitation(id:, request_options: {}) ⇒ WorkOS::Invitation

Revoke an invitation

Parameters:

  • id (String)

    The unique ID of the invitation.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
# File 'lib/workos/user_management.rb', line 1429

def revoke_invitation(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/user_management/invitations/#{WorkOS::Util.encode_path(id)}/revoke",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Invitation.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

#revoke_session(session_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Revoke Session

Parameters:

  • session_id (String)

    The ID of the session to revoke. This can be extracted from the sid claim of the access token.

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

    (see WorkOS::Types::RequestOptions)



688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
# File 'lib/workos/user_management.rb', line 688

def revoke_session(
  session_id:,
  request_options: {}
)
  body = {
    "session_id" => session_id
  }
  @client.request(
    method: :post,
    path: "/user_management/sessions/revoke",
    auth: true,
    body: body,
    request_options: request_options
  )
  nil
end

#send_email_change(id:, new_email:, request_options: {}) ⇒ WorkOS::EmailChange

Send email change code

Parameters:

  • id (String)

    The unique ID of the user.

  • new_email (String)

    The new email address to change to.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
# File 'lib/workos/user_management.rb', line 1124

def send_email_change(
  id:,
  new_email:,
  request_options: {}
)
  body = {
    "new_email" => new_email
  }
  response = @client.request(
    method: :post,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}/email_change/send",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::EmailChange.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

#send_invitation(email:, organization_id: nil, role_slug: nil, expires_in_days: nil, inviter_user_id: nil, locale: nil, request_options: {}) ⇒ WorkOS::UserInvite

Send an invitation

Parameters:

  • email (String)

    The email address of the recipient.

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

    The ID of the organization that the recipient will join.

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

    The role that the recipient will receive when they join the organization in the invitation.

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

    How many days the invitations will be valid for. Must be between 1 and 30 days. Defaults to 7 days if not specified.

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

    The ID of the user who invites the recipient. The invitation email will mention the name of this user.

  • locale (WorkOS::Types::CreateUserInviteOptionsLocale, nil) (defaults to: nil)

    The locale to use when rendering the invitation email. See supported locales.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
# File 'lib/workos/user_management.rb', line 1314

def send_invitation(
  email:,
  organization_id: nil,
  role_slug: nil,
  expires_in_days: nil,
  inviter_user_id: nil,
  locale: nil,
  request_options: {}
)
  body = {
    "email" => email,
    "organization_id" => organization_id,
    "role_slug" => role_slug,
    "expires_in_days" => expires_in_days,
    "inviter_user_id" => inviter_user_id,
    "locale" => locale
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/invitations",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::UserInvite.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

#send_verification_email(id:, request_options: {}) ⇒ WorkOS::SendVerificationEmailResponse

Send verification email

Parameters:

  • id (String)

    The ID of the user.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
# File 'lib/workos/user_management.rb', line 1173

def send_verification_email(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}/email_verification/send",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::SendVerificationEmailResponse.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

#update_jwt_template(content:, request_options: {}) ⇒ WorkOS::JWTTemplateResponse

Update JWT template

Parameters:

  • content (String)

    The JWT template content as a Liquid template string.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
# File 'lib/workos/user_management.rb', line 1463

def update_jwt_template(
  content:,
  request_options: {}
)
  body = {
    "content" => content
  }
  response = @client.request(
    method: :put,
    path: "/user_management/jwt_template",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::JWTTemplateResponse.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

#update_user(id:, email: nil, first_name: nil, last_name: nil, name: nil, email_verified: nil, metadata: WorkOS::OMIT, external_id: WorkOS::OMIT, locale: WorkOS::OMIT, password: nil, request_options: {}) ⇒ WorkOS::User

Update a user

Parameters:

  • id (String)

    The unique ID of the user.

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

    The email address of the user.

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

    The first name of the user.

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

    The last name of the user.

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

    The user's full name.

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

    Whether the user's email has been verified.

  • metadata (Hash{String => String}, nil) (defaults to: WorkOS::OMIT)

    Object containing metadata key/value pairs associated with the user.

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

    The external ID of the user.

  • locale (String, nil) (defaults to: WorkOS::OMIT)

    The user's preferred locale.

  • password (WorkOS::UserManagement::PasswordPlaintext, WorkOS::UserManagement::PasswordHashed, nil) (defaults to: nil)

    Identifies the password.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
# File 'lib/workos/user_management.rb', line 1030

def update_user(
  id:,
  email: nil,
  first_name: nil,
  last_name: nil,
  name: nil,
  email_verified: nil,
  metadata: WorkOS::OMIT,
  external_id: WorkOS::OMIT,
  locale: WorkOS::OMIT,
  password: nil,
  request_options: {}
)
  body = {
    "email" => email,
    "first_name" => first_name,
    "last_name" => last_name,
    "name" => name,
    "email_verified" => email_verified
  }.compact
  body["metadata"] =  unless .equal?(WorkOS::OMIT)
  body["external_id"] = external_id unless external_id.equal?(WorkOS::OMIT)
  body["locale"] = locale unless locale.equal?(WorkOS::OMIT)
  if password
    case password
    when WorkOS::UserManagement::PasswordPlaintext
      body["password"] = password.password
    when WorkOS::UserManagement::PasswordHashed
      body["password_hash"] = password.password_hash
      body["password_hash_type"] = password.password_hash_type
      body["password_salt_position"] = password.password_salt_position unless password.password_salt_position.nil?
    else
      raise ArgumentError, "expected password to be one of: WorkOS::UserManagement::PasswordPlaintext, WorkOS::UserManagement::PasswordHashed, got #{password.class}"
    end
  end
  response = @client.request(
    method: :put,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::User.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

#verify_email(id:, code:, request_options: {}) ⇒ WorkOS::VerifyEmailResponse

Verify email

Parameters:

  • id (String)

    The ID of the user.

  • code (String)

    The one-time email verification code.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/workos/user_management.rb', line 1149

def verify_email(
  id:,
  code:,
  request_options: {}
)
  body = {
    "code" => code
  }
  response = @client.request(
    method: :post,
    path: "/user_management/users/#{WorkOS::Util.encode_path(id)}/email_verification/confirm",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::VerifyEmailResponse.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