@vercel/oidc 3.5.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ [**@vercel/oidc**](../README.md)
2
+
3
+ ---
4
+
5
+ # Function: verifyVercelOidcToken()
6
+
7
+ > **verifyVercelOidcToken**\<`PayloadType`\>(`token`, `options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`JWTVerifyResult`\<`PayloadType`\>\>
8
+
9
+ Defined in: [packages/oidc/src/verify-vercel-oidc-token.ts:53](https://github.com/vercel/vercel/blob/main/packages/oidc/src/verify-vercel-oidc-token.ts#L53)
10
+
11
+ Verifies a Vercel OIDC token against Vercel's remote JWKS.
12
+
13
+ The issuer must be `https://oidc.vercel.com` or start with
14
+ `https://oidc.vercel.com/`. The JWKS is always
15
+ `https://oidc.vercel.com/.well-known/jwks`.
16
+
17
+ Options:
18
+
19
+ - `issuer`: Expected `iss` claim verified by Jose. The verified issuer must
20
+ still be `https://oidc.vercel.com` or start with
21
+ `https://oidc.vercel.com/`.
22
+ - `projectId`: Expected `project_id` claim or claims. Defaults to
23
+ `process.env.VERCEL_PROJECT_ID`. Pass an array to allow any matching
24
+ project ID. Pass `'*'` to allow any project ID. When `projectId` is `'*'`,
25
+ either `ownerId` or `audience` is required.
26
+ - `environment`: Expected `environment` claim or claims. Defaults to
27
+ `process.env.VERCEL_TARGET_ENV || process.env.VERCEL_ENV`. Pass an array
28
+ to allow any matching environment. Pass `'*'` to allow any environment.
29
+ - `ownerId`: Expected `owner_id` claim. When omitted, the claim is not
30
+ checked.
31
+ - Any other Jose JWT verification option.
32
+
33
+ ## Type Parameters
34
+
35
+ ### PayloadType
36
+
37
+ `PayloadType` = [`VercelOidcPayload`](../type-aliases/VercelOidcPayload.md)
38
+
39
+ ## Parameters
40
+
41
+ ### token
42
+
43
+ `string`
44
+
45
+ The Vercel OIDC token to verify.
46
+
47
+ ### options?
48
+
49
+ `object` & `JWTVerifyOptions`
50
+
51
+ Optional Jose JWT verification options.
52
+
53
+ ## Returns
54
+
55
+ [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`JWTVerifyResult`\<`PayloadType`\>\>
56
+
57
+ Jose's verified JWT result.
@@ -0,0 +1,39 @@
1
+ [**@vercel/oidc**](../README.md)
2
+
3
+ ---
4
+
5
+ # Type Alias: VercelOidcPayload
6
+
7
+ > **VercelOidcPayload** = `JWTPayload` & `object`
8
+
9
+ Defined in: [packages/oidc/src/verify-vercel-oidc-token.ts:16](https://github.com/vercel/vercel/blob/main/packages/oidc/src/verify-vercel-oidc-token.ts#L16)
10
+
11
+ ## Type Declaration
12
+
13
+ ### aud
14
+
15
+ > **aud**: `string`
16
+
17
+ ### environment
18
+
19
+ > **environment**: `string`
20
+
21
+ ### external_sub?
22
+
23
+ > `optional` **external_sub?**: `string`
24
+
25
+ ### iss
26
+
27
+ > **iss**: `string`
28
+
29
+ ### owner_id
30
+
31
+ > **owner_id**: `string`
32
+
33
+ ### project_id
34
+
35
+ > **project_id**: `string`
36
+
37
+ ### sub
38
+
39
+ > **sub**: `string`
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "require": "./dist/index.js"
19
19
  }
20
20
  },
21
- "version": "3.5.0",
21
+ "version": "3.6.1",
22
22
  "repository": {
23
23
  "directory": "packages/oidc",
24
24
  "type": "git",
@@ -27,6 +27,11 @@
27
27
  "bugs": {
28
28
  "url": "https://github.com/vercel/vercel/issues"
29
29
  },
30
+ "dependencies": {
31
+ "jose": "^5.9.6",
32
+ "@vercel/cli-config": "0.2.0",
33
+ "@vercel/cli-exec": "0.1.1"
34
+ },
30
35
  "devDependencies": {
31
36
  "prettier": "3.8.3",
32
37
  "tinyspawn": "1.3.1",
@@ -1,30 +0,0 @@
1
- /**
2
- * Auth configuration stored in ~/.../com.vercel.cli/auth.json
3
- */
4
- export interface AuthConfig {
5
- /** An `access_token` obtained using the OAuth Device Authorization flow. */
6
- token?: string;
7
- /** A `refresh_token` obtained using the OAuth Device Authorization flow. */
8
- refreshToken?: string;
9
- /**
10
- * The absolute time (seconds) when the token expires.
11
- * Used to optimistically check if the token is still valid.
12
- */
13
- expiresAt?: number;
14
- /** Whether to skip writing this config to disk. */
15
- skipWrite?: boolean;
16
- }
17
- /**
18
- * Read the auth config from disk
19
- * Returns null if the file doesn't exist or cannot be read
20
- */
21
- export declare function readAuthConfig(): AuthConfig | null;
22
- /**
23
- * Write the auth config to disk with proper permissions
24
- */
25
- export declare function writeAuthConfig(config: AuthConfig): void;
26
- /**
27
- * Check if an access token is valid (not expired)
28
- * Copied from packages/cli/src/util/client.ts:72-81
29
- */
30
- export declare function isValidAccessToken(authConfig: AuthConfig, expirationBufferMs?: number): boolean;
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var auth_config_exports = {};
30
- __export(auth_config_exports, {
31
- isValidAccessToken: () => isValidAccessToken,
32
- readAuthConfig: () => readAuthConfig,
33
- writeAuthConfig: () => writeAuthConfig
34
- });
35
- module.exports = __toCommonJS(auth_config_exports);
36
- var fs = __toESM(require("fs"));
37
- var path = __toESM(require("path"));
38
- var import_token_util = require("./token-util");
39
- function getAuthConfigPath() {
40
- const dataDir = (0, import_token_util.getVercelDataDir)();
41
- if (!dataDir) {
42
- throw new Error(
43
- `Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`
44
- );
45
- }
46
- return path.join(dataDir, "auth.json");
47
- }
48
- function readAuthConfig() {
49
- try {
50
- const authPath = getAuthConfigPath();
51
- if (!fs.existsSync(authPath)) {
52
- return null;
53
- }
54
- const content = fs.readFileSync(authPath, "utf8");
55
- if (!content) {
56
- return null;
57
- }
58
- return JSON.parse(content);
59
- } catch (_error) {
60
- return null;
61
- }
62
- }
63
- function writeAuthConfig(config) {
64
- const authPath = getAuthConfigPath();
65
- const authDir = path.dirname(authPath);
66
- if (!fs.existsSync(authDir)) {
67
- fs.mkdirSync(authDir, { mode: 504, recursive: true });
68
- }
69
- fs.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
70
- }
71
- function isValidAccessToken(authConfig, expirationBufferMs = 0) {
72
- if (!authConfig.token)
73
- return false;
74
- if (typeof authConfig.expiresAt !== "number")
75
- return true;
76
- const nowInSeconds = Math.floor(Date.now() / 1e3);
77
- const bufferInSeconds = expirationBufferMs / 1e3;
78
- return authConfig.expiresAt >= nowInSeconds + bufferInSeconds;
79
- }
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- isValidAccessToken,
83
- readAuthConfig,
84
- writeAuthConfig
85
- });