Merge pull request #786 from max-stytch/max/fix-url-serialization
fix: correct authState.authorizationUrl type to URL
This commit is contained in:
commit
ec84e21556
6 changed files with 11 additions and 7 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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={() => {
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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:") {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue