Class: WorkOS::Authorization

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

Defined Under Namespace

Classes: ParentByExternalId, ParentById, ParentResourceByExternalId, ParentResourceById, ResourceTargetByExternalId, ResourceTargetById

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Authorization

Returns a new instance of Authorization.



51
52
53
# File 'lib/workos/authorization.rb', line 51

def initialize(client)
  @client = client
end

Instance Attribute Details

#parent_external_idString (readonly)

Returns:

  • (String)


49
# File 'lib/workos/authorization.rb', line 49

ParentByExternalId = Data.define(:parent_resource_type_slug, :parent_external_id)

#parent_resource_external_idString (readonly)

Returns:

  • (String)


35
# File 'lib/workos/authorization.rb', line 35

ParentResourceByExternalId = Data.define(:parent_resource_type_slug, :parent_resource_external_id)

#parent_resource_idString (readonly)

Returns:

  • (String)


27
# File 'lib/workos/authorization.rb', line 27

ParentResourceById = Data.define(:parent_resource_id)

#parent_resource_type_slugString (readonly)

Returns:

  • (String)


35
# File 'lib/workos/authorization.rb', line 35

ParentResourceByExternalId = Data.define(:parent_resource_type_slug, :parent_resource_external_id)

#resource_external_idString (readonly)

Returns:

  • (String)


21
# File 'lib/workos/authorization.rb', line 21

ResourceTargetByExternalId = Data.define(:resource_external_id, :resource_type_slug)

#resource_idString (readonly)

Returns:

  • (String)


13
# File 'lib/workos/authorization.rb', line 13

ResourceTargetById = Data.define(:resource_id)

#resource_type_slugString (readonly)

Returns:

  • (String)


21
# File 'lib/workos/authorization.rb', line 21

ResourceTargetByExternalId = Data.define(:resource_external_id, :resource_type_slug)

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:



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

def add_environment_role_permission(
  slug:,
  body_slug:,
  request_options: {}
)
  body = {
    "slug" => body_slug
  }
  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

#add_organization_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:



716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/workos/authorization.rb', line 716

def add_organization_role_permission(
  organization_id:,
  slug:,
  body_slug:,
  request_options: {}
)
  body = {
    "slug" => body_slug
  }
  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

#assign_role(organization_membership_id:, role_slug:, resource_target:, request_options: {}) ⇒ WorkOS::UserRoleAssignment

Assign a role

Parameters:

Returns:



502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/workos/authorization.rb', line 502

