Skip to content

Commit 7731e0f

Browse files
committed
updates
1 parent 27913bc commit 7731e0f

10 files changed

Lines changed: 33 additions & 39 deletions

File tree

lib/Resource/ApiKey.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(
2323
/** An obfuscated representation of the API Key value. */
2424
public string $obfuscatedValue,
2525
/** Timestamp of when the API Key was last used. */
26-
public ?string $lastUsedAt,
26+
public ?\DateTimeImmutable $lastUsedAt,
2727
/**
2828
* The permission slugs assigned to the API Key.
2929
* @var array<string>
@@ -44,7 +44,7 @@ public static function fromArray(array $data): self
4444
owner: ApiKeyOwner::fromArray($data['owner']),
4545
name: $data['name'],
4646
obfuscatedValue: $data['obfuscated_value'],
47-
lastUsedAt: $data['last_used_at'] ?? null,
47+
lastUsedAt: isset($data['last_used_at']) ? new \DateTimeImmutable($data['last_used_at']) : null,
4848
permissions: $data['permissions'],
4949
createdAt: new \DateTimeImmutable($data['created_at']),
5050
updatedAt: new \DateTimeImmutable($data['updated_at']),
@@ -59,7 +59,7 @@ public function toArray(): array
5959
'owner' => $this->owner->toArray(),
6060
'name' => $this->name,
6161
'obfuscated_value' => $this->obfuscatedValue,
62-
'last_used_at' => $this->lastUsedAt,
62+
'last_used_at' => $this->lastUsedAt?->format(\DateTimeInterface::RFC3339_EXTENDED),
6363
'permissions' => $this->permissions,
6464
'created_at' => $this->createdAt->format(\DateTimeInterface::RFC3339_EXTENDED),
6565
'updated_at' => $this->updatedAt->format(\DateTimeInterface::RFC3339_EXTENDED),

lib/Resource/ApiKeyWithValue.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
/** An obfuscated representation of the API Key value. */
2323
public string $obfuscatedValue,
2424
/** Timestamp of when the API Key was last used. */
25-
public ?string $lastUsedAt,
25+
public ?\DateTimeImmutable $lastUsedAt,
2626
/**
2727
* The permission slugs assigned to the API Key.
2828
* @var array<string>
@@ -45,7 +45,7 @@ public static function fromArray(array $data): self
4545
owner: ApiKeyWithValueOwner::fromArray($data['owner']),
4646
name: $data['name'],
4747
obfuscatedValue: $data['obfuscated_value'],
48-
lastUsedAt: $data['last_used_at'] ?? null,
48+
lastUsedAt: isset($data['last_used_at']) ? new \DateTimeImmutable($data['last_used_at']) : null,
4949
permissions: $data['permissions'],
5050
createdAt: new \DateTimeImmutable($data['created_at']),
5151
updatedAt: new \DateTimeImmutable($data['updated_at']),
@@ -61,7 +61,7 @@ public function toArray(): array
6161
'owner' => $this->owner->toArray(),
6262
'name' => $this->name,
6363
'obfuscated_value' => $this->obfuscatedValue,
64-
'last_used_at' => $this->lastUsedAt,
64+
'last_used_at' => $this->lastUsedAt?->format(\DateTimeInterface::RFC3339_EXTENDED),
6565
'permissions' => $this->permissions,
6666
'created_at' => $this->createdAt->format(\DateTimeInterface::RFC3339_EXTENDED),
6767
'updated_at' => $this->updatedAt->format(\DateTimeInterface::RFC3339_EXTENDED),

lib/Resource/AuditLogEvent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(
1414
/** Identifier of what happened. */
1515
public string $action,
1616
/** ISO-8601 value of when the action occurred. */
17-
public string $occurredAt,
17+
public \DateTimeImmutable $occurredAt,
1818
/** The entity that performed the action. */
1919
public AuditLogEventActor $actor,
2020
/**
@@ -38,7 +38,7 @@ public static function fromArray(array $data): self
3838
{
3939
return new self(
4040
action: $data['action'],
41-
occurredAt: $data['occurred_at'],
41+
occurredAt: new \DateTimeImmutable($data['occurred_at']),
4242
actor: AuditLogEventActor::fromArray($data['actor']),
4343
targets: array_map(fn ($item) => AuditLogEventTarget::fromArray($item), $data['targets']),
4444
context: AuditLogEventContext::fromArray($data['context']),
@@ -51,7 +51,7 @@ public function toArray(): array
5151
{
5252
return [
5353
'action' => $this->action,
54-
'occurred_at' => $this->occurredAt,
54+
'occurred_at' => $this->occurredAt->format(\DateTimeInterface::RFC3339_EXTENDED),
5555
'actor' => $this->actor->toArray(),
5656
'targets' => array_map(fn ($item) => $item->toArray(), $this->targets),
5757
'context' => $this->context->toArray(),

lib/Resource/GenerateLink.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public function __construct(
3131
public ?GenerateLinkIntent $intent = null,
3232
/** Options to configure the Admin Portal based on the intent. */
3333
public ?IntentOptions $intentOptions = null,
34+
/**
35+
* The email addresses of the IT admins to grant access to the Admin Portal for the given organization. Accepts up to 20 emails.
36+
* @var array<string>|null
37+
*/
38+
public ?array $adminEmails = null,
3439
) {
3540
}
3641

