Mitigate Replay Attacks When Using the Implicit Flow
Generate a Cryptographically Random Nonce
function randomString(length) {
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz+/';
let result = '';
while (length > 0) {
const bytes = new Uint8Array(16);
const random = window.crypto.getRandomValues(bytes);
random.forEach((c) => {
if (length === 0) return;
if (c < charset.length) {
result += charset[c];
length--;
}
});
}
return result;
}
Persist Nonces Across Requests
Validate the ID Token
Last updated
Was this helpful?