-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: let folks know the URL we're opening during login (#1267)
* fix: let folks know the URL we're opening during login * Create big-toes-obey.md * chore: update snapshots * getting my head around our magic mocks * Update mock-oauth-flow.ts * Update packages/wrangler/src/user.tsx Co-authored-by: Pete Bacon Darwin <[email protected]> * attempt to get mocks working * make generateAuthUrl mockable * add comment * mock more * Update generate-random-state.ts Co-authored-by: Pete Bacon Darwin <[email protected]>
- Loading branch information
1 parent
d8ee04f
commit c667398
Showing
8 changed files
with
102 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: let folks know the URL we're opening during login | ||
|
||
Closes #1259 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
interface GenerateAuthUrlProps { | ||
authUrl: string; | ||
clientId: string; | ||
callbackUrl: string; | ||
scopes: string[]; | ||
stateQueryParam: string; | ||
codeChallenge: string; | ||
} | ||
|
||
/** | ||
* generateAuthUrl was extracted from getAuthURL in user.tsx | ||
* to make it possible to mock the generated URL | ||
*/ | ||
export const generateAuthUrl = ({ | ||
authUrl, | ||
clientId, | ||
callbackUrl, | ||
scopes, | ||
stateQueryParam, | ||
codeChallenge, | ||
}: GenerateAuthUrlProps) => { | ||
return ( | ||
authUrl + | ||
`?response_type=code&` + | ||
`client_id=${encodeURIComponent(clientId)}&` + | ||
`redirect_uri=${encodeURIComponent(callbackUrl)}&` + | ||
// we add offline_access manually for every request | ||
`scope=${encodeURIComponent([...scopes, "offline_access"].join(" "))}&` + | ||
`state=${stateQueryParam}&` + | ||
`code_challenge=${encodeURIComponent(codeChallenge)}&` + | ||
`code_challenge_method=S256` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { webcrypto as crypto } from "node:crypto"; | ||
import { PKCE_CHARSET } from "./user"; | ||
|
||
/** | ||
* Generates random state to be passed for anti-csrf. | ||
* extracted from user.tsx to make it possible to | ||
* mock the generated URL | ||
*/ | ||
export function generateRandomState(lengthOfState: number): string { | ||
const output = new Uint32Array(lengthOfState); | ||
// @ts-expect-error crypto's types aren't there yet | ||
crypto.getRandomValues(output); | ||
return Array.from(output) | ||
.map((num: number) => PKCE_CHARSET[num % PKCE_CHARSET.length]) | ||
.join(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters