web-auth-library
Advanced tools
Comparing version
@@ -35,5 +35,5 @@ import { type Credentials } from "./credentials.js"; | ||
}; | ||
waitUntil?: (promise: Promise<void | unknown>) => void; | ||
waitUntil?: <T = unknown>(promise: Promise<T>) => void; | ||
cache?: Map<string, any>; | ||
}; | ||
export {}; |
/* SPDX-FileCopyrightText: 2022-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
import { decodeJwt } from "jose"; | ||
import { canUseDefaultCache } from "../core/env.js"; | ||
import { FetchError } from "../core/error.js"; | ||
import { logOnce } from "../core/utils.js"; | ||
import { getCredentials } from "./credentials.js"; | ||
@@ -15,2 +17,5 @@ import { createCustomToken } from "./customToken.js"; | ||
export async function getAccessToken(options) { | ||
if (!options?.waitUntil && canUseDefaultCache) { | ||
logOnce("warn", "verifyIdToken", "Missing `waitUntil` option."); | ||
} | ||
let credentials; | ||
@@ -73,3 +78,3 @@ // Normalize service account credentials | ||
// if the code is running in Cloudflare Workers environment | ||
if (self.caches?.default) { | ||
if (canUseDefaultCache) { | ||
res = await caches.default.match(cacheKey); | ||
@@ -97,3 +102,3 @@ } | ||
} | ||
if (self.caches?.default) { | ||
if (canUseDefaultCache) { | ||
let cacheRes = res.clone(); | ||
@@ -100,0 +105,0 @@ cacheRes = new Response(cacheRes.body, cacheRes); |
@@ -29,3 +29,3 @@ import { KeyLike } from "jose"; | ||
certificateURL?: string; | ||
waitUntil?: (promise: Promise<void | unknown>) => void; | ||
waitUntil?: <T = unknown>(promise: Promise<T>) => void; | ||
}): Promise<KeyLike>; | ||
@@ -32,0 +32,0 @@ /** |
@@ -99,4 +99,4 @@ import { Credentials } from "./credentials.js"; | ||
}; | ||
waitUntil?: (promise: Promise<void | unknown>) => Promise<void | unknown>; | ||
}): Promise<import("jose").JWTPayload>; | ||
waitUntil?: <T = unknown>(promise: Promise<T>) => void; | ||
}): Promise<UserToken>; | ||
type VerifyCustomTokenResponse = { | ||
@@ -109,2 +109,81 @@ kind: "identitytoolkit#VerifyCustomTokenResponse"; | ||
}; | ||
export interface UserToken { | ||
/** | ||
* Always set to https://securetoken.google.com/GOOGLE_CLOUD_PROJECT | ||
*/ | ||
iss: string; | ||
/** | ||
* Always set to GOOGLE_CLOUD_PROJECT | ||
*/ | ||
aud: string; | ||
/** | ||
* The user's unique ID | ||
*/ | ||
sub: string; | ||
/** | ||
* The token issue time, in seconds since epoch | ||
*/ | ||
iat: number; | ||
/** | ||
* The token expiry time, normally 'iat' + 3600 | ||
*/ | ||
exp: number; | ||
/** | ||
* The user's unique ID. Must be equal to 'sub' | ||
*/ | ||
user_id: string; | ||
/** | ||
* The time the user authenticated, normally 'iat' | ||
*/ | ||
auth_time: number; | ||
/** | ||
* The sign in provider, only set when the provider is 'anonymous' | ||
*/ | ||
provider_id?: "anonymous"; | ||
/** | ||
* The user's primary email | ||
*/ | ||
email?: string; | ||
/** | ||
* The user's email verification status | ||
*/ | ||
email_verified?: boolean; | ||
/** | ||
* The user's primary phone number | ||
*/ | ||
phone_number?: string; | ||
/** | ||
* The user's display name | ||
*/ | ||
name?: string; | ||
/** | ||
* The user's profile photo URL | ||
*/ | ||
picture?: string; | ||
/** | ||
* Information on all identities linked to this user | ||
*/ | ||
firebase: { | ||
/** | ||
* The primary sign-in provider | ||
*/ | ||
sign_in_provider: SignInProvider; | ||
/** | ||
* A map of providers to the user's list of unique identifiers from | ||
* each provider | ||
*/ | ||
identities?: { | ||
[provider in SignInProvider]?: string[]; | ||
}; | ||
}; | ||
/** | ||
* Custom claims set by the developer | ||
*/ | ||
[claim: string]: unknown; | ||
/** | ||
* @deprecated use `sub` instead | ||
*/ | ||
uid?: never; | ||
} | ||
export type SignInProvider = "custom" | "email" | "password" | "phone" | "anonymous" | "google.com" | "facebook.com" | "github.com" | "twitter.com" | "microsoft.com" | "apple.com"; | ||
export {}; |
/* SPDX-FileCopyrightText: 2022-present Kriasoft */ | ||
/* SPDX-License-Identifier: MIT */ | ||
import { decodeProtectedHeader, errors, jwtVerify } from "jose"; | ||
import { canUseDefaultCache } from "../core/env.js"; | ||
import { FetchError } from "../core/error.js"; | ||
import { logOnce } from "../core/utils.js"; | ||
import { getCredentials, importPublicKey } from "./credentials.js"; | ||
@@ -101,4 +103,2 @@ import { createCustomToken } from "./customToken.js"; | ||
} | ||
// #region Get the Google Cloud project ID | ||
// using environment variables as a fallback | ||
let projectId = options?.projectId; | ||
@@ -115,3 +115,5 @@ if (projectId === undefined) { | ||
} | ||
// #endregion | ||
if (!options.waitUntil && canUseDefaultCache) { | ||
logOnce("warn", "verifyIdToken", "Missing `waitUntil` option."); | ||
} | ||
// Import the public key from the Google Cloud project | ||
@@ -118,0 +120,0 @@ const header = decodeProtectedHeader(options.idToken); |
{ | ||
"name": "web-auth-library", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"packageManager": "yarn@4.0.0-rc.39", | ||
@@ -85,3 +85,3 @@ "description": "Authentication library for the browser environment using Web Crypto API", | ||
"@babel/preset-typescript": "^7.21.0", | ||
"@cloudflare/workers-types": "^4.20230221.0", | ||
"@cloudflare/workers-types": "^4.20230228.0", | ||
"@types/jest": "^29.4.0", | ||
@@ -88,0 +88,0 @@ "@typescript-eslint/eslint-plugin": "^5.54.0", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
48624
6.14%37
12.12%1107
10.15%1
-50%