
Research
Security News
Malicious npm Package Wipes Codebases with Remote Trigger
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
web-auth-library
Advanced tools
A collection of utility functions for working with Web Crypto API.
# Install using NPM
$ npm install web-auth-library --save
# Install using Yarn
$ yarn add web-auth-library
import { getAuthToken } from "web-auth-library/google";
const token = await getAuthToken({
credentials: env.GOOGLE_CLOUD_CREDENTIALS,
scope: "https://www.googleapis.com/auth/cloud-platform",
});
// => {
// accessToken: "ya29.c.b0AXv0zTOQVv0...",
// type: "Bearer",
// expires: 1653855236,
// }
return fetch("https://cloudresourcemanager.googleapis.com/v1/projects", {
headers: {
authorization: `Bearer ${token.accessToken}`,
},
});
Where env.GOOGLE_CLOUD_CREDENTIALS
is an environment variable / secret
containing a service account key
(JSON) obtained from the Google Cloud Platform.
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,
// }
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: 'example@example.iam.gserviceaccount.com',
// email: 'example@example.iam.gserviceaccount.com',
// email_verified: true,
// exp: 1654199401,
// iat: 1654195801,
// },
// data: 'eyJhbGciOiJ...',
// signature: 'MDzBStL...'
// }
import { verifyIdToken } from "web-auth-library/google";
const token = await verifyIdToken(idToken, { audience: "https://example.com" });
// => {
// iss: 'https://accounts.google.com',
// aud: 'https://example.com',
// sub: '118363561738753879481'
// azp: 'example@example.iam.gserviceaccount.com',
// email: 'example@example.iam.gserviceaccount.com',
// email_verified: true,
// exp: 1654199401,
// iat: 1654195801,
// }
import { getCredentials, importKey, sign } from "web-auth-library/google";
const credentials = getCredentials(env.GOOGLE_CLOUD_CREDENTIALS);
const signingKey = await importKey(credentials.private_key, ["sign"]);
const signature = await sign(signingKey, "xxx");
JWT
tokenimport { jwt } from "web-auth-library";
jwt.decode("eyJ0eXAiOiJKV1QiLC...");
// => {
// header: { alg: "HS256", typ: "JWT" },
// payload: { iss: "...", aud: "...", iat: ..., exp: ... },
// signature: "xxx"
// }
jwt.decode("eyJ0eXAiOiJKV1QiLC...", { header: false, signature: false });
// => {
// payload: { iss: "...", aud: "...", iat: ..., exp: ... },
// }
You're very welcome to create a PR or send me a message on Discord.
Copyright © 2022-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.
Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors.
FAQs
Authentication library for the browser environment using Web Crypto API
The npm package web-auth-library receives a total of 9,543 weekly downloads. As such, web-auth-library popularity was classified as popular.
We found that web-auth-library demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.
Security News
New CNA status enables OpenJS Foundation to assign CVEs for security vulnerabilities in projects like ESLint, Fastify, Electron, and others, while leaving disclosure responsibility with individual maintainers.