Skip to content

Commit 27913bc

Browse files
committed
corrections from a merge conflict
1 parent 1015097 commit 27913bc

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

lib/Service/SSO.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ 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.
109110
* @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.
110111
* @param \WorkOS\Resource\SSOProvider|null $provider Used to initiate OAuth authentication with Google, Microsoft, GitHub, or Apple.
111112
* @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.
112116
* @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.
113117
* @param string|null $connection Used to initiate SSO for a connection. The value should be a WorkOS connection ID.
114118
*
@@ -122,7 +126,9 @@ public function deleteConnection(
122126
* @return \WorkOS\Resource\SSOAuthorizeUrlResponse
123127
*/
124128
public function getAuthorizationUrl(
129+
string $clientId,
125130
string $redirectUri,
131+
string $responseType,
126132
?array $providerScopes = null,
127133
?array $providerQueryParams = null,
128134
?string $domain = null,
@@ -138,18 +144,18 @@ public function getAuthorizationUrl(
138144
$query = array_filter([
139145
'provider_scopes' => $providerScopes,
140146
'provider_query_params' => $providerQueryParams,
147+
'client_id' => $clientId,
141148
'domain' => $domain,
142149
'provider' => $provider?->value,
143150
'redirect_uri' => $redirectUri,
151+
'response_type' => $responseType,
144152
'state' => $state,
145153
'connection' => $connection,
146154
'organization' => $organization,
147155
'domain_hint' => $domainHint,
148156
'login_hint' => $loginHint,
149157
'nonce' => $nonce,
150-
'response_type' => 'code',
151158
], fn ($v) => $v !== null);
152-
$query['client_id'] = $this->client->requireClientId();
153159
$response = $this->client->request(
154160
method: 'GET',
155161
path: 'sso/authorize',
@@ -228,19 +234,25 @@ public function getProfile(
228234
* Get a Profile and Token
229235
*
230236
* 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.
231239
* @param string $code The authorization code received from the authorization callback.
240+
* @param string $grantType The grant type for the token request.
232241
* @return \WorkOS\Resource\SSOTokenResponse
233242
*/
234243
public function getProfileAndToken(
244+
string $clientId,
245+
string $clientSecret,
235246
string $code,
247+
string $grantType,
236248
?\WorkOS\RequestOptions $options = null,
237249
): \WorkOS\Resource\SSOTokenResponse {
238250
$body = [
251+
'client_id' => $clientId,
252+
'client_secret' => $clientSecret,
239253
'code' => $code,
240-
'grant_type' => 'authorization_code',
254+
'grant_type' => $grantType,
241255
];
242-
$body['client_id'] = $this->client->requireClientId();
243-
$body['client_secret'] = $this->client->requireApiKey();
244256
$response = $this->client->request(
245257
method: 'POST',
246258
path: 'sso/token',

lib/Service/UserManagement.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,15 @@ 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.
293294
* @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.
294296
* @return mixed
295297
*/
296298
public function getAuthorizationUrl(
299+
string $responseType,
297300
string $redirectUri,
301+
string $clientId,
298302
?string $codeChallengeMethod = null,
299303
?string $codeChallenge = null,
300304
?string $domainHint = null,
@@ -324,10 +328,10 @@ public function getAuthorizationUrl(
324328
'prompt' => $prompt,
325329
'state' => $state,
326330
'organization_id' => $organizationId,
331+
'response_type' => $responseType,
327332
'redirect_uri' => $redirectUri,
328-
'response_type' => 'code',
333+
'client_id' => $clientId,
329334
], fn ($v) => $v !== null);
330-
$query['client_id'] = $this->client->requireClientId();
331335
$response = $this->client->request(
332336
method: 'GET',
333337
path: 'user_management/authorize',

tests/Service/SSOTest.php

Lines changed: 5 additions & 2 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(redirectUri: 'test_value');
63+
$result = $client->sso()->getAuthorizationUrl(clientId: 'test_value', redirectUri: 'test_value', responseType: 'test_value');
6464
$this->assertInstanceOf(\WorkOS\Resource\SSOAuthorizeUrlResponse::class, $result);
6565
$this->assertIsArray($result->toArray());
6666
$request = $this->getLastRequest();
@@ -110,15 +110,18 @@ 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(code: 'test_value');
113+
$result = $client->sso()->getProfileAndToken(clientId: 'test_value', clientSecret: 'test_value', code: 'test_value', grantType: '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']);
121123
$this->assertSame('test_value', $body['code']);
124+
$this->assertArrayHasKey('grant_type', $body);
122125
}
123126

124127
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(redirectUri: 'test_value');
31+
$client->userManagement()->getAuthorizationUrl(responseType: 'test_value', redirectUri: 'test_value', clientId: '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)