Skip to content

Commit 6976b4a

Browse files
rickyromboclaude
andcommitted
Normalize OAuth API key to handle 0x prefixes
Strip 0x prefix from api_key/client_id query params at parse time and update isValidApiKey to accept prefixed keys, so OAuth consent works regardless of whether the key includes the prefix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 60b4ec7 commit 6976b4a

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

packages/web/src/pages/oauth-login-page/hooks.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ const useParsedQueryParams = () => {
7575

7676
const scope = collapseScopes(rawScope)
7777

78-
const apiKey =
79-
typeof api_key === 'string'
80-
? api_key
81-
: typeof client_id === 'string'
82-
? client_id
83-
: undefined
78+
const apiKey = (() => {
79+
const raw =
80+
typeof api_key === 'string'
81+
? api_key
82+
: typeof client_id === 'string'
83+
? client_id
84+
: undefined
85+
if (raw?.toLowerCase().startsWith('0x')) return raw.slice(2)
86+
return raw
87+
})()
8488

8589
const parsedRedirectUri = useMemo<'postmessage' | URL | null>(() => {
8690
if (redirectUri && typeof redirectUri === 'string') {

packages/web/src/pages/oauth-login-page/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export const getIsRedirectValid = ({
4141

4242
export const isValidApiKey = (key: string | string[]) => {
4343
if (Array.isArray(key)) return false
44-
if (key.length !== 40) {
44+
const normalized = key.toLowerCase().startsWith('0x') ? key.slice(2) : key
45+
if (normalized.length !== 40) {
4546
return false
4647
}
4748
const hexadecimalRegex = /^[0-9a-fA-F]+$/
48-
return hexadecimalRegex.test(key)
49+
return hexadecimalRegex.test(normalized)
4950
}
5051

5152
const getFormattedAppAddress = ({

0 commit comments

Comments
 (0)