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:



1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/workos/authorization.rb', line 1110

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:



524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/workos/authorization.rb', line 524

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

Assign a role

Parameters:

Returns:



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

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::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:, request_options: {}) ⇒ WorkOS::AuthorizationCheck

Check authorization

Parameters:

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/workos/authorization.rb', line 61

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:



1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
# File 'lib/workos/authorization.rb', line 1033

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:



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/workos/authorization.rb', line 422

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:



1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
# File 'lib/workos/authorization.rb', line 1206

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:



834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
# File 'lib/workos/authorization.rb', line 834

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



504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/workos/authorization.rb', line 504

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)



1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
# File 'lib/workos/authorization.rb', line 1282

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)



938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
# File 'lib/workos/authorization.rb', line 938

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_resource_by_external_id(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)



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

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

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



1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
# File 'lib/workos/authorization.rb', line 1062

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



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/workos/authorization.rb', line 453

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:



1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'lib/workos/authorization.rb', line 1235

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:



877
878
879
880
881
882
883
884
885
886
887
888
889
890
# File 'lib/workos/authorization.rb', line 877

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:



601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/workos/authorization.rb', line 601

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



163
164
165
166
167
168
169
170
171
172
173
174
175
176
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
# File 'lib/workos/authorization.rb', line 163

def list_effective_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_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: 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:



214
215
216
217
218
219
220
221
222
223
224
225
226
227
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
# File 'lib/workos/authorization.rb', line 214

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:



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
# File 'lib/workos/authorization.rb', line 1014

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:



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
1004
1005
1006
1007
1008
1009
# File 'lib/workos/authorization.rb', line 966

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_memberships_for_resource_by_external_id(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:



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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'lib/workos/authorization.rb', line 702

def list_memberships_for_resource_by_external_id(
  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_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:



399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/workos/authorization.rb', line 399

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:



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
1192
1193
1194
1195
1196
1197
# File 'lib/workos/authorization.rb', line 1162

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_resources(before: nil, after: nil, limit: nil, order: "desc", organization_id: nil, resource_type_slug: nil, resource_external_id: 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.

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

    Filter resources by external ID.

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

    Search resources by name.

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

    Identifies the parent.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
# File 'lib/workos/authorization.rb', line 763

def list_resources(
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  organization_id: nil,
  resource_type_slug: nil,
  resource_external_id: 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,
    "resource_external_id" => resource_external_id,
    "search" => search
  }.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,
      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, resource_external_id: resource_external_id, search: search, parent: parent},
    fetch_next: fetch_next
  )
end

#list_resources_for_membership(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.

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

    Identifies the parent resource.

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

    (see WorkOS::Types::RequestOptions)

Returns:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/workos/authorization.rb', line 101

def list_resources_for_membership(
  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
  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: 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:



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

def list_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_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

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



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

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:



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

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)



381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/workos/authorization.rb', line 381

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:



1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'lib/workos/authorization.rb', line 1135

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:



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

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:



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/workos/authorization.rb', line 1083

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



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

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:



1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# File 'lib/workos/authorization.rb', line 1256

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:



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

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:



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/workos/authorization.rb', line 627

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