Skip to content

Commit d8a51c2

Browse files
committed
Fix incomplete Portal intent documentation and add validation
Update PHPDoc to include missing intent values (certificate_renewal, domain_verification) and add runtime validation for $intent parameter to provide better error messages before API calls. Includes test coverage for all intent values and invalid intent handling. Fixes #295
1 parent ed4dd61 commit d8a51c2

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

lib/Portal.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,33 @@ class Portal
1313
* Generate a Portal Link scoped to an Organization.
1414
*
1515
* @param string $organization An Organization identifier.
16-
* @param string $intent The intent of the Admin Portal. Possible values are ["audit_logs", "dsync", "log_streams", "sso",].
16+
* @param string $intent The intent of the Admin Portal. Possible values are ["audit_logs", "certificate_renewal", "domain_verification", "dsync", "log_streams", "sso"].
1717
* @param null|string $returnUrl The URL to which WorkOS should send users when they click on
1818
* the link to return to your website. (Optional).
1919
* @param null|string $successUrl The URL to which WorkOS will redirect users to
2020
* upon successfully setting up Single Sign On or Directory Sync. (Optional).
2121
*
22+
* @throws Exception\UnexpectedValueException
2223
* @throws Exception\WorkOSException
2324
*
2425
* @return Resource\PortalLink
2526
*/
2627
public function generateLink($organization, $intent, $returnUrl = null, $successUrl = null)
2728
{
29+
$validIntents = [
30+
'audit_logs',
31+
'certificate_renewal',
32+
'domain_verification',
33+
'dsync',
34+
'log_streams',
35+
'sso'
36+
];
37+
38+
if (!in_array($intent, $validIntents)) {
39+
$msg = "Invalid intent. Valid values are: " . implode(", ", $validIntents);
40+
throw new Exception\UnexpectedValueException($msg);
41+
}
42+
2843
$generateLinkPath = "portal/generate_link";
2944
$params = [
3045
"organization" => $organization,

tests/WorkOS/PortalTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,70 @@ public function testGenerateLinkLogStreams()
130130
$this->assertSame($expectation, $response->link);
131131
}
132132

133+
public function testGenerateLinkCertificateRenewal()
134+
{
135+
$generateLinkPath = "portal/generate_link";
136+
137+
$result = $this->generatePortalLinkFixture();
138+
139+
$params = [
140+
"organization" => "org_01EHZNVPK3SFK441A1RGBFSHRT",
141+
"intent" => "certificate_renewal",
142+
"return_url" => null,
143+
"success_url" => null
144+
];
145+
146+
$this->mockRequest(
147+
Client::METHOD_POST,
148+
$generateLinkPath,
149+
null,
150+
$params,
151+
true,
152+
$result
153+
);
154+
155+
$expectation = "https://id.workos.com/portal/launch?secret=secret";
156+
157+
$response = $this->ap->generateLink("org_01EHZNVPK3SFK441A1RGBFSHRT", "certificate_renewal");
158+
$this->assertSame($expectation, $response->link);
159+
}
160+
161+
public function testGenerateLinkDomainVerification()
162+
{
163+
$generateLinkPath = "portal/generate_link";
164+
165+
$result = $this->generatePortalLinkFixture();
166+
167+
$params = [
168+
"organization" => "org_01EHZNVPK3SFK441A1RGBFSHRT",
169+
"intent" => "domain_verification",
170+
"return_url" => null,
171+
"success_url" => null
172+
];
173+
174+
$this->mockRequest(
175+
Client::METHOD_POST,
176+
$generateLinkPath,
177+
null,
178+
$params,
179+
true,
180+
$result
181+
);
182+
183+
$expectation = "https://id.workos.com/portal/launch?secret=secret";
184+
185+
$response = $this->ap->generateLink("org_01EHZNVPK3SFK441A1RGBFSHRT", "domain_verification");
186+
$this->assertSame($expectation, $response->link);
187+
}
188+
189+
public function testGenerateLinkWithInvalidIntent()
190+
{
191+
$this->expectException(Exception\UnexpectedValueException::class);
192+
$this->expectExceptionMessage("Invalid intent. Valid values are:");
193+
194+
$this->ap->generateLink("org_01EHZNVPK3SFK441A1RGBFSHRT", "invalid_intent");
195+
}
196+
133197
// Fixtures
134198

135199
private function generatePortalLinkFixture()

0 commit comments

Comments
 (0)