@vercel/passport
Advanced tools
+13
| # @vercel/passport | ||
| ## 0.1.1 | ||
| ### Patch Changes | ||
| - afdf72b: Restore the `@vercel/passport` package after it was temporarily removed. | ||
| ## 0.1.0 | ||
| ### Minor Changes | ||
| - 73d85e5: Add `getIdentity` for reading Passport identity from Vercel Functions. |
+131
| import { type JWTVerifyOptions } from 'jose'; | ||
| export declare const PASSPORT_HEADER_NAME = "x-vercel-oidc-passport-token"; | ||
| export declare const PASSPORT_COOKIE_NAME = "_vercel_passport"; | ||
| export type TokenSource = 'header' | 'cookie' | 'local'; | ||
| export interface PassportIdentityPayload { | ||
| typ?: string; | ||
| owner?: string; | ||
| owner_id?: string; | ||
| project?: string; | ||
| project_id?: string; | ||
| environment?: string; | ||
| plan?: string; | ||
| aud?: string; | ||
| iss?: string; | ||
| sub: string; | ||
| scope?: string; | ||
| external_iss?: string; | ||
| external_sub?: string; | ||
| connector_id?: string; | ||
| sid?: string; | ||
| tenant_id?: string; | ||
| installation_id?: string; | ||
| email?: string; | ||
| name?: string; | ||
| [claim: string]: unknown; | ||
| } | ||
| export interface PassportIdentity { | ||
| token: string | null; | ||
| tokenSource: TokenSource; | ||
| verified: boolean; | ||
| payload: PassportIdentityPayload; | ||
| subject: string; | ||
| externalIssuer?: string; | ||
| externalSubject?: string; | ||
| connectorId?: string; | ||
| email?: string; | ||
| name?: string; | ||
| owner: { | ||
| id?: string; | ||
| slug: string; | ||
| }; | ||
| project?: { | ||
| id?: string; | ||
| name?: string; | ||
| }; | ||
| environment?: string; | ||
| } | ||
| export interface HeadersLike { | ||
| get(name: string): string | null | undefined; | ||
| } | ||
| export interface RequestLike { | ||
| headers: HeadersLike | HeaderRecord; | ||
| } | ||
| export type HeaderRecord = Record<string, string | string[] | undefined>; | ||
| export interface CookieLike { | ||
| get(name: string): { | ||
| value?: string; | ||
| } | string | null | undefined; | ||
| } | ||
| export interface PassportIdentityInput { | ||
| headers?: HeadersLike | HeaderRecord; | ||
| cookies?: CookieLike; | ||
| cookieHeader?: string; | ||
| token?: string; | ||
| } | ||
| export interface PassportDevelopmentIdentityOptions { | ||
| audience?: string; | ||
| connectorId?: string; | ||
| enabled?: boolean; | ||
| environment?: string; | ||
| externalIssuer?: string; | ||
| externalSubject?: string; | ||
| issuer?: string; | ||
| owner?: string; | ||
| ownerId?: string; | ||
| project?: string; | ||
| projectId?: string; | ||
| } | ||
| export interface PassportIdentityOptions { | ||
| /** | ||
| * Verify an explicit local token against Passport JWKS. Request-context, | ||
| * header, and cookie tokens are always verified. | ||
| */ | ||
| verify?: boolean; | ||
| /** | ||
| * Allow a decoded but unverified explicit local token when `verify` is false. | ||
| */ | ||
| allowUnverified?: boolean; | ||
| /** | ||
| * Local development identity generation used when no Passport header/cookie | ||
| * exists. Defaults to enabled outside production and outside Vercel. Set to | ||
| * false to disable. | ||
| */ | ||
| development?: boolean | PassportDevelopmentIdentityOptions; | ||
| /** | ||
| * Local development identity used when no Passport header/cookie exists. | ||
| */ | ||
| localIdentity?: PassportIdentityPayload | string; | ||
| /** | ||
| * Environment variable name containing a JSON local development identity. | ||
| * Defaults to `VERCEL_PASSPORT_IDENTITY`. | ||
| */ | ||
| localIdentityEnv?: string; | ||
| /** | ||
| * Environment variable name containing a Passport JWT for local debugging. | ||
| * Defaults to `VERCEL_PASSPORT_TOKEN`. | ||
| */ | ||
| localTokenEnv?: string; | ||
| /** | ||
| * Options forwarded to the JWT verifier when verifying the token. | ||
| */ | ||
| verifyOptions?: PassportVerifyOptions; | ||
| } | ||
| export declare class PassportIdentityError extends Error { | ||
| constructor(message: string); | ||
| } | ||
| /** | ||
| * Read the Passport identity for the current request. | ||
| * | ||
| * The helper reads Vercel's request context by default. It prefers the trusted | ||
| * `x-vercel-oidc-passport-token` header and supports explicit cookie/token | ||
| * overrides for tests and local debugging. Request tokens are always verified | ||
| * against the dedicated Passport issuer and must include Passport-specific | ||
| * claims. | ||
| */ | ||
| export declare function getIdentity(input?: RequestLike | HeadersLike | HeaderRecord | PassportIdentityInput, options?: PassportIdentityOptions): Promise<PassportIdentity | null>; | ||
| export type PassportVerifyOptions = { | ||
| projectId?: string | string[] | '*'; | ||
| environment?: string | string[] | '*'; | ||
| ownerId?: string; | ||
| } & JWTVerifyOptions; |
+424
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| PASSPORT_COOKIE_NAME: () => PASSPORT_COOKIE_NAME, | ||
| PASSPORT_HEADER_NAME: () => PASSPORT_HEADER_NAME, | ||
| PassportIdentityError: () => PassportIdentityError, | ||
| getIdentity: () => getIdentity | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| var import_jose = require("jose"); | ||
| const PASSPORT_HEADER_NAME = "x-vercel-oidc-passport-token"; | ||
| const PASSPORT_COOKIE_NAME = "_vercel_passport"; | ||
| const PASSPORT_ISSUER = "https://passport.vercel.com"; | ||
| const VERCEL_OIDC_ISSUER = "https://oidc.vercel.com"; | ||
| const PASSPORT_JWKS = (0, import_jose.createRemoteJWKSet)( | ||
| new URL(`${VERCEL_OIDC_ISSUER}/.well-known/jwks`) | ||
| ); | ||
| const DEFAULT_ALGORITHMS = ["RS256"]; | ||
| const SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context"); | ||
| let hasWarnedAboutDevelopmentIdentity = false; | ||
| class PassportIdentityError extends Error { | ||
| constructor(message) { | ||
| super(message); | ||
| this.name = "PassportIdentityError"; | ||
| } | ||
| } | ||
| async function getIdentity(input, options = {}) { | ||
| const normalized = normalizeInput(input); | ||
| const context = getContext(); | ||
| const headers = normalized.headers ?? context.headers; | ||
| const tokenFromInput = normalized.token; | ||
| const headerToken = getHeader(headers, PASSPORT_HEADER_NAME); | ||
| const cookieToken = getCookie( | ||
| normalized.cookies, | ||
| normalized.cookieHeader, | ||
| PASSPORT_COOKIE_NAME | ||
| ); | ||
| const token = tokenFromInput ?? headerToken ?? cookieToken ?? getEnvToken(options); | ||
| const tokenSource = tokenFromInput ? "local" : headerToken ? "header" : cookieToken ? "cookie" : "local"; | ||
| if (token) { | ||
| const shouldVerify = tokenSource === "local" ? options.verify ?? false : true; | ||
| if (shouldVerify) { | ||
| const payload = await verifyPassportToken(token, options.verifyOptions); | ||
| return createIdentity(token, tokenSource, true, payload); | ||
| } | ||
| if (options.allowUnverified === false) { | ||
| throw new PassportIdentityError( | ||
| "Passport identity token verification is disabled and unverified tokens are not allowed." | ||
| ); | ||
| } | ||
| return createIdentity(token, tokenSource, false, decodeJwtPayload(token)); | ||
| } | ||
| const localIdentity = getLocalIdentity(options); | ||
| if (localIdentity) { | ||
| return createIdentity(null, "local", false, localIdentity); | ||
| } | ||
| return null; | ||
| } | ||
| function createIdentity(token, tokenSource, verified, payload) { | ||
| validatePassportPayload(payload); | ||
| return { | ||
| token, | ||
| tokenSource, | ||
| verified, | ||
| payload, | ||
| subject: payload.sub, | ||
| externalIssuer: stringClaim(payload.external_iss), | ||
| externalSubject: stringClaim(payload.external_sub), | ||
| connectorId: stringClaim(payload.connector_id), | ||
| email: stringClaim(payload.email), | ||
| name: stringClaim(payload.name), | ||
| owner: { | ||
| id: stringClaim(payload.owner_id), | ||
| slug: stringClaim(payload.owner) | ||
| }, | ||
| project: createProjectIdentity(payload), | ||
| environment: stringClaim(payload.environment) | ||
| }; | ||
| } | ||
| function normalizeInput(input) { | ||
| if (!input) { | ||
| return {}; | ||
| } | ||
| if (isPassportIdentityInput(input)) { | ||
| return input; | ||
| } | ||
| if (isRequestLike(input)) { | ||
| return { headers: input.headers }; | ||
| } | ||
| return { headers: input }; | ||
| } | ||
| function isPassportIdentityInput(input) { | ||
| if (!input || typeof input !== "object") { | ||
| return false; | ||
| } | ||
| return "token" in input || "cookies" in input || "cookieHeader" in input; | ||
| } | ||
| function isRequestLike(input) { | ||
| if (!input || typeof input !== "object" || !("headers" in input)) { | ||
| return false; | ||
| } | ||
| return !isHeadersLike(input); | ||
| } | ||
| function isHeadersLike(input) { | ||
| return Boolean( | ||
| input && typeof input === "object" && "get" in input && typeof input.get === "function" | ||
| ); | ||
| } | ||
| function getContext() { | ||
| const fromSymbol = globalThis; | ||
| return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {}; | ||
| } | ||
| function getHeader(headers, name) { | ||
| if (!headers) { | ||
| return void 0; | ||
| } | ||
| if ("get" in headers && typeof headers.get === "function") { | ||
| return headers.get(name) ?? void 0; | ||
| } | ||
| const lowerName = name.toLowerCase(); | ||
| const value = Object.entries(headers).find( | ||
| ([key]) => key.toLowerCase() === lowerName | ||
| )?.[1]; | ||
| return Array.isArray(value) ? value[0] : value; | ||
| } | ||
| function getCookie(cookies, cookieHeader, name) { | ||
| if (cookies) { | ||
| const value = cookies.get(name); | ||
| if (typeof value === "string") { | ||
| return value; | ||
| } | ||
| if (value?.value) { | ||
| return value.value; | ||
| } | ||
| } | ||
| if (!cookieHeader) { | ||
| return void 0; | ||
| } | ||
| for (const part of cookieHeader.split(";")) { | ||
| const [rawKey, ...rawValue] = part.trim().split("="); | ||
| if (rawKey === name) { | ||
| return rawValue.join("="); | ||
| } | ||
| } | ||
| return void 0; | ||
| } | ||
| function getEnvToken(options) { | ||
| const envName = options.localTokenEnv ?? "VERCEL_PASSPORT_TOKEN"; | ||
| return process.env[envName] || void 0; | ||
| } | ||
| function getLocalIdentity(options) { | ||
| const localIdentity = options.localIdentity; | ||
| if (typeof localIdentity === "object") { | ||
| return localIdentity; | ||
| } | ||
| if (typeof localIdentity === "string" && localIdentity !== "") { | ||
| return parseLocalIdentity(localIdentity); | ||
| } | ||
| const envName = options.localIdentityEnv ?? "VERCEL_PASSPORT_IDENTITY"; | ||
| const envValue = process.env[envName]; | ||
| if (envValue) { | ||
| return parseLocalIdentity(envValue); | ||
| } | ||
| return getDevelopmentIdentity(options); | ||
| } | ||
| function getDevelopmentIdentity(options) { | ||
| if (!isLocalDevelopmentEnvironment()) { | ||
| return void 0; | ||
| } | ||
| const development = options.development; | ||
| const config = typeof development === "object" ? development : {}; | ||
| const envEnabled = process.env.VERCEL_PASSPORT_DEV; | ||
| const enabled = development !== false && config.enabled !== false && envEnabled !== "0" && envEnabled !== "false"; | ||
| if (!enabled) { | ||
| return void 0; | ||
| } | ||
| const owner = config.owner ?? process.env.VERCEL_PASSPORT_DEV_OWNER ?? "local"; | ||
| const ownerId = config.ownerId ?? process.env.VERCEL_PASSPORT_DEV_OWNER_ID; | ||
| const connectorId = config.connectorId ?? process.env.VERCEL_PASSPORT_DEV_CONNECTOR_ID ?? "local"; | ||
| const externalIssuer = config.externalIssuer ?? process.env.VERCEL_PASSPORT_DEV_EXTERNAL_ISS; | ||
| const externalSubject = config.externalSubject ?? process.env.VERCEL_PASSPORT_DEV_EXTERNAL_SUB ?? "test-user"; | ||
| const environment = config.environment ?? process.env.VERCEL_PASSPORT_DEV_ENVIRONMENT ?? "development"; | ||
| const project = config.project ?? process.env.VERCEL_PASSPORT_DEV_PROJECT ?? "local"; | ||
| const projectId = config.projectId ?? process.env.VERCEL_PASSPORT_DEV_PROJECT_ID ?? process.env.VERCEL_PROJECT_ID; | ||
| const issuer = config.issuer ?? process.env.VERCEL_PASSPORT_DEV_ISSUER ?? `${PASSPORT_ISSUER}/${owner}`; | ||
| const audience = config.audience ?? process.env.VERCEL_PASSPORT_DEV_AUDIENCE ?? `https://vercel.com/${owner}/${project}/${environment}`; | ||
| const subject = `owner:${owner}:connector:${connectorId}:principal:${externalSubject}`; | ||
| warnAboutDevelopmentIdentity(); | ||
| return { | ||
| aud: audience, | ||
| connector_id: connectorId, | ||
| email: "test-user@passport.local", | ||
| environment, | ||
| ...externalIssuer ? { external_iss: externalIssuer } : {}, | ||
| external_sub: externalSubject, | ||
| iss: issuer, | ||
| name: "Test User", | ||
| owner, | ||
| ...ownerId ? { owner_id: ownerId } : {}, | ||
| project, | ||
| ...projectId ? { project_id: projectId } : {}, | ||
| scope: subject, | ||
| sub: subject, | ||
| typ: "passport" | ||
| }; | ||
| } | ||
| function isLocalDevelopmentEnvironment() { | ||
| if (process.env.VERCEL === "1" && process.env.VERCEL_ENV !== "development") { | ||
| return false; | ||
| } | ||
| return process.env.VERCEL_ENV === void 0 || process.env.VERCEL_ENV === "" || process.env.VERCEL_ENV === "development"; | ||
| } | ||
| function warnAboutDevelopmentIdentity() { | ||
| if (hasWarnedAboutDevelopmentIdentity) { | ||
| return; | ||
| } | ||
| hasWarnedAboutDevelopmentIdentity = true; | ||
| console.warn( | ||
| "[@vercel/passport] Using a local development Passport identity. Set VERCEL_PASSPORT_DEV=0 or pass { development: false } to disable this behavior." | ||
| ); | ||
| } | ||
| function parseLocalIdentity(value) { | ||
| try { | ||
| const parsed = JSON.parse(value); | ||
| if (!parsed || typeof parsed !== "object") { | ||
| throw new PassportIdentityError( | ||
| "Local Passport identity must be an object." | ||
| ); | ||
| } | ||
| return parsed; | ||
| } catch (error) { | ||
| if (error instanceof PassportIdentityError) { | ||
| throw error; | ||
| } | ||
| throw new PassportIdentityError( | ||
| "Local Passport identity must be valid JSON." | ||
| ); | ||
| } | ||
| } | ||
| function decodeJwtPayload(token) { | ||
| const [, payload] = token.split("."); | ||
| if (!payload) { | ||
| throw new PassportIdentityError("Passport identity token is not a JWT."); | ||
| } | ||
| const normalized = payload.replace(/-/g, "+").replace(/_/g, "/"); | ||
| const padded = normalized.padEnd( | ||
| normalized.length + (4 - normalized.length % 4) % 4, | ||
| "=" | ||
| ); | ||
| try { | ||
| return JSON.parse(Buffer.from(padded, "base64").toString("utf8")); | ||
| } catch { | ||
| throw new PassportIdentityError( | ||
| "Passport identity token payload is invalid." | ||
| ); | ||
| } | ||
| } | ||
| async function verifyPassportToken(token, options) { | ||
| const { | ||
| algorithms, | ||
| environment = process.env.VERCEL_TARGET_ENV || process.env.VERCEL_ENV, | ||
| ownerId, | ||
| projectId = process.env.VERCEL_PROJECT_ID, | ||
| ...verifyOptions | ||
| } = options ?? {}; | ||
| if (projectId === "*" && ownerId === void 0 && !hasAudienceVerification(verifyOptions.audience)) { | ||
| throw new TypeError( | ||
| "Expected ownerId or audience to be provided when projectId is '*'." | ||
| ); | ||
| } | ||
| const unverifiedPayload = decodeJwtPayload(token); | ||
| const { payload } = await (0, import_jose.jwtVerify)( | ||
| token, | ||
| getJwksForIssuer(unverifiedPayload.iss), | ||
| { | ||
| ...verifyOptions, | ||
| algorithms: algorithms ?? DEFAULT_ALGORITHMS | ||
| } | ||
| ); | ||
| validateIssuer(payload.iss); | ||
| validateClaim({ | ||
| actual: payload.project_id, | ||
| claim: "project_id", | ||
| env: "VERCEL_PROJECT_ID", | ||
| expected: projectId, | ||
| option: "projectId" | ||
| }); | ||
| validateClaim({ | ||
| actual: payload.environment, | ||
| claim: "environment", | ||
| env: "VERCEL_TARGET_ENV or VERCEL_ENV", | ||
| expected: environment, | ||
| option: "environment" | ||
| }); | ||
| validateOptionalClaim({ | ||
| actual: payload.owner_id, | ||
| claim: "owner_id", | ||
| expected: ownerId | ||
| }); | ||
| return payload; | ||
| } | ||
| function hasAudienceVerification(audience) { | ||
| return Array.isArray(audience) ? audience.length > 0 : audience !== void 0; | ||
| } | ||
| function getJwksForIssuer(issuer) { | ||
| validateIssuer(issuer); | ||
| return PASSPORT_JWKS; | ||
| } | ||
| function validateIssuer(actual) { | ||
| if (!isPassportIssuer(actual)) { | ||
| throw new TypeError( | ||
| `Expected Passport token iss claim to be "${PASSPORT_ISSUER}" scoped to an owner.` | ||
| ); | ||
| } | ||
| } | ||
| function isPassportIssuer(value) { | ||
| return value === PASSPORT_ISSUER || typeof value === "string" && value.startsWith(`${PASSPORT_ISSUER}/`); | ||
| } | ||
| function validateClaim({ | ||
| actual, | ||
| claim, | ||
| env, | ||
| expected, | ||
| option | ||
| }) { | ||
| if (expected === "*") { | ||
| return; | ||
| } | ||
| if (expected === void 0 || expected.length === 0) { | ||
| throw new TypeError( | ||
| `Expected ${env} to be set or ${option} to be provided. Pass ${option}: '*' to allow any ${claim} claim.` | ||
| ); | ||
| } | ||
| if (Array.isArray(expected) && typeof actual === "string" && expected.includes(actual)) { | ||
| return; | ||
| } | ||
| if (actual !== expected) { | ||
| throw new TypeError( | ||
| Array.isArray(expected) ? `Expected Passport token ${claim} claim to be one of: ${expected.map((value) => `"${value}"`).join(", ")}.` : `Expected Passport token ${claim} claim to be "${expected}".` | ||
| ); | ||
| } | ||
| } | ||
| function validateOptionalClaim({ | ||
| actual, | ||
| claim, | ||
| expected | ||
| }) { | ||
| if (expected === void 0) { | ||
| return; | ||
| } | ||
| if (actual !== expected) { | ||
| throw new TypeError( | ||
| `Expected Passport token ${claim} claim to be "${expected}".` | ||
| ); | ||
| } | ||
| } | ||
| function validatePassportPayload(payload) { | ||
| if (payload.typ !== "passport") { | ||
| throw new PassportIdentityError( | ||
| 'Passport identity token is missing typ="passport".' | ||
| ); | ||
| } | ||
| if (!payload.sub || typeof payload.sub !== "string") { | ||
| throw new PassportIdentityError( | ||
| "Passport identity is missing a sub claim." | ||
| ); | ||
| } | ||
| if (!payload.iss || typeof payload.iss !== "string") { | ||
| throw new PassportIdentityError( | ||
| "Passport identity is missing an iss claim." | ||
| ); | ||
| } | ||
| validateIssuer(payload.iss); | ||
| const owner = stringClaim(payload.owner); | ||
| const connectorId = stringClaim(payload.connector_id); | ||
| const externalSub = stringClaim(payload.external_sub); | ||
| if (!owner) { | ||
| throw new PassportIdentityError( | ||
| "Passport identity is missing an owner claim." | ||
| ); | ||
| } | ||
| if (!connectorId) { | ||
| throw new PassportIdentityError( | ||
| "Passport identity is missing a connector_id claim." | ||
| ); | ||
| } | ||
| if (!externalSub) { | ||
| throw new PassportIdentityError( | ||
| "Passport identity is missing an external_sub claim." | ||
| ); | ||
| } | ||
| } | ||
| function createProjectIdentity(payload) { | ||
| const id = stringClaim(payload.project_id); | ||
| const name = stringClaim(payload.project); | ||
| return id || name ? { id, name } : void 0; | ||
| } | ||
| function stringClaim(value) { | ||
| return typeof value === "string" ? value : void 0; | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| PASSPORT_COOKIE_NAME, | ||
| PASSPORT_HEADER_NAME, | ||
| PassportIdentityError, | ||
| getIdentity | ||
| }); |
+202
| Apache License | ||
| Version 2.0, January 2004 | ||
| http://www.apache.org/licenses/ | ||
| TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||
| 1. Definitions. | ||
| "License" shall mean the terms and conditions for use, reproduction, | ||
| and distribution as defined by Sections 1 through 9 of this document. | ||
| "Licensor" shall mean the copyright owner or entity authorized by | ||
| the copyright owner that is granting the License. | ||
| "Legal Entity" shall mean the union of the acting entity and all | ||
| other entities that control, are controlled by, or are under common | ||
| control with that entity. For the purposes of this definition, | ||
| "control" means (i) the power, direct or indirect, to cause the | ||
| direction or management of such entity, whether by contract or | ||
| otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||
| outstanding shares, or (iii) beneficial ownership of such entity. | ||
| "You" (or "Your") shall mean an individual or Legal Entity | ||
| exercising permissions granted by this License. | ||
| "Source" form shall mean the preferred form for making modifications, | ||
| including but not limited to software source code, documentation | ||
| source, and configuration files. | ||
| "Object" form shall mean any form resulting from mechanical | ||
| transformation or translation of a Source form, including but | ||
| not limited to compiled object code, generated documentation, | ||
| and conversions to other media types. | ||
| "Work" shall mean the work of authorship, whether in Source or | ||
| Object form, made available under the License, as indicated by a | ||
| copyright notice that is included in or attached to the work | ||
| (an example is provided in the Appendix below). | ||
| "Derivative Works" shall mean any work, whether in Source or Object | ||
| form, that is based on (or derived from) the Work and for which the | ||
| editorial revisions, annotations, elaborations, or other modifications | ||
| represent, as a whole, an original work of authorship. For the purposes | ||
| of this License, Derivative Works shall not include works that remain | ||
| separable from, or merely link (or bind by name) to the interfaces of, | ||
| the Work and Derivative Works thereof. | ||
| "Contribution" shall mean any work of authorship, including | ||
| the original version of the Work and any modifications or additions | ||
| to that Work or Derivative Works thereof, that is intentionally | ||
| submitted to Licensor for inclusion in the Work by the copyright owner | ||
| or by an individual or Legal Entity authorized to submit on behalf of | ||
| the copyright owner. For the purposes of this definition, "submitted" | ||
| means any form of electronic, verbal, or written communication sent | ||
| to the Licensor or its representatives, including but not limited to | ||
| communication on electronic mailing lists, source code control systems, | ||
| and issue tracking systems that are managed by, or on behalf of, the | ||
| Licensor for the purpose of discussing and improving the Work, but | ||
| excluding communication that is conspicuously marked or otherwise | ||
| designated in writing by the copyright owner as "Not a Contribution." | ||
| "Contributor" shall mean Licensor and any individual or Legal Entity | ||
| on behalf of whom a Contribution has been received by Licensor and | ||
| subsequently incorporated within the Work. | ||
| 2. Grant of Copyright License. Subject to the terms and conditions of | ||
| this License, each Contributor hereby grants to You a perpetual, | ||
| worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| copyright license to reproduce, prepare Derivative Works of, | ||
| publicly display, publicly perform, sublicense, and distribute the | ||
| Work and such Derivative Works in Source or Object form. | ||
| 3. Grant of Patent License. Subject to the terms and conditions of | ||
| this License, each Contributor hereby grants to You a perpetual, | ||
| worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| (except as stated in this section) patent license to make, have made, | ||
| use, offer to sell, sell, import, and otherwise transfer the Work, | ||
| where such license applies only to those patent claims licensable | ||
| by such Contributor that are necessarily infringed by their | ||
| Contribution(s) alone or by combination of their Contribution(s) | ||
| with the Work to which such Contribution(s) was submitted. If You | ||
| institute patent litigation against any entity (including a | ||
| cross-claim or counterclaim in a lawsuit) alleging that the Work | ||
| or a Contribution incorporated within the Work constitutes direct | ||
| or contributory patent infringement, then any patent licenses | ||
| granted to You under this License for that Work shall terminate | ||
| as of the date such litigation is filed. | ||
| 4. Redistribution. You may reproduce and distribute copies of the | ||
| Work or Derivative Works thereof in any medium, with or without | ||
| modifications, and in Source or Object form, provided that You | ||
| meet the following conditions: | ||
| (a) You must give any other recipients of the Work or | ||
| Derivative Works a copy of this License; and | ||
| (b) You must cause any modified files to carry prominent notices | ||
| stating that You changed the files; and | ||
| (c) You must retain, in the Source form of any Derivative Works | ||
| that You distribute, all copyright, patent, trademark, and | ||
| attribution notices from the Source form of the Work, | ||
| excluding those notices that do not pertain to any part of | ||
| the Derivative Works; and | ||
| (d) If the Work includes a "NOTICE" text file as part of its | ||
| distribution, then any Derivative Works that You distribute must | ||
| include a readable copy of the attribution notices contained | ||
| within such NOTICE file, excluding those notices that do not | ||
| pertain to any part of the Derivative Works, in at least one | ||
| of the following places: within a NOTICE text file distributed | ||
| as part of the Derivative Works; within the Source form or | ||
| documentation, if provided along with the Derivative Works; or, | ||
| within a display generated by the Derivative Works, if and | ||
| wherever such third-party notices normally appear. The contents | ||
| of the NOTICE file are for informational purposes only and | ||
| do not modify the License. You may add Your own attribution | ||
| notices within Derivative Works that You distribute, alongside | ||
| or as an addendum to the NOTICE text from the Work, provided | ||
| that such additional attribution notices cannot be construed | ||
| as modifying the License. | ||
| You may add Your own copyright statement to Your modifications and | ||
| may provide additional or different license terms and conditions | ||
| for use, reproduction, or distribution of Your modifications, or | ||
| for any such Derivative Works as a whole, provided Your use, | ||
| reproduction, and distribution of the Work otherwise complies with | ||
| the conditions stated in this License. | ||
| 5. Submission of Contributions. Unless You explicitly state otherwise, | ||
| any Contribution intentionally submitted for inclusion in the Work | ||
| by You to the Licensor shall be under the terms and conditions of | ||
| this License, without any additional terms or conditions. | ||
| Notwithstanding the above, nothing herein shall supersede or modify | ||
| the terms of any separate license agreement you may have executed | ||
| with Licensor regarding such Contributions. | ||
| 6. Trademarks. This License does not grant permission to use the trade | ||
| names, trademarks, service marks, or product names of the Licensor, | ||
| except as required for reasonable and customary use in describing the | ||
| origin of the Work and reproducing the content of the NOTICE file. | ||
| 7. Disclaimer of Warranty. Unless required by applicable law or | ||
| agreed to in writing, Licensor provides the Work (and each | ||
| Contributor provides its Contributions) on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| implied, including, without limitation, any warranties or conditions | ||
| of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||
| PARTICULAR PURPOSE. You are solely responsible for determining the | ||
| appropriateness of using or redistributing the Work and assume any | ||
| risks associated with Your exercise of permissions under this License. | ||
| 8. Limitation of Liability. In no event and under no legal theory, | ||
| whether in tort (including negligence), contract, or otherwise, | ||
| unless required by applicable law (such as deliberate and grossly | ||
| negligent acts) or agreed to in writing, shall any Contributor be | ||
| liable to You for damages, including any direct, indirect, special, | ||
| incidental, or consequential damages of any character arising as a | ||
| result of this License or out of the use or inability to use the | ||
| Work (including but not limited to damages for loss of goodwill, | ||
| work stoppage, computer failure or malfunction, or any and all | ||
| other commercial damages or losses), even if such Contributor | ||
| has been advised of the possibility of such damages. | ||
| 9. Accepting Warranty or Additional Liability. While redistributing | ||
| the Work or Derivative Works thereof, You may choose to offer, | ||
| and charge a fee for, acceptance of support, warranty, indemnity, | ||
| or other liability obligations and/or rights consistent with this | ||
| License. However, in accepting such obligations, You may act only | ||
| on Your own behalf and on Your sole responsibility, not on behalf | ||
| of any other Contributor, and only if You agree to indemnify, | ||
| defend, and hold each Contributor harmless for any liability | ||
| incurred by, or claims asserted against, such Contributor by reason | ||
| of your accepting any such warranty or additional liability. | ||
| END OF TERMS AND CONDITIONS | ||
| APPENDIX: How to apply the Apache License to your work. | ||
| To apply the Apache License to your work, attach the following | ||
| boilerplate notice, with the fields enclosed by brackets "[]" | ||
| replaced with your own identifying information. (Don't include | ||
| the brackets!) The text should be enclosed in the appropriate | ||
| comment syntax for the file format. We also recommend that a | ||
| file or class name and description of purpose be included on the | ||
| same "printed page" as the copyright notice for easier | ||
| identification within third-party archives. | ||
| Copyright 2017 Vercel, Inc. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. |
+44
-4
| { | ||
| "name": "@vercel/passport", | ||
| "version": "0.0.1", | ||
| "description": "Placeholder — not yet released", | ||
| "license": "MIT" | ||
| } | ||
| "description": "Runtime Passport identity helpers intended for use with Vercel Functions", | ||
| "homepage": "https://vercel.com", | ||
| "files": [ | ||
| "dist", | ||
| "README.md", | ||
| "CHANGELOG.md" | ||
| ], | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/index.js" | ||
| } | ||
| }, | ||
| "version": "0.1.1", | ||
| "repository": { | ||
| "directory": "packages/passport", | ||
| "type": "git", | ||
| "url": "git+https://github.com/vercel/vercel.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/vercel/vercel/issues" | ||
| }, | ||
| "dependencies": { | ||
| "jose": "5.9.6" | ||
| }, | ||
| "devDependencies": { | ||
| "vitest": "2.0.1" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 20" | ||
| }, | ||
| "license": "Apache-2.0", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "scripts": { | ||
| "build": "node ../../utils/build.mjs", | ||
| "test": "vitest run --config ../../vitest.config.mts", | ||
| "type-check": "tsc --noEmit", | ||
| "vitest-unit": "pnpm test" | ||
| } | ||
| } |
+115
-0
| # @vercel/passport | ||
| Runtime helpers for reading Passport identity inside Vercel Functions. | ||
| ## Usage | ||
| ```ts | ||
| import { getIdentity } from '@vercel/passport'; | ||
| export async function GET() { | ||
| const identity = await getIdentity(); | ||
| if (!identity) { | ||
| return Response.json({ authenticated: false }, { status: 401 }); | ||
| } | ||
| return Response.json({ | ||
| authenticated: true, | ||
| externalSubject: identity.externalSubject, | ||
| subject: identity.subject, | ||
| }); | ||
| } | ||
| ``` | ||
| In local development, tests, or environments without Vercel request context, pass headers and cookies explicitly: | ||
| ```ts | ||
| import { getIdentity } from '@vercel/passport'; | ||
| import { cookies, headers } from 'next/headers'; | ||
| export async function GET() { | ||
| const identity = await getIdentity({ | ||
| cookies: await cookies(), | ||
| headers: await headers(), | ||
| }); | ||
| return Response.json({ identity }); | ||
| } | ||
| ``` | ||
| `getIdentity` reads the `x-vercel-oidc-passport-token` header injected by | ||
| Vercel after Passport validates the visitor. For tests and local debugging, you | ||
| can also pass the `_vercel_passport` cookie explicitly. | ||
| By default, request tokens are verified against Vercel's OIDC JWKS. The helper | ||
| only accepts the dedicated `https://passport.vercel.com/{owner}` issuer. It also | ||
| validates the Passport-specific token shape so regular Vercel OIDC tokens are | ||
| not accepted as Passport identities. | ||
| ## Local development | ||
| Local development usually does not have a real `_vercel_passport` cookie or | ||
| `x-vercel-oidc-passport-token` header, because those are created by Passport in | ||
| Vercel's edge network. In local development, `getIdentity()` returns a hardcoded | ||
| Passport-shaped test identity and logs a warning the first time it does so. | ||
| The default test identity uses: | ||
| ```txt | ||
| externalSubject: test-user | ||
| email: test-user@passport.local | ||
| name: Test User | ||
| ``` | ||
| Override individual fields with: | ||
| ```bash | ||
| VERCEL_PASSPORT_DEV_OWNER=acme | ||
| VERCEL_PASSPORT_DEV_CONNECTOR_ID=scl_dev | ||
| VERCEL_PASSPORT_DEV_EXTERNAL_SUB=user_dev | ||
| VERCEL_PASSPORT_DEV_EXTERNAL_ISS=https://idp.example.com | ||
| VERCEL_PASSPORT_DEV_PROJECT=my-project | ||
| VERCEL_PASSPORT_DEV_PROJECT_ID=prj_local | ||
| ``` | ||
| Disable the local test identity with: | ||
| ```bash | ||
| VERCEL_PASSPORT_DEV=0 | ||
| ``` | ||
| or: | ||
| ```ts | ||
| const identity = await getIdentity(undefined, { development: false }); | ||
| ``` | ||
| Or provide the full payload yourself: | ||
| ```ts | ||
| const identity = await getIdentity(undefined, { | ||
| localIdentity: { | ||
| typ: 'passport', | ||
| iss: 'https://passport.vercel.com/local', | ||
| owner: 'local', | ||
| connector_id: 'local', | ||
| external_sub: 'local-user', | ||
| sub: 'owner:local:connector:local:principal:local-user', | ||
| }, | ||
| }); | ||
| ``` | ||
| Development identities are ignored on Vercel unless `VERCEL_ENV=development`. | ||
| You can also copy a Passport token from a deployed request and pass it directly | ||
| for debugging: | ||
| ```ts | ||
| const identity = await getIdentity( | ||
| { token: process.env.VERCEL_PASSPORT_TOKEN }, | ||
| { verify: false } | ||
| ); | ||
| ``` | ||
| Only disable verification for local debugging. In deployed code, use the default | ||
| verification behavior. |
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.
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 16 instances
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
No website
QualityPackage does not have a website.
33549
22722.45%6
200%555
Infinity%1
-50%1
-50%117
5750%1
Infinity%1
Infinity%23
2200%+ Added
+ Added