-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathApiKeys.php
More file actions
126 lines (117 loc) · 4.22 KB
/
ApiKeys.php
File metadata and controls
126 lines (117 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
<?php
declare(strict_types=1);
// This file is auto-generated by oagen. Do not edit.
namespace WorkOS\Service;
use WorkOS\Resource\ApiKey;
use WorkOS\Resource\ApiKeyValidationResponse;
use WorkOS\Resource\ApiKeyWithValue;
class ApiKeys
{
public function __construct(
private readonly \WorkOS\HttpClient $client,
) {
}
/**
* Validate API key
*
* Validate an API key value and return the API key object if valid.
* @param string $value The value for an API key.
* @return \WorkOS\Resource\ApiKeyValidationResponse
* @throws \WorkOS\Exception\WorkOSException
*/
public function createValidation(
string $value,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\ApiKeyValidationResponse {
$body = [
'value' => $value,
];
$response = $this->client->request(
method: 'POST',
path: 'api_keys/validations',
body: $body,
options: $options,
);
return ApiKeyValidationResponse::fromArray($response);
}
/**
* Delete an API key
*
* Permanently deletes an API key. This action cannot be undone. Once deleted, any requests using this API key will fail authentication.
* @param string $id The unique ID of the API key.
* @return void
* @throws \WorkOS\Exception\WorkOSException
*/
public function deleteApiKey(
string $id,
?\WorkOS\RequestOptions $options = null,
): void {
$this->client->request(
method: 'DELETE',
path: "api_keys/{$id}",
options: $options,
);
}
/**
* List API keys for an organization
*
* Get a list of all API keys for an organization.
* @param string $organizationId Unique identifier of the Organization.
* @param string|null $before An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
* @param string|null $after An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.
* @param int|null $limit Upper limit on the number of objects to return, between `1` and `100`. Defaults to 10.
* @param \WorkOS\Resource\EventsOrder|null $order Order the results by the creation time. Defaults to "desc".
* @return \WorkOS\PaginatedResponse<\WorkOS\Resource\ApiKey>
* @throws \WorkOS\Exception\WorkOSException
*/
public function listOrganizationApiKeys(
string $organizationId,
?string $before = null,
?string $after = null,
?int $limit = null,
?\WorkOS\Resource\EventsOrder $order = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\PaginatedResponse {
$query = array_filter([
'before' => $before,
'after' => $after,
'limit' => $limit,
'order' => $order?->value,
], fn ($v) => $v !== null);
return $this->client->requestPage(
method: 'GET',
path: "organizations/{$organizationId}/api_keys",
query: $query,
modelClass: ApiKey::class,
options: $options,
);
}
/**
* Create an API key for an organization
*
* Create a new API key for an organization.
* @param string $organizationId Unique identifier of the Organization.
* @param string $name The name for the API key.
* @param array<string>|null $permissions The permission slugs to assign to the API key.
* @return \WorkOS\Resource\ApiKeyWithValue
* @throws \WorkOS\Exception\WorkOSException
*/
public function createOrganizationApiKey(
string $organizationId,
string $name,
?array $permissions = null,
?\WorkOS\RequestOptions $options = null,
): \WorkOS\Resource\ApiKeyWithValue {
$body = array_filter([
'name' => $name,
'permissions' => $permissions,
], fn ($v) => $v !== null);
$response = $this->client->request(
method: 'POST',
path: "organizations/{$organizationId}/api_keys",
body: $body,
options: $options,
);
return ApiKeyWithValue::fromArray($response);
}
}