@@ -42,6 +47,7 @@ public static function fromArray(array $data): self
4247
successUrl: $data['success_url'] ?? null,
4348
intent: isset($data['intent']) ? GenerateLinkIntent::from($data['intent']) : null,
4449
intentOptions: isset($data['intent_options']) ? IntentOptions::fromArray($data['intent_options']) : null,
50+
adminEmails: $data['admin_emails'] ?? null,
4551
);
4652
}
4753

@@ -53,6 +59,7 @@ public function toArray(): array
5359
'success_url' => $this->successUrl,
5460
'intent' => $this->intent?->value,
5561
'intent_options' => $this->intentOptions?->toArray(),
62+
'admin_emails' => $this->adminEmails,
5663
];
5764
}
5865
}

lib/Service/AdminPortal.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(
3232
* - `certificate_renewal` - Launch Admin Portal for renewing SAML Certificates
3333
* - `bring_your_own_key` - Launch Admin Portal for configuring Bring Your Own Key
3434
* @param \WorkOS\Resource\IntentOptions|null $intentOptions Options to configure the Admin Portal based on the intent.
35+
* @param array<string>|null $adminEmails The email addresses of the IT admins to grant access to the Admin Portal for the given organization. Accepts up to 20 emails.
3536
* @return \WorkOS\Resource\PortalLinkResponse
3637
*/
3738
public function generateLink(
@@ -40,6 +41,7 @@ public function generateLink(
4041
?string $successUrl = null,
4142
?\WorkOS\Resource\GenerateLinkIntent $intent = null,
4243
?\WorkOS\Resource\IntentOptions $intentOptions = null,
44+
?array $adminEmails = null,
4345
?\WorkOS\RequestOptions $options = null,
4446
): \WorkOS\Resource\PortalLinkResponse {
4547
$body = array_filter([
@@ -48,6 +50,7 @@ public function generateLink(
4850
'organization' => $organization,
4951
'intent' => $intent?->value,
5052
'intent_options' => $intentOptions,
53+
'admin_emails' => $adminEmails,
5154
], fn ($v) => $v !== null);
5255
$response = $this->client->request(
5356
method: 'POST',

lib/Service/SSO.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,9 @@ public function deleteConnection(
106106
* Initiates the single sign-on flow.
107107
* @param array<string>|null $providerScopes Additional OAuth scopes to request from the identity provider. Only applicable when using OAuth connections.
108108
* @param array<string, string>|null $providerQueryParams Key/value pairs of query parameters to pass to the OAuth provider. Only applicable when using OAuth connections.
109-
* @param string $clientId The unique identifier of the WorkOS environment client.
110109
* @param string|null $domain (deprecated) Deprecated. Use `connection` or `organization` instead. Used to initiate SSO for a connection by domain. The domain must be associated with a connection in your WorkOS environment.
111110
* @param \WorkOS\Resource\SSOProvider|null $provider Used to initiate OAuth authentication with Google, Microsoft, GitHub, or Apple.
112111
* @param string $redirectUri Where to redirect the user after they complete the authentication process. You must use one of the redirect URIs configured via the [Redirects](https://dashboard.workos.com/redirects) page on the dashboard.
113-
* @param string $responseType The only valid option for the response type parameter is `"code"`.
114-
*
115-
* The `"code"` parameter value initiates an [authorization code grant type](https://tools.ietf.org/html/rfc6749#section-4.1). This grant type allows you to exchange an authorization code for an access token during the redirect that takes place after a user has authenticated with an identity provider.
116112
* @param string|null $state An optional parameter that can be used to encode arbitrary information to help restore application state between redirects. If included, the redirect URI received from WorkOS will contain the exact `state` that was passed.
117113
* @param string|null $connection Used to initiate SSO for a connection. The value should be a WorkOS connection ID.
118114
*
@@ -126,9 +122,7 @@ public function deleteConnection(
126122
* @return \WorkOS\Resource\SSOAuthorizeUrlResponse
127123
*/
128124
public function getAuthorizationUrl(
129-
string $clientId,
130125
string $redirectUri,
131-
string $responseType,
132126
?array $providerScopes = null,
133127
?array $providerQueryParams = null,
134128
?string $domain = null,
@@ -144,18 +138,18 @@ public function getAuthorizationUrl(
144138
$query = array_filter([
145139
'provider_scopes' => $providerScopes,
146140
'provider_query_params' => $providerQueryParams,
147-
'client_id' => $clientId,
148141
'domain' => $domain,
149142
'provider' => $provider?->value,
150143
'redirect_uri' => $redirectUri,
151-
'response_type' => $responseType,
152144
'state' => $state,
153145
'connection' => $connection,
154146
'organization' => $organization,
155147
'domain_hint' => $domainHint,
156148
'login_hint' => $loginHint,
157149
'nonce' => $nonce,
150+
'response_type' => 'code',
158151
], fn ($v) => $v !== null);
152+
$query['client_id'] = $this->client->requireClientId();
159153
$response = $this->client->request(
160154
method: 'GET',
161155
path: 'sso/authorize',
@@ -234,25 +228,19 @@ public function getProfile(
234228
* Get a Profile and Token
235229
*
236230
* Get an access token along with the user [Profile](https://workos.com/docs/reference/sso/profile) using the code passed to your [Redirect URI](https://workos.com/docs/reference/sso/get-authorization-url/redirect-uri).
237-
* @param string $clientId The client ID of the WorkOS environment.
238-
* @param string $clientSecret The client secret of the WorkOS environment.
239231
* @param string $code The authorization code received from the authorization callback.
240-
* @param string $grantType The grant type for the token request.
241232
* @return \WorkOS\Resource\SSOTokenResponse
242233
*/
243234
public function getProfileAndToken(
244-
string $clientId,
245-
string $clientSecret,
246235
string $code,
247-
string $grantType,
248236
?\WorkOS\RequestOptions $options = null,
249237
): \WorkOS\Resource\SSOTokenResponse {
250238
$body = [
251-
'client_id' => $clientId,
252-
'client_secret' => $clientSecret,
253239
'code' => $code,
254-
'grant_type' => $grantType,
240+
'grant_type' => 'authorization_code',
255241
];
242+
$body['client_id'] = $this->client->requireClientId();
243+
$body['client_secret'] = $this->client->requireApiKey();
256244
$response = $this->client->request(
257245
method: 'POST',
258246
path: 'sso/token',

lib/Service/UserManagement.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,11 @@ public function authenticateWithDeviceCode(
290290
* @param string|null $prompt Controls the authentication flow behavior for the user.
291291
* @param string|null $state An opaque value used to maintain state between the request and the callback.
292292
* @param string|null $organizationId The ID of the organization to authenticate the user against.
293-
* @param string $responseType The response type of the application.
294293
* @param string $redirectUri The callback URI where the authorization code will be sent after authentication.
295-
* @param string $clientId The unique identifier of the WorkOS environment client.
296294
* @return mixed
297295
*/
298296
public function getAuthorizationUrl(
299-
string $responseType,
300297
string $redirectUri,
301-
string $clientId,
302298
?string $codeChallengeMethod = null,
303299
?string $codeChallenge = null,
304300
?string $domainHint = null,
@@ -328,10 +324,10 @@ public function getAuthorizationUrl(
328324
'prompt' => $prompt,
329325
'state' => $state,
330326
'organization_id' => $organizationId,
331-
'response_type' => $responseType,
332327
'redirect_uri' => $redirectUri,
333-
'client_id' => $clientId,
328+
'response_type' => 'code',
334329
], fn ($v) => $v !== null);
330+
$query['client_id'] = $this->client->requireClientId();
335331
$response = $this->client->request(
336332
method: 'GET',
337333
path: 'user_management/authorize',

tests/Fixtures/generate_link.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"bookmark_slug": "chatgpt",
99
"provider_type": "GoogleSAML"
1010
}
11-
}
11+
},
12+
"admin_emails": [
13+
"admin@example.com"
14+
]
1215
}

tests/Service/SSOTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testGetAuthorizationUrl(): void
6060
{
6161
$fixture = $this->loadFixture('sso_authorize_url_response');
6262
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
63-
$result = $client->sso()->getAuthorizationUrl(clientId: 'test_value', redirectUri: 'test_value', responseType: 'test_value');
63+
$result = $client->sso()->getAuthorizationUrl(redirectUri: 'test_value');
6464
$this->assertInstanceOf(\WorkOS\Resource\SSOAuthorizeUrlResponse::class, $result);
6565
$this->assertIsArray($result->toArray());
6666
$request = $this->getLastRequest();
@@ -110,18 +110,15 @@ public function testGetProfileAndToken(): void
110110
{
111111
$fixture = $this->loadFixture('sso_token_response');
112112
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
113-
$result = $client->sso()->getProfileAndToken(clientId: 'test_value', clientSecret: 'test_value', code: 'test_value', grantType: 'test_value');
113+
$result = $client->sso()->getProfileAndToken(code: 'test_value');
114114
$this->assertInstanceOf(\WorkOS\Resource\SSOTokenResponse::class, $result);
115115
$this->assertSame($fixture['access_token'], $result->accessToken);
116116
$this->assertIsArray($result->toArray());
117117
$request = $this->getLastRequest();
118118
$this->assertSame('POST', $request->getMethod());
119119
$this->assertStringEndsWith('sso/token', $request->getUri()->getPath());
120120
$body = json_decode((string) $request->getBody(), true);
121-
$this->assertSame('test_value', $body['client_id']);
122-
$this->assertSame('test_value', $body['client_secret']);
123121
$this->assertSame('test_value', $body['code']);
124-
$this->assertArrayHasKey('grant_type', $body);
125122
}
126123

127124
public function testPaginationBoundary(): void

tests/Service/UserManagementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testGetJwks(): void
2828
public function testGetAuthorizationUrl(): void
2929
{
3030
$client = $this->createMockClient([['status' => 200, 'body' => []]]);
31-
$client->userManagement()->getAuthorizationUrl(responseType: 'test_value', redirectUri: 'test_value', clientId: 'test_value');
31+
$client->userManagement()->getAuthorizationUrl(redirectUri: 'test_value');
3232
$request = $this->getLastRequest();
3333
$this->assertSame('GET', $request->getMethod());
3434
$this->assertStringEndsWith('user_management/authorize', $request->getUri()->getPath());

0 commit comments

Comments
 (0)