lib/saml: fix base64 encoding of SAML assertions for users with non-ASCII names (#16)
This PR fixes `encodeAssertion` to use btoa correctly for SAML assertions that contain non-ASCII. Messages are first manually encoded into UTF-8, and the resulting data is coerced into a JS string that btoa will correctly encode. That intermediary string isn't entirely meaningful -- JS strings are UTF-16, not UTF-8 -- but I think this "hack" of sorts is tolerable given how fleeting its use is.
This commit is contained in:
parent
683d9222cb
commit
162dd87fc1
@ -14,7 +14,9 @@ export async function encodeAssertion(
|
|||||||
key: CryptoKey,
|
key: CryptoKey,
|
||||||
assertionData: AssertionData,
|
assertionData: AssertionData,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return btoa(await signAssertion(key, assertionData));
|
// naively calling btoa does not correctly handle non-ASCII
|
||||||
|
const payload = await signAssertion(key, assertionData);
|
||||||
|
return btoa(String.fromCharCode(...new TextEncoder().encode(payload)));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function signAssertion(
|
async function signAssertion(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user