Skip to content

v0.4.0

Compare
Choose a tag to compare
@koistya koistya released this 02 Jun 19:19
· 10 commits to main since this release

Retrieving an ID token for the target audience

import { getAuthToken } from "web-auth-library/google";

const token = await getAuthToken({
  credentials: env.GOOGLE_CLOUD_CREDENTIALS,
  audience: "https://example.com",
});
// => {
//   idToken: "eyJhbGciOiJSUzI1NiIsImtpZ...",
//   audience: "https://example.com",
//   expires: 1654199401,
// }

Decoding an ID token

import { jwt } from "web-auth-library/google";

jwt.decode(idToken);
// {
//   header: {
//     alg: 'RS256',
//     kid: '38f3883468fc659abb4475f36313d22585c2d7ca',
//     typ: 'JWT'
//   },
//   payload: {
//     iss: 'https://accounts.google.com',
//     sub: '118363561738753879481'
//     aud: 'https://example.com',
//     azp: '[email protected]',
//     email: '[email protected]',
//     email_verified: true,
//     exp: 1654199401,
//     iat: 1654195801,
//   },
//   data: 'eyJhbGciOiJ...',
//   signature: 'MDzBStL...'
// }

Verifying an ID token

import { verifyIdToken } from "web-auth-library/google";

const token = await verifyIdToken(idToken, { audience: "https://example.com" });
// => {
//   iss: 'https://accounts.google.com',
//   sub: '118363561738753879481'
//   aud: 'https://example.com',
//   azp: '[email protected]',
//   email: '[email protected]',
//   email_verified: true,
//   exp: 1654199401,
//   iat: 1654195801,
// }