Class: WorkOS::Authorization

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Authorization

Returns a new instance of Authorization.



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

def initialize(client)
  @client = client
end

Instance Method Details

#add_environment_role_permission(slug:, body_slug:, request_options: {}) ⇒ WorkOS::Role

Add a permission to an environment role

Parameters:

  • slug (String)

    The slug of the environment role.

  • body_slug (String)

    The slug of the permission to add to the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
# File 'lib/workos/authorization.rb', line 1104

def add_environment_role_permission(
  slug:,
  body_slug:,
  request_options: {}
)
  body = {
    "slug" => body_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/roles/#{WorkOS::Util.encode_path(slug)}/permissions",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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

#assign_role(organization_membership_id:, role_slug:, resource_target:, resource_id: nil, resource_external_id: nil, resource_type_slug: nil, request_options: {}) ⇒ WorkOS::RoleAssignment

Assign a role

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership.

  • role_slug (String)

    The slug of the role to assign.

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

    The ID of the resource. Mutually exclusive with ‘resource_external_id` and `resource_type_slug`.

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

    The external ID of the resource. Required with ‘resource_type_slug`. Mutually exclusive with `resource_id`.

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

    The resource type slug. Required with ‘resource_external_id`. Mutually exclusive with `resource_id`.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
300
301
302
303
304
305
306
307
308
309
# File 'lib/workos/authorization.rb', line 275

def assign_role(
  organization_membership_id:,
  role_slug:,
  resource_target:,
  resource_id: nil,
  resource_external_id: nil,
  resource_type_slug: nil,
  request_options: {}
)
  params = {}.compact
  case resource_target[:type]
  when "by_id"
    params["resource_id"] = resource_target[:resource_id]
  when "by_external_id"
    params["resource_external_id"] = resource_target[:resource_external_id]
    params["resource_type_slug"] = resource_target[:resource_type_slug]
  end
  body = {
    "role_slug" => role_slug,
    "resource_id" => resource_id,
    "resource_external_id" => resource_external_id,
    "resource_type_slug" => resource_type_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/role_assignments",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::RoleAssignment.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

#check(organization_membership_id:, permission_slug:, resource_target:, resource_id: nil, resource_external_id: nil, resource_type_slug: nil, request_options: {}) ⇒ WorkOS::AuthorizationCheck

Check authorization

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership to check.

  • permission_slug (String)

    The slug of the permission to check.

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

    The ID of the resource. Mutually exclusive with ‘resource_external_id` and `resource_type_slug`.

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

    The external ID of the resource. Required with ‘resource_type_slug`. Mutually exclusive with `resource_id`.

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

    The slug of the resource type. Required with ‘resource_external_id`. Mutually exclusive with `resource_id`.

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

    (see WorkOS::Types::RequestOptions)

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/workos/authorization.rb', line 21

def check(
  organization_membership_id:,
  permission_slug:,
  resource_target:,
  resource_id: nil,
  resource_external_id: nil,
  resource_type_slug: nil,
  request_options: {}
)
  params = {}.compact
  case resource_target[:type]
  when "by_id"
    params["resource_id"] = resource_target[:resource_id]
  when "by_external_id"
    params["resource_external_id"] = resource_target[:resource_external_id]
    params["resource_type_slug"] = resource_target[:resource_type_slug]
  end
  body = {
    "permission_slug" => permission_slug,
    "resource_id" => resource_id,
    "resource_external_id" => resource_external_id,
    "resource_type_slug" => resource_type_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/check",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuthorizationCheck.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_environment_role(slug:, name:, description: nil, resource_type_slug: nil, request_options: {}) ⇒ WorkOS::Role

Create an environment role

Parameters:

  • slug (String)

    A unique slug for the role.

  • name (String)

    A descriptive name for the role.

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

    An optional description of the role.

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

    The slug of the resource type the role is scoped to.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/workos/authorization.rb', line 1027

def create_environment_role(
  slug:,
  name:,
  description: nil,
  resource_type_slug: nil,
  request_options: {}
)
  body = {
    "slug" => slug,
    "name" => name,
    "description" => description,
    "resource_type_slug" => resource_type_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/roles",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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_organization_role(organization_id:, name:, slug: nil, description: nil, resource_type_slug: nil, request_options: {}) ⇒ WorkOS::Role

Create a custom role

Parameters:

  • organization_id (String)

    The ID of the organization.

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

    A unique identifier for the role within the organization. When provided, must begin with ‘org-’ and contain only lowercase letters, numbers, hyphens, and underscores. When omitted, a slug is auto-generated from the role name and a random suffix.

  • name (String)

    A descriptive name for the role.

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

    An optional description of the role’s purpose.

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

    The slug of the resource type the role is scoped to.

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

    (see WorkOS::Types::RequestOptions)

Returns:



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/workos/authorization.rb', line 399

def create_organization_role(
  organization_id:,
  name:,
  slug: nil,
  description: nil,
  resource_type_slug: nil,
  request_options: {}
)
  body = {
    "slug" => slug,
    "name" => name,
    "description" => description,
    "resource_type_slug" => resource_type_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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_permission(slug:, name:, description: nil, resource_type_slug: nil, request_options: {}) ⇒ WorkOS::Permission

Create a permission

Parameters:

  • slug (String)

    A unique key to reference the permission. Must be lowercase and contain only letters, numbers, hyphens, underscores, colons, periods, and asterisks.

  • name (String)

    A descriptive name for the Permission.

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

    An optional description of the Permission.

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

    The slug of the resource type this permission is scoped to.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
# File 'lib/workos/authorization.rb', line 1200

def create_permission(
  slug:,
  name:,
  description: nil,
  resource_type_slug: nil,
  request_options: {}
)
  body = {
    "slug" => slug,
    "name" => name,
    "description" => description,
    "resource_type_slug" => resource_type_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/permissions",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Permission.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_resource(external_id:, name:, resource_type_slug:, organization_id:, description: nil, parent_resource_id: nil, parent_resource_external_id: nil, parent_resource_type_slug: nil, parent_resource: nil, request_options: {}) ⇒ WorkOS::AuthorizationResource

Create an authorization resource

Parameters:

  • external_id (String)

    An external identifier for the resource.

  • name (String)

    A display name for the resource.

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

    An optional description of the resource.

  • resource_type_slug (String)

    The slug of the resource type.

  • organization_id (String)

    The ID of the organization this resource belongs to.

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

    The ID of the parent resource. Mutually exclusive with ‘parent_resource_external_id` and `parent_resource_type_slug`.

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

    The external ID of the parent resource. Required with ‘parent_resource_type_slug`. Mutually exclusive with `parent_resource_id`.

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

    The resource type slug of the parent resource. Required with ‘parent_resource_external_id`. Mutually exclusive with `parent_resource_id`.

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

    (see WorkOS::Types::RequestOptions)

Returns:



814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
# File 'lib/workos/authorization.rb', line 814

def create_resource(
  external_id:,
  name:,
  resource_type_slug:,
  organization_id:,
  description: nil,
  parent_resource_id: nil,
  parent_resource_external_id: nil,
  parent_resource_type_slug: nil,
  parent_resource: nil,
  request_options: {}
)
  params = {}.compact
  if parent_resource
    case parent_resource[:type]
    when "by_id"
      params["parent_resource_id"] = parent_resource[:parent_resource_id]
    when "by_external_id"
      params["parent_resource_external_id"] = parent_resource[:parent_resource_external_id]
      params["parent_resource_type_slug"] = parent_resource[:parent_resource_type_slug]
    end
  end
  body = {
    "external_id" => external_id,
    "name" => name,
    "description" => description,
    "resource_type_slug" => resource_type_slug,
    "organization_id" => organization_id,
    "parent_resource_id" => parent_resource_id,
    "parent_resource_external_id" => parent_resource_external_id,
    "parent_resource_type_slug" => parent_resource_type_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/resources",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuthorizationResource.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_role_permission(organization_id:, slug:, body_slug:, request_options: {}) ⇒ WorkOS::Role

Add a permission to a custom role

Parameters:

  • organization_id (String)

    The ID of the organization.

  • slug (String)

    The slug of the role.

  • body_slug (String)

    The slug of the permission to add to the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/workos/authorization.rb', line 501

def create_role_permission(
  organization_id:,
  slug:,
  body_slug:,
  request_options: {}
)
  body = {
    "slug" => body_slug
  }.compact
  response = @client.request(
    method: :post,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles/#{WorkOS::Util.encode_path(slug)}/permissions",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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_organization_membership_role_assignment(organization_membership_id:, role_assignment_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Remove a role assignment by ID

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership.

  • role_assignment_id (String)

    The ID of the role assignment to remove.

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

    (see WorkOS::Types::RequestOptions)



358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/workos/authorization.rb', line 358

def delete_organization_membership_role_assignment(
  organization_membership_id:,
  role_assignment_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/role_assignments/#{WorkOS::Util.encode_path(role_assignment_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_organization_resource(organization_id:, resource_type_slug:, external_id:, cascade_delete: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an authorization resource by external ID

Parameters:

  • organization_id (String)

    The ID of the organization that owns the resource.

  • resource_type_slug (String)

    The slug of the resource type.

  • external_id (String)

    An identifier you provide to reference the resource in your system.

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

    If true, deletes all descendant resources and role assignments. If not set and the resource has children or assignments, the request will fail.

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

    (see WorkOS::Types::RequestOptions)



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/workos/authorization.rb', line 655

def delete_organization_resource(
  organization_id:,
  resource_type_slug:,
  external_id:,
  cascade_delete: nil,
  request_options: {}
)
  params = {
    "cascade_delete" => cascade_delete
  }.compact
  @client.request(
    method: :delete,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/resources/#{WorkOS::Util.encode_path(resource_type_slug)}/#{WorkOS::Util.encode_path(external_id)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  nil
end

#delete_organization_role(organization_id:, slug:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a custom role

Parameters:

  • organization_id (String)

    The ID of the organization.

  • slug (String)

    The slug of the role.

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

    (see WorkOS::Types::RequestOptions)



481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/workos/authorization.rb', line 481

def delete_organization_role(
  organization_id:,
  slug:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_permission(slug:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a permission

Parameters:

  • slug (String)

    A unique key to reference the permission. Must be lowercase and contain only letters, numbers, hyphens, underscores, colons, periods, and asterisks.

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

    (see WorkOS::Types::RequestOptions)



1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
# File 'lib/workos/authorization.rb', line 1276

def delete_permission(
  slug:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/authorization/permissions/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_resource(resource_id:, cascade_delete: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an authorization resource

Parameters:

  • resource_id (String)

    The ID of the authorization resource.

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

    If true, deletes all descendant resources and role assignments. If not set and the resource has children or assignments, the request will fail.

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

    (see WorkOS::Types::RequestOptions)



932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
# File 'lib/workos/authorization.rb', line 932

def delete_resource(
  resource_id:,
  cascade_delete: nil,
  request_options: {}
)
  params = {
    "cascade_delete" => cascade_delete
  }.compact
  @client.request(
    method: :delete,
    path: "/authorization/resources/#{WorkOS::Util.encode_path(resource_id)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  nil
end

#delete_role_permission(organization_id:, slug:, permission_slug:, request_options: {}) ⇒ WorkOS::Role

Remove a permission from a custom role

Parameters:

  • organization_id (String)

    The ID of the organization.

  • slug (String)

    The slug of the role.

  • permission_slug (String)

    The slug of the permission to remove.

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

    (see WorkOS::Types::RequestOptions)

Returns:



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/workos/authorization.rb', line 555

def delete_role_permission(
  organization_id:,
  slug:,
  permission_slug:,
  request_options: {}
)
  response = @client.request(
    method: :delete,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles/#{WorkOS::Util.encode_path(slug)}/permissions/#{WorkOS::Util.encode_path(permission_slug)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Role.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_environment_role(slug:, request_options: {}) ⇒ WorkOS::Role

Get an environment role

Parameters:

  • slug (String)

    The slug of the environment role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'lib/workos/authorization.rb', line 1056

def get_environment_role(
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/authorization/roles/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Role.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_organization_resource(organization_id:, resource_type_slug:, external_id:, request_options: {}) ⇒ WorkOS::AuthorizationResource

Get a resource by external ID

Parameters:

  • organization_id (String)

    The ID of the organization that owns the resource.

  • resource_type_slug (String)

    The slug of the resource type.

  • external_id (String)

    An identifier you provide to reference the resource in your system.

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

    (see WorkOS::Types::RequestOptions)

Returns:



578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/workos/authorization.rb', line 578

def get_organization_resource(
  organization_id:,
  resource_type_slug:,
  external_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/resources/#{WorkOS::Util.encode_path(resource_type_slug)}/#{WorkOS::Util.encode_path(external_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AuthorizationResource.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_organization_role(organization_id:, slug:, request_options: {}) ⇒ WorkOS::Role

Get a custom role

Parameters:

  • organization_id (String)

    The ID of the organization.

  • slug (String)

    The slug of the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/workos/authorization.rb', line 430

def get_organization_role(
  organization_id:,
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Role.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_permission(slug:, request_options: {}) ⇒ WorkOS::AuthorizationPermission

Get a permission

Parameters:

  • slug (String)

    A unique key to reference the permission. Must be lowercase and contain only letters, numbers, hyphens, underscores, colons, periods, and asterisks.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
# File 'lib/workos/authorization.rb', line 1229

def get_permission(
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/authorization/permissions/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AuthorizationPermission.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_resource(resource_id:, request_options: {}) ⇒ WorkOS::AuthorizationResource

Get a resource

Parameters:

  • resource_id (String)

    The ID of the authorization resource.

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

    (see WorkOS::Types::RequestOptions)

Returns:



863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/workos/authorization.rb', line 863

def get_resource(
  resource_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/authorization/resources/#{WorkOS::Util.encode_path(resource_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AuthorizationResource.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_effective_permissions_by_external_id(organization_membership_id:, resource_type_slug:, external_id:, before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuthorizationPermission>

List effective permissions for an organization membership on a resource by external ID

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership.

  • resource_type_slug (String)

    The slug of the resource type.

  • external_id (String)

    An identifier you provide to reference the resource in your system.

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

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

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

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

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

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

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

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
# File 'lib/workos/authorization.rb', line 177

def list_effective_permissions_by_external_id(
  organization_membership_id:,
  resource_type_slug:,
  external_id:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/resources/#{WorkOS::Util.encode_path(resource_type_slug)}/#{WorkOS::Util.encode_path(external_id)}/permissions",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_effective_permissions_by_external_id(
      organization_membership_id: organization_membership_id,
      resource_type_slug: resource_type_slug,
      external_id: external_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::AuthorizationPermission,
    filters: {organization_membership_id: organization_membership_id, resource_type_slug: resource_type_slug, external_id: external_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_environment_roles(request_options: {}) ⇒ WorkOS::RoleList

List environment roles

Parameters:

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

    (see WorkOS::Types::RequestOptions)

Returns:



1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'lib/workos/authorization.rb', line 1008

def list_environment_roles(request_options: {})
  response = @client.request(
    method: :get,
    path: "/authorization/roles",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::RoleList.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_memberships_for_resource(resource_id:, permission_slug:, before: nil, after: nil, limit: nil, order: "desc", assignment: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserOrganizationMembershipBaseListData>

List organization memberships for resource

Parameters:

  • resource_id (String)

    The ID of the authorization resource.

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

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

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

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

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

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

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

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

  • permission_slug (String)

    The permission slug to filter by. Only users with this permission on the resource are returned.

  • assignment (WorkOS::Types::AuthorizationAssignment, nil) (defaults to: nil)

    Filter by assignment type. Use ‘direct` for direct assignments only, or `indirect` to include inherited assignments.

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

    (see WorkOS::Types::RequestOptions)

Returns:



960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
# File 'lib/workos/authorization.rb', line 960

def list_memberships_for_resource(
  resource_id:,
  permission_slug:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  assignment: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "permission_slug" => permission_slug,
    "assignment" => assignment
  }.compact
  response = @client.request(
    method: :get,
    path: "/authorization/resources/#{WorkOS::Util.encode_path(resource_id)}/organization_memberships",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_memberships_for_resource(
      resource_id: resource_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      permission_slug: permission_slug,
      assignment: assignment,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserOrganizationMembershipBaseListData,
    filters: {resource_id: resource_id, before: before, limit: limit, order: order, permission_slug: permission_slug, assignment: assignment},
    fetch_next: fetch_next
  )
end

#list_organization_membership_resources(organization_membership_id:, permission_slug:, parent_resource:, before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuthorizationResource>

List resources for organization membership

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership.

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

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

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

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

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

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

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

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

  • permission_slug (String)

    The permission slug to filter by. Only child resources where the organization membership has this permission are returned.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/workos/authorization.rb', line 66

def list_organization_membership_resources(
  organization_membership_id:,
  permission_slug:,
  parent_resource:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "permission_slug" => permission_slug
  }.compact
  case parent_resource[:type]
  when "by_id"
    params["parent_resource_id"] = parent_resource[:parent_resource_id]
  when "by_external_id"
    params["parent_resource_type_slug"] = parent_resource[:parent_resource_type_slug]
    params["parent_resource_external_id"] = parent_resource[:parent_resource_external_id]
  end
  response = @client.request(
    method: :get,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/resources",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organization_membership_resources(
      organization_membership_id: organization_membership_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      permission_slug: permission_slug,
      parent_resource: parent_resource,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::AuthorizationResource,
    filters: {organization_membership_id: organization_membership_id, before: before, limit: limit, order: order, permission_slug: permission_slug, parent_resource: parent_resource},
    fetch_next: fetch_next
  )
end

#list_organization_membership_role_assignments(organization_membership_id:, before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::RoleAssignment>

List role assignments

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership.

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

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

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

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

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

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

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

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



228
229
230
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
258
259
260
261
262
263
264
265
# File 'lib/workos/authorization.rb', line 228

def list_organization_membership_role_assignments(
  organization_membership_id:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/role_assignments",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organization_membership_role_assignments(
      organization_membership_id: organization_membership_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::RoleAssignment,
    filters: {organization_membership_id: organization_membership_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_organization_roles(organization_id:, request_options: {}) ⇒ WorkOS::RoleList

List custom roles

Parameters:

  • organization_id (String)

    The ID of the organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/workos/authorization.rb', line 376

def list_organization_roles(
  organization_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::RoleList.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_permissions(before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuthorizationPermission>

List permissions

Parameters:

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

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

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

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

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

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

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

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
# File 'lib/workos/authorization.rb', line 1156

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

#list_resource_organization_memberships(organization_id:, resource_type_slug:, external_id:, permission_slug:, before: nil, after: nil, limit: nil, order: "desc", assignment: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserOrganizationMembershipBaseListData>

List memberships for a resource by external ID

Parameters:

  • organization_id (String)

    The ID of the organization that owns the resource.

  • resource_type_slug (String)

    The slug of the resource type this resource belongs to.

  • external_id (String)

    An identifier you provide to reference the resource in your system.

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

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

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

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

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

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

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

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

  • permission_slug (String)

    The permission slug to filter by. Only users with this permission on the resource are returned.

  • assignment (WorkOS::Types::AuthorizationAssignment, nil) (defaults to: nil)

    Filter by assignment type. Use “direct” for direct assignments only, or “indirect” to include inherited assignments.

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

    (see WorkOS::Types::RequestOptions)

Returns:



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'lib/workos/authorization.rb', line 687

def list_resource_organization_memberships(
  organization_id:,
  resource_type_slug:,
  external_id:,
  permission_slug:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  assignment: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "permission_slug" => permission_slug,
    "assignment" => assignment
  }.compact
  response = @client.request(
    method: :get,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/resources/#{WorkOS::Util.encode_path(resource_type_slug)}/#{WorkOS::Util.encode_path(external_id)}/organization_memberships",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_resource_organization_memberships(
      organization_id: organization_id,
      resource_type_slug: resource_type_slug,
      external_id: external_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      permission_slug: permission_slug,
      assignment: assignment,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserOrganizationMembershipBaseListData,
    filters: {organization_id: organization_id, resource_type_slug: resource_type_slug, external_id: external_id, before: before, limit: limit, order: order, permission_slug: permission_slug, assignment: assignment},
    fetch_next: fetch_next
  )
end

#list_resource_permissions(organization_membership_id:, resource_id:, before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuthorizationPermission>

List effective permissions for an organization membership on a resource

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership.

  • resource_id (String)

    The ID of the authorization resource.

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

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

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

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

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

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

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

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

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

    (see WorkOS::Types::RequestOptions)

Returns:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/workos/authorization.rb', line 126

def list_resource_permissions(
  organization_membership_id:,
  resource_id:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/resources/#{WorkOS::Util.encode_path(resource_id)}/permissions",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_resource_permissions(
      organization_membership_id: organization_membership_id,
      resource_id: resource_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::AuthorizationPermission,
    filters: {organization_membership_id: organization_membership_id, resource_id: resource_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_resources(before: nil, after: nil, limit: nil, order: "desc", organization_id: nil, resource_type_slug: nil, search: nil, parent: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuthorizationResource>

List resources

Parameters:

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

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

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

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

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

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

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

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

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

    Filter resources by organization ID.

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

    Filter resources by resource type slug.

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

    Search resources by name.

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

    (see WorkOS::Types::RequestOptions)

Returns:



746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# File 'lib/workos/authorization.rb', line 746

def list_resources(
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  organization_id: nil,
  resource_type_slug: nil,
  search: nil,
  parent: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "organization_id" => organization_id,
    "resource_type_slug" => resource_type_slug,
    "search" => search
  }.compact
  if parent
    case parent[:type]
    when "by_id"
      params["parent_resource_id"] = parent[:parent_resource_id]
    when "by_external_id"
      params["parent_resource_type_slug"] = parent[:parent_resource_type_slug]
      params["parent_external_id"] = parent[:parent_external_id]
    end
  end
  response = @client.request(
    method: :get,
    path: "/authorization/resources",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_resources(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      organization_id: organization_id,
      resource_type_slug: resource_type_slug,
      search: search,
      parent: parent,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::AuthorizationResource,
    filters: {before: before, limit: limit, order: order, organization_id: organization_id, resource_type_slug: resource_type_slug, search: search, parent: parent},
    fetch_next: fetch_next
  )
end

#remove_role(organization_membership_id:, role_slug:, resource_target:, resource_id: nil, resource_external_id: nil, resource_type_slug: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Remove a role assignment

Parameters:

  • organization_membership_id (String)

    The ID of the organization membership.

  • role_slug (String)

    The slug of the role to remove.

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

    The ID of the resource. Mutually exclusive with ‘resource_external_id` and `resource_type_slug`.

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

    The external ID of the resource. Required with ‘resource_type_slug`. Mutually exclusive with `resource_id`.

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

    The resource type slug. Required with ‘resource_external_id`. Mutually exclusive with `resource_id`.

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

    (see WorkOS::Types::RequestOptions)



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/workos/authorization.rb', line 319

def remove_role(
  organization_membership_id:,
  role_slug:,
  resource_target:,
  resource_id: nil,
  resource_external_id: nil,
  resource_type_slug: nil,
  request_options: {}
)
  params = {}.compact
  case resource_target[:type]
  when "by_id"
    params["resource_id"] = resource_target[:resource_id]
  when "by_external_id"
    params["resource_external_id"] = resource_target[:resource_external_id]
    params["resource_type_slug"] = resource_target[:resource_type_slug]
  end
  body = {
    "role_slug" => role_slug,
    "resource_id" => resource_id,
    "resource_external_id" => resource_external_id,
    "resource_type_slug" => resource_type_slug
  }.compact
  @client.request(
    method: :delete,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/role_assignments",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  nil
end

#set_environment_role_permissions(slug:, permissions:, request_options: {}) ⇒ WorkOS::Role

Set permissions for an environment role

Parameters:

  • slug (String)

    The slug of the environment role.

  • permissions (Array<String>)

    The permission slugs to assign to the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/workos/authorization.rb', line 1129

def set_environment_role_permissions(
  slug:,
  permissions:,
  request_options: {}
)
  body = {
    "permissions" => permissions
  }.compact
  response = @client.request(
    method: :put,
    path: "/authorization/roles/#{WorkOS::Util.encode_path(slug)}/permissions",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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_environment_role(slug:, name: nil, description: nil, request_options: {}) ⇒ WorkOS::Role

Update an environment role

Parameters:

  • slug (String)

    The slug of the environment role.

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

    A descriptive name for the role.

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

    An optional description of the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
# File 'lib/workos/authorization.rb', line 1077

def update_environment_role(
  slug:,
  name: nil,
  description: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description
  }.compact
  response = @client.request(
    method: :patch,
    path: "/authorization/roles/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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_organization_resource(organization_id:, resource_type_slug:, external_id:, name: nil, description: nil, parent_resource_id: nil, parent_resource_external_id: nil, parent_resource_type_slug: nil, parent_resource: nil, request_options: {}) ⇒ WorkOS::AuthorizationResource

Update a resource by external ID

Parameters:

  • organization_id (String)

    The ID of the organization that owns the resource.

  • resource_type_slug (String)

    The slug of the resource type.

  • external_id (String)

    An identifier you provide to reference the resource in your system.

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

    A display name for the resource.

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

    An optional description of the resource.

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

    The ID of the parent resource. Mutually exclusive with ‘parent_resource_external_id` and `parent_resource_type_slug`.

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

    The external ID of the parent resource. Required with ‘parent_resource_type_slug`. Mutually exclusive with `parent_resource_id`.

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

    The resource type slug of the parent resource. Required with ‘parent_resource_external_id`. Mutually exclusive with `parent_resource_id`.

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

    (see WorkOS::Types::RequestOptions)

Returns:



606
607
608
609
610
611
612
613
614
615
616
617
618
619
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
646
# File 'lib/workos/authorization.rb', line 606

def update_organization_resource(
  organization_id:,
  resource_type_slug:,
  external_id:,
  name: nil,
  description: nil,
  parent_resource_id: nil,
  parent_resource_external_id: nil,
  parent_resource_type_slug: nil,
  parent_resource: nil,
  request_options: {}
)
  params = {}.compact
  if parent_resource
    case parent_resource[:type]
    when "by_id"
      params["parent_resource_id"] = parent_resource[:parent_resource_id]
    when "by_external_id"
      params["parent_resource_external_id"] = parent_resource[:parent_resource_external_id]
      params["parent_resource_type_slug"] = parent_resource[:parent_resource_type_slug]
    end
  end
  body = {
    "name" => name,
    "description" => description,
    "parent_resource_id" => parent_resource_id,
    "parent_resource_external_id" => parent_resource_external_id,
    "parent_resource_type_slug" => parent_resource_type_slug
  }.compact
  response = @client.request(
    method: :patch,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/resources/#{WorkOS::Util.encode_path(resource_type_slug)}/#{WorkOS::Util.encode_path(external_id)}",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuthorizationResource.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_organization_role(organization_id:, slug:, name: nil, description: nil, request_options: {}) ⇒ WorkOS::Role

Update a custom role

Parameters:

  • organization_id (String)

    The ID of the organization.

  • slug (String)

    The slug of the role.

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

    A descriptive name for the role.

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

    An optional description of the role’s purpose.

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

    (see WorkOS::Types::RequestOptions)

Returns:



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/workos/authorization.rb', line 453

def update_organization_role(
  organization_id:,
  slug:,
  name: nil,
  description: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description
  }.compact
  response = @client.request(
    method: :patch,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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_permission(slug:, name: nil, description: nil, request_options: {}) ⇒ WorkOS::AuthorizationPermission

Update a permission

Parameters:

  • slug (String)

    A unique key to reference the permission. Must be lowercase and contain only letters, numbers, hyphens, underscores, colons, periods, and asterisks.

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

    A descriptive name for the Permission.

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

    An optional description of the Permission.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
# File 'lib/workos/authorization.rb', line 1250

def update_permission(
  slug:,
  name: nil,
  description: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description
  }.compact
  response = @client.request(
    method: :patch,
    path: "/authorization/permissions/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuthorizationPermission.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_resource(resource_id:, name: nil, description: nil, parent_resource_id: nil, parent_resource_external_id: nil, parent_resource_type_slug: nil, parent_resource: nil, request_options: {}) ⇒ WorkOS::AuthorizationResource

Update a resource

Parameters:

  • resource_id (String)

    The ID of the authorization resource.

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

    A display name for the resource.

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

    An optional description of the resource.

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

    The ID of the parent resource. Mutually exclusive with ‘parent_resource_external_id` and `parent_resource_type_slug`.

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

    The external ID of the parent resource. Required with ‘parent_resource_type_slug`. Mutually exclusive with `parent_resource_id`.

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

    The resource type slug of the parent resource. Required with ‘parent_resource_external_id`. Mutually exclusive with `parent_resource_id`.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
914
915
916
917
918
919
920
921
922
923
924
925
# File 'lib/workos/authorization.rb', line 887

def update_resource(
  resource_id:,
  name: nil,
  description: nil,
  parent_resource_id: nil,
  parent_resource_external_id: nil,
  parent_resource_type_slug: nil,
  parent_resource: nil,
  request_options: {}
)
  params = {}.compact
  if parent_resource
    case parent_resource[:type]
    when "by_id"
      params["parent_resource_id"] = parent_resource[:parent_resource_id]
    when "by_external_id"
      params["parent_resource_external_id"] = parent_resource[:parent_resource_external_id]
      params["parent_resource_type_slug"] = parent_resource[:parent_resource_type_slug]
    end
  end
  body = {
    "name" => name,
    "description" => description,
    "parent_resource_id" => parent_resource_id,
    "parent_resource_external_id" => parent_resource_external_id,
    "parent_resource_type_slug" => parent_resource_type_slug
  }.compact
  response = @client.request(
    method: :patch,
    path: "/authorization/resources/#{WorkOS::Util.encode_path(resource_id)}",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuthorizationResource.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_role_permissions(organization_id:, slug:, permissions:, request_options: {}) ⇒ WorkOS::Role

Set permissions for a custom role

Parameters:

  • organization_id (String)

    The ID of the organization.

  • slug (String)

    The slug of the role.

  • permissions (Array<String>)

    The permission slugs to assign to the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/workos/authorization.rb', line 528

def update_role_permissions(
  organization_id:,
  slug:,
  permissions:,
  request_options: {}
)
  body = {
    "permissions" => permissions
  }.compact
  response = @client.request(
    method: :put,
    path: "/authorization/organizations/#{WorkOS::Util.encode_path(organization_id)}/roles/#{WorkOS::Util.encode_path(slug)}/permissions",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Role.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