def assign_role(
  organization_membership_id:,
  role_slug:,
  resource_target:,
  request_options: {}
)
  body = {
    "role_slug" => role_slug
  }
  case resource_target
  when WorkOS::Authorization::ResourceTargetById
    body["resource_id"] = resource_target.resource_id
  when WorkOS::Authorization::ResourceTargetByExternalId
    body["resource_external_id"] = resource_target.resource_external_id
    body["resource_type_slug"] = resource_target.resource_type_slug
  else
    raise ArgumentError, "expected resource_target to be one of: WorkOS::Authorization::ResourceTargetById, WorkOS::Authorization::ResourceTargetByExternalId, got #{resource_target.class}"
  end
  response = @client.request(
    method: :post,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/role_assignments",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::UserRoleAssignment.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:, request_options: {}) ⇒ WorkOS::AuthorizationCheck

Check authorization

Parameters:

Returns:



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
266
267
268
269
# File 'lib/workos/authorization.rb', line 241

def check(
  organization_membership_id:,
  permission_slug:,
  resource_target:,
  request_options: {}
)
  body = {
    "permission_slug" => permission_slug
  }
  case resource_target
  when WorkOS::Authorization::ResourceTargetById
    body["resource_id"] = resource_target.resource_id
  when WorkOS::Authorization::ResourceTargetByExternalId
    body["resource_external_id"] = resource_target.resource_external_id
    body["resource_type_slug"] = resource_target.resource_type_slug
  else
    raise ArgumentError, "expected resource_target to be one of: WorkOS::Authorization::ResourceTargetById, WorkOS::Authorization::ResourceTargetByExternalId, got #{resource_target.class}"
  end
  response = @client.request(
    method: :post,
    path: "/authorization/organization_memberships/#{WorkOS::Util.encode_path(organization_membership_id)}/check",
    auth: true,
    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:



1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
# File 'lib/workos/authorization.rb', line 1329

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_group_role_assignment(group_id:, role_slug:, resource_id: nil, resource_external_id: nil, resource_type_slug: nil, request_options: {}) ⇒ WorkOS::GroupRoleAssignment

Assign a role to a group

Parameters:

  • group_id (String)

    The ID of the group.

  • role_slug (String)

    The slug of the role to assign to the group.

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

    The ID of the resource. Omit along with the external-id fields to target the organization itself.

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

    The external ID of the resource.

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

    The resource type slug.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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/authorization.rb', line 110

def create_group_role_assignment(
  group_id:,
  role_slug:,
  resource_id: nil,
  resource_external_id: nil,
  resource_type_slug: nil,
  request_options: {}
)
  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/groups/#{WorkOS::Util.encode_path(group_id)}/role_assignments",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::GroupRoleAssignment.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:



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
# File 'lib/workos/authorization.rb', line 614

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:



1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
# File 'lib/workos/authorization.rb', line 1502

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: 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 (WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId, nil) (defaults to: nil)

    Identifies the parent resource.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
# File 'lib/workos/authorization.rb', line 1079

def create_resource(
  external_id:,
  name:,
  resource_type_slug:,
  organization_id:,
  description: nil,
  parent_resource: nil,
  request_options: {}
)
  body = {
    "external_id" => external_id,
    "name" => name,
    "description" => description,
    "resource_type_slug" => resource_type_slug,
    "organization_id" => organization_id
  }.compact
  if parent_resource
    case parent_resource
    when WorkOS::Authorization::ParentResourceById
      body["parent_resource_id"] = parent_resource.parent_resource_id
    when WorkOS::Authorization::ParentResourceByExternalId
      body["parent_resource_external_id"] = parent_resource.parent_resource_external_id
      body["parent_resource_type_slug"] = parent_resource.parent_resource_type_slug
    else
      raise ArgumentError, "expected parent_resource to be one of: WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId, got #{parent_resource.class}"
    end
  end
  response = @client.request(
    method: :post,
    path: "/authorization/resources",
    auth: true,
    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

#delete_group_role_assignment(group_id:, role_assignment_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Remove a group role assignment

Parameters:

  • group_id (String)

    The ID of the group.

  • role_assignment_id (String)

    The ID of the group role assignment to remove.

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

    (see WorkOS::Types::RequestOptions)



221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/workos/authorization.rb', line 221

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

#delete_group_role_assignments(group_id:, role_slug:, resource_id: nil, resource_external_id: nil, resource_type_slug: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Remove group role assignments by criteria

Parameters:

  • group_id (String)

    The ID of the group.

  • role_slug (String)

    The slug of the role to remove assignments for.

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

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

    The resource type slug.

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

    (see WorkOS::Types::RequestOptions)



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

def delete_group_role_assignments(
  group_id:,
  role_slug:,
  resource_id: nil,
  resource_external_id: nil,
  resource_type_slug: nil,
  request_options: {}
)
  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/groups/#{WorkOS::Util.encode_path(group_id)}/role_assignments",
    auth: true,
    body: body,
    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)



696
697
698
699
700
701
702
703
704
705
706
707
708
# File 'lib/workos/authorization.rb', line 696

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)



1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
# File 'lib/workos/authorization.rb', line 1578

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: false, 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: false)

    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)



1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
# File 'lib/workos/authorization.rb', line 1183

def delete_resource(
  resource_id:,
  cascade_delete: false,
  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_resource_by_external_id(organization_id:, resource_type_slug:, external_id:, cascade_delete: false, 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: false)

    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)



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

