Merge pull request #786 from max-stytch/max/fix-url-serialization

fix: correct authState.authorizationUrl type to URL
This commit is contained in:
Cliff Hall 2025-09-06 11:16:30 -04:00 • committed by GitHub
commit ec84e21556
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 11 additions and 7 deletions

View file

@ -187,7 +187,7 @@ const AuthDebugger = ({
JSON.stringify(currentState), JSON.stringify(currentState),
); );
// Open the authorization URL automatically // Open the authorization URL automatically
window.location.href = currentState.authorizationUrl; window.location.href = currentState.authorizationUrl.toString();
break; break;
} }
} }

View file

@ -240,7 +240,7 @@ export const OAuthFlowProgress = ({
<p className="font-medium mb-2 text-sm">Authorization URL:</p> <p className="font-medium mb-2 text-sm">Authorization URL:</p>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<p className="text-xs break-all"> <p className="text-xs break-all">
{authState.authorizationUrl} {String(authState.authorizationUrl)}
</p> </p>
<button <button
onClick={() => { onClick={() => {

View file

@ -482,7 +482,9 @@ describe("AuthDebugger", () => {
await waitFor(() => { await waitFor(() => {
expect(updateAuthState).toHaveBeenCalledWith( expect(updateAuthState).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
authorizationUrl: expect.stringContaining("scope="), authorizationUrl: expect.objectContaining({
href: "https://oauth.example.com/authorize?scope=read+write",
}),
}), }),
); );
}); });
@ -496,7 +498,9 @@ describe("AuthDebugger", () => {
await waitFor(() => { await waitFor(() => {
expect(updateAuthState).toHaveBeenCalledWith( expect(updateAuthState).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
authorizationUrl: expect.stringContaining("scope="), authorizationUrl: expect.objectContaining({
href: "https://oauth.example.com/authorize?scope=read+write",
}),
}), }),
); );
}); });

View file

@ -34,7 +34,7 @@ export interface AuthDebuggerState {
authServerUrl: URL | null; authServerUrl: URL | null;
oauthMetadata: OAuthMetadata | null; oauthMetadata: OAuthMetadata | null;
oauthClientInfo: OAuthClientInformationFull | OAuthClientInformation | null; oauthClientInfo: OAuthClientInformationFull | OAuthClientInformation | null;
authorizationUrl: string | null; authorizationUrl: URL | null;
authorizationCode: string; authorizationCode: string;
latestError: Error | null; latestError: Error | null;
statusMessage: StatusMessage | null; statusMessage: StatusMessage | null;

View file

@ -132,7 +132,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
context.provider.saveCodeVerifier(codeVerifier); context.provider.saveCodeVerifier(codeVerifier);
context.updateState({ context.updateState({
authorizationUrl: authorizationUrl.toString(), authorizationUrl: authorizationUrl,
oauthStep: "authorization_code", oauthStep: "authorization_code",
}); });
}, },

View file

@ -5,7 +5,7 @@
* @param url - The URL string to validate * @param url - The URL string to validate
* @throws Error if the URL has an unsafe protocol * @throws Error if the URL has an unsafe protocol
*/ */
export function validateRedirectUrl(url: string): void { export function validateRedirectUrl(url: string | URL): void {
try { try {
const parsedUrl = new URL(url); const parsedUrl = new URL(url);
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") { if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {