(key: CryptoKey, jwt: string)
| 39 | } |
| 40 | |
| 41 | export async function verifyAuthJwt<T = JwtData>(key: CryptoKey, jwt: string): Promise<T> { |
| 42 | const jwtParts = jwt.split('.'); |
| 43 | if (jwtParts.length !== 3) { |
| 44 | throw new Error('Malformed JWT'); |
| 45 | } |
| 46 | |
| 47 | const data = textToData(jwtParts[0] + '.' + jwtParts[1]); |
| 48 | if (await crypto.subtle.verify({ name: 'HMAC' }, key, decodeBase64Url(jwtParts[2]), data) === true) { |
| 49 | return JSON.parse(dataToText(decodeBase64Url(jwtParts[1]))) as T; |
| 50 | } |
| 51 | |
| 52 | throw new Error('Invalid JWT'); |
| 53 | } |
| 54 | |
| 55 | export async function resolveCookieDomain(request: Request) { |
| 56 | const config = await AppConfig.getConfig(); |
no test coverage detected