def delete_resource_by_external_id(
  organization_id:,
  resource_type_slug:,
  external_id:,
  cascade_delete: false,
  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

#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:



1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
# File 'lib/workos/authorization.rb', line 1358

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_group_role_assignment(group_id:, role_assignment_id:, request_options: {}) ⇒ WorkOS::GroupRoleAssignment

Get a group role assignment

Parameters:

  • group_id (String)

    The ID of the group.

  • role_assignment_id (String)

    The ID of the group role assignment.

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

    (see WorkOS::Types::RequestOptions)

Returns:



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/workos/authorization.rb', line 200

def get_group_role_assignment(
  group_id:,
  role_assignment_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/authorization/groups/#{WorkOS::Util.encode_path(group_id)}/role_assignments/#{WorkOS::Util.encode_path(role_assignment_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::GroupRoleAssignment.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:



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/workos/authorization.rb', line 645

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:



1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
# File 'lib/workos/authorization.rb', line 1531

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:



1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
# File 'lib/workos/authorization.rb', line 1122

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

#get_resource_by_external_id(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:



793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/workos/authorization.rb', line 793

def get_resource_by_external_id(
  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

#list_effective_permissions(organization_membership_id:, resource_id:, before: nil, after: nil, limit: 10, 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: 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:



343
344
345
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
375
376
377
378
379
380
381
382
# File 'lib/workos/authorization.rb', line 343

def list_effective_permissions(
  organization_membership_id:,
  resource_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: "/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_effective_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_effective_permissions_by_external_id(organization_membership_id:, resource_type_slug:, external_id:, before: nil, after: nil, limit: 10, 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: 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:



394
395
396
397
398
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
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/workos/authorization.rb', line 394

def list_effective_permissions_by_external_id(
  organization_membership_id:,
  resource_type_slug:,
  external_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: "/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:



1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
# File 'lib/workos/authorization.rb', line 1310

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_group_role_assignments(group_id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::GroupRoleAssignment>

List role assignments for a group

Parameters:

  • group_id (String)

    The ID of the group.

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



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/workos/authorization.rb', line 63

def list_group_role_assignments(
  group_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: "/authorization/groups/#{WorkOS::Util.encode_path(group_id)}/role_assignments",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_group_role_assignments(
      group_id: group_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::GroupRoleAssignment,
    filters: {group_id: group_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_memberships_for_resource(resource_id:, permission_slug:, before: nil, after: nil, limit: 10, 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: 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).

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



1211
1212
1213
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
1252
1253
1254
# File 'lib/workos/authorization.rb', line 1211

def list_memberships_for_resource(
  resource_id:,
  permission_slug:,
  before: nil,
  after: nil,
  limit: 10,
  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_memberships_for_resource_by_external_id(organization_id:, resource_type_slug:, external_id:, permission_slug:, before: nil, after: nil, limit: 10, 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: 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).

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



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
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
# File 'lib/workos/authorization.rb', line 894

def list_memberships_for_resource_by_external_id(
  organization_id:,
  resource_type_slug:,
  external_id:,
  permission_slug:,
  before: nil,
  after: nil,
  limit: 10,
  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_memberships_for_resource_by_external_id(
      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_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:



591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/workos/authorization.rb', line 591

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: 10, 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: 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:



1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
# File 'lib/workos/authorization.rb', line 1458

def list_permissions(
  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: "/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_resources(before: nil, after: nil, limit: 10, order: "desc", organization_id: nil, resource_type_slug: nil, resource_external_id: 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: 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)

    Filter resources by organization ID.

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

    Filter resources by resource type slug.

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

    Filter resources by external ID.

  • parent (WorkOS::Authorization::ParentById, WorkOS::Authorization::ParentByExternalId, nil) (defaults to: nil)

    Identifies the parent.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
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
# File 'lib/workos/authorization.rb', line 1011

def list_resources(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  organization_id: nil,
  resource_type_slug: nil,
  resource_external_id: nil,
  parent: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "organization_id" => organization_id,
    "resource_type_slug" => resource_type_slug,
    "resource_external_id" => resource_external_id
  }.compact
  if parent
    case parent
    when WorkOS::Authorization::ParentById
      params["parent_resource_id"] = parent.parent_resource_id
    when WorkOS::Authorization::ParentByExternalId
      params["parent_resource_type_slug"] = parent.parent_resource_type_slug
      params["parent_external_id"] = parent.parent_external_id
    else
      raise ArgumentError, "expected parent to be one of: WorkOS::Authorization::ParentById, WorkOS::Authorization::ParentByExternalId, got #{parent.class}"
    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,
      resource_external_id: resource_external_id,
      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, resource_external_id: resource_external_id, parent: parent},
    fetch_next: fetch_next
  )
end

#list_resources_for_membership(organization_membership_id:, permission_slug:, parent_resource:, before: nil, after: nil, limit: 10, 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: 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).

  • permission_slug (String)

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

  • parent_resource (WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId)

    Identifies the parent resource.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/workos/authorization.rb', line 281

def list_resources_for_membership(
  organization_membership_id:,
  permission_slug:,
  parent_resource:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "permission_slug" => permission_slug
  }.compact
  case parent_resource
  when WorkOS::Authorization::ParentResourceById
    params["parent_resource_id"] = parent_resource.parent_resource_id
  when WorkOS::Authorization::ParentResourceByExternalId
    params["parent_resource_type_slug"] = parent_resource.parent_resource_type_slug
    params["parent_resource_external_id"] = parent_resource.parent_resource_external_id
  else
    raise ArgumentError, "expected parent_resource to be one of: WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId, got #{parent_resource.class}"
  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_resources_for_membership(
      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_role_assignments(organization_membership_id:, before: nil, after: nil, limit: 10, order: "desc", resource_id: nil, resource_external_id: nil, resource_type_slug: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserRoleAssignment>

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

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

    Filter assignments by the ID of the resource.

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

    Filter assignments by the external ID of the resource.

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

    Filter assignments by the slug of the resource type.

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

    (see WorkOS::Types::RequestOptions)

Returns:



448
449
450
451
452
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
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/workos/authorization.rb', line 448

def list_role_assignments(
  organization_membership_id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  resource_id: nil,
  resource_external_id: nil,
  resource_type_slug: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "resource_id" => resource_id,
    "resource_external_id" => resource_external_id,
    "resource_type_slug" => resource_type_slug
  }.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_role_assignments(
      organization_membership_id: organization_membership_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      resource_id: resource_id,
      resource_external_id: resource_external_id,
      resource_type_slug: resource_type_slug,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserRoleAssignment,
    filters: {organization_membership_id: organization_membership_id, before: before, limit: limit, order: order, resource_id: resource_id, resource_external_id: resource_external_id, resource_type_slug: resource_type_slug},
    fetch_next: fetch_next
  )
end

#list_role_assignments_for_resource(resource_id:, before: nil, after: nil, limit: 10, order: "desc", role_slug: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserRoleAssignment>

List role assignments for a 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: 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).

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

    Filter assignments by the slug of the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
1304
1305
# File 'lib/workos/authorization.rb', line 1265

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

#list_role_assignments_for_resource_by_external_id(organization_id:, resource_type_slug:, external_id:, before: nil, after: nil, limit: 10, order: "desc", role_slug: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::UserRoleAssignment>

List role assignments 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.

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

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

    Filter assignments by the slug of the role.

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

    (see WorkOS::Types::RequestOptions)

Returns:



954
955
956
957
958
959
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
# File 'lib/workos/authorization.rb', line 954

def list_role_assignments_for_resource_by_external_id(
  organization_id:,
  resource_type_slug:,
  external_id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  role_slug: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "role_slug" => role_slug
  }.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)}/role_assignments",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_role_assignments_for_resource_by_external_id(
      organization_id: organization_id,
      resource_type_slug: resource_type_slug,
      external_id: external_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      role_slug: role_slug,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::UserRoleAssignment,
    filters: {organization_id: organization_id, resource_type_slug: resource_type_slug, external_id: external_id, before: before, limit: limit, order: order, role_slug: role_slug},
    fetch_next: fetch_next
  )
end

#remove_organization_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:



770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
# File 'lib/workos/authorization.rb', line 770

def remove_organization_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

#remove_role(organization_membership_id:, role_slug:, resource_target:, request_options: {}) ⇒ void

This method returns an undefined value.

Remove a role assignment

Parameters:



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/workos/authorization.rb', line 538

def remove_role(
  organization_membership_id:,
  role_slug:,
  resource_target:,
  request_options: {}
)
  params = {}
  case resource_target
  when WorkOS::Authorization::ResourceTargetById
    params["resource_id"] = resource_target.resource_id
  when WorkOS::Authorization::ResourceTargetByExternalId
    params["resource_external_id"] = resource_target.resource_external_id
    params["resource_type_slug"] = resource_target.resource_type_slug
  else
    raise ArgumentError, "expected resource_target to be one of: WorkOS::Authorization::ResourceTargetById, WorkOS::Authorization::ResourceTargetByExternalId, got #{resource_target.class}"
  end
  body = {
    "role_slug" => role_slug
  }
  @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

#remove_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)



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

def remove_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

#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:



1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
# File 'lib/workos/authorization.rb', line 1431

def set_environment_role_permissions(
  slug:,
  permissions:,
  request_options: {}
)
  body = {
    "permissions" => permissions
  }
  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

#set_organization_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:



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'lib/workos/authorization.rb', line 743

def set_organization_role_permissions(
  organization_id:,
  slug:,
  permissions:,
  request_options: {}
)
  body = {
    "permissions" => permissions
  }
  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

#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:



1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
# File 'lib/workos/authorization.rb', line 1379

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_group_role_assignments(group_id:, role_assignments:, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::GroupRoleAssignment>

Replace all role assignments for a group

Parameters:

  • group_id (String)

    The ID of the group.

  • role_assignments (Array<WorkOS::ReplaceGroupRoleAssignmentEntry>)

    The list of role assignments that should exist for the group. All existing assignments will be replaced.

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

    (see WorkOS::Types::RequestOptions)

Returns:



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/workos/authorization.rb', line 141

def update_group_role_assignments(
  group_id:,
  role_assignments:,
  request_options: {}
)
  body = {
    "role_assignments" => role_assignments
  }
  response = @client.request(
    method: :put,
    path: "/authorization/groups/#{WorkOS::Util.encode_path(group_id)}/role_assignments",
    auth: true,
    body: body,
    request_options: request_options
  )
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::GroupRoleAssignment,
    filters: {group_id: group_id, role_assignments: role_assignments}
  )
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:



668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/workos/authorization.rb', line 668

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:



1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
# File 'lib/workos/authorization.rb', line 1552

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: 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 (WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId, nil) (defaults to: nil)

    Identifies the parent resource.

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

    (see WorkOS::Types::RequestOptions)

Returns:



1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/workos/authorization.rb', line 1144

def update_resource(
  resource_id:,
  name: nil,
  description: nil,
  parent_resource: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description
  }.compact
  if parent_resource
    case parent_resource
    when WorkOS::Authorization::ParentResourceById
      body["parent_resource_id"] = parent_resource.parent_resource_id
    when WorkOS::Authorization::ParentResourceByExternalId
      body["parent_resource_external_id"] = parent_resource.parent_resource_external_id
      body["parent_resource_type_slug"] = parent_resource.parent_resource_type_slug
    else
      raise ArgumentError, "expected parent_resource to be one of: WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId, got #{parent_resource.class}"
    end
  end
  response = @client.request(
    method: :patch,
    path: "/authorization/resources/#{WorkOS::Util.encode_path(resource_id)}",
    auth: true,
    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_resource_by_external_id(organization_id:, resource_type_slug:, external_id:, name: nil, description: 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 (WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId, nil) (defaults to: nil)

    Identifies the parent resource.

  • 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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/workos/authorization.rb', line 819

def update_resource_by_external_id(
  organization_id:,
  resource_type_slug:,
  external_id:,
  name: nil,
  description: nil,
  parent_resource: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "description" => description
  }.compact
  if parent_resource
    case parent_resource
    when WorkOS::Authorization::ParentResourceById
      body["parent_resource_id"] = parent_resource.parent_resource_id
    when WorkOS::Authorization::ParentResourceByExternalId
      body["parent_resource_external_id"] = parent_resource.parent_resource_external_id
      body["parent_resource_type_slug"] = parent_resource.parent_resource_type_slug
    else
      raise ArgumentError, "expected parent_resource to be one of: WorkOS::Authorization::ParentResourceById, WorkOS::Authorization::ParentResourceByExternalId, got #{parent_resource.class}"
    end
  end
  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,
    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