#Google authentication JWT validation (✅)

4 messages · Page 1 of 1 (latest)

lethal sun
#

Anyone could help guide me with validating the ID JWT token Google provides when using Google auth?
Google suggests using a library but there is none for Deno it seems.
I saw some JWT packages but when I try to verify the JWT I get this error The alg 'RS256' demands a key. so I'm likely missing some stuff here.
I'm not super familiar with JWT and struggling quite a bit to get something working.
https://developers.google.com/identity/sign-in/web/backend-auth#using-a-google-api-client-library

This is some of the code I tried

import { decode as jwtDecode, Payload, verify as jwtVerify } from "https://deno.land/x/[email protected]/mod.ts";

    public async validateToken(id_token: string): Promise<Payload> {
        const token = this.decodeIdToken(id_token);
        const response = await fetch("https://www.googleapis.com/oauth2/v3/certs");
        const cert = await response.json();
        const verifiedToken = await jwtVerify(id_token, cert[token.header.kid]);
    }
pliant harbor
#

Jose also works on deno (at least there is a package, have only tried it on node): https://deno.land/x/[email protected]?pos=1&qid=392e446b3af9a0c390c11e4648d79799, I used it on npm myself to verify tokens: https://github.com/danielr1996/arbeitszeit-backend/blob/a1b86d59e4773033ea9f1d6fab9c74abbdf92707/src/auth.module/jwt-auth.guard.ts#L32

So basically it should be nothing more than
const JWKS = jose.createRemoteJWKSet(new URL("https://www.googleapis.com/oauth2/v3/certs"))
const {payload} = await jose.jwtVerify(token, JWKS)

GitHub

Contribute to danielr1996/arbeitszeit-backend development by creating an account on GitHub.

lethal sun
#

Awesome thanks a lot for that, got it working 🙂

#

✅ Google authentication JWT validation