fix app.tsx no –crypto.randomUUID is not a function error
This commit is contained in:
+16
-1
@@ -39,6 +39,21 @@ async function createCodeVerifier() {
|
||||
return base64UrlEncode(array)
|
||||
}
|
||||
|
||||
function generateUUID() {
|
||||
// Use native crypto.randomUUID when available, otherwise fallback to RFC4122 v4
|
||||
// Compatible with older browsers that lack crypto.randomUUID
|
||||
if (typeof crypto !== 'undefined' && 'randomUUID' in crypto) {
|
||||
// @ts-ignore
|
||||
return (crypto as any).randomUUID()
|
||||
}
|
||||
|
||||
const bytes = crypto.getRandomValues(new Uint8Array(16))
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
||||
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')
|
||||
return `${hex.substr(0, 8)}-${hex.substr(8, 4)}-${hex.substr(12, 4)}-${hex.substr(16, 4)}-${hex.substr(20, 12)}`
|
||||
}
|
||||
|
||||
function getLocalToken() {
|
||||
return window.localStorage.getItem('oidc_access_token')
|
||||
}
|
||||
@@ -137,7 +152,7 @@ function App() {
|
||||
async function login() {
|
||||
try {
|
||||
const config = await fetchOIDCConfig()
|
||||
const state = crypto.randomUUID()
|
||||
const state = generateUUID()
|
||||
const codeVerifier = await createCodeVerifier()
|
||||
const codeChallenge = await sha256(codeVerifier)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user