@vercel/oidc 3.4.0 → 3.5.0
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.
- package/CHANGELOG.md +12 -0
- package/dist/get-vercel-oidc-token-sync.d.ts +22 -0
- package/dist/get-vercel-oidc-token-sync.js +37 -0
- package/dist/{get-vercel-oidc-token.d.ts → get-vercel-oidc-token-with-refresh.d.ts} +0 -22
- package/dist/{get-vercel-oidc-token.js → get-vercel-oidc-token-with-refresh.js} +8 -19
- package/dist/{get-vercel-oidc-token.test.js → get-vercel-oidc-token-with-refresh.test.js} +17 -17
- package/dist/index-edge-light.d.ts +11 -0
- package/dist/index-edge-light.js +47 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -3
- package/docs/README.md +9 -141
- package/docs/classes/AccessTokenMissingError.md +58 -80
- package/docs/classes/RefreshAccessTokenFailedError.md +61 -83
- package/docs/functions/getContext.md +13 -0
- package/docs/functions/getVercelOidcToken.md +62 -0
- package/docs/functions/getVercelOidcTokenSync.md +36 -0
- package/docs/functions/getVercelToken.md +19 -0
- package/package.json +5 -4
- /package/dist/{get-vercel-oidc-token.test.d.ts → get-vercel-oidc-token-with-refresh.test.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the current OIDC token from the request context or the environment variable.
|
|
3
|
+
*
|
|
4
|
+
* Do not cache this value, as it is subject to change in production!
|
|
5
|
+
*
|
|
6
|
+
* This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
7
|
+
* It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
8
|
+
*
|
|
9
|
+
* This function will not refresh the token if it is expired. For refreshing the token, use the @{link getVercelOidcToken} function.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} The OIDC token.
|
|
12
|
+
* @throws {Error} If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* // Using the OIDC token
|
|
18
|
+
* const token = getVercelOidcTokenSync();
|
|
19
|
+
* console.log('OIDC Token:', token);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function getVercelOidcTokenSync(): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_vercel_oidc_token_sync_exports = {};
|
|
20
|
+
__export(get_vercel_oidc_token_sync_exports, {
|
|
21
|
+
getVercelOidcTokenSync: () => getVercelOidcTokenSync
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_vercel_oidc_token_sync_exports);
|
|
24
|
+
var import_get_context = require("./get-context");
|
|
25
|
+
function getVercelOidcTokenSync() {
|
|
26
|
+
const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
|
|
27
|
+
if (!token) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`The 'x-vercel-oidc-token' header is missing from the request.`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return token;
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
getVercelOidcTokenSync
|
|
37
|
+
});
|
|
@@ -58,25 +58,3 @@ export interface GetVercelOidcTokenOptions {
|
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
60
|
export declare function getVercelOidcToken(options?: GetVercelOidcTokenOptions): Promise<string>;
|
|
61
|
-
/**
|
|
62
|
-
* Gets the current OIDC token from the request context or the environment variable.
|
|
63
|
-
*
|
|
64
|
-
* Do not cache this value, as it is subject to change in production!
|
|
65
|
-
*
|
|
66
|
-
* This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
67
|
-
* It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
68
|
-
*
|
|
69
|
-
* This function will not refresh the token if it is expired. For refreshing the token, use the @{link getVercelOidcToken} function.
|
|
70
|
-
*
|
|
71
|
-
* @returns {string} The OIDC token.
|
|
72
|
-
* @throws {Error} If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
*
|
|
76
|
-
* ```js
|
|
77
|
-
* // Using the OIDC token
|
|
78
|
-
* const token = getVercelOidcTokenSync();
|
|
79
|
-
* console.log('OIDC Token:', token);
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export declare function getVercelOidcTokenSync(): string;
|
|
@@ -26,19 +26,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
getVercelOidcToken: () => getVercelOidcToken
|
|
32
|
-
getVercelOidcTokenSync: () => getVercelOidcTokenSync
|
|
29
|
+
var get_vercel_oidc_token_with_refresh_exports = {};
|
|
30
|
+
__export(get_vercel_oidc_token_with_refresh_exports, {
|
|
31
|
+
getVercelOidcToken: () => getVercelOidcToken
|
|
33
32
|
});
|
|
34
|
-
module.exports = __toCommonJS(
|
|
35
|
-
var
|
|
33
|
+
module.exports = __toCommonJS(get_vercel_oidc_token_with_refresh_exports);
|
|
34
|
+
var import_get_vercel_oidc_token_sync = require("./get-vercel-oidc-token-sync");
|
|
36
35
|
var import_token_error = require("./token-error");
|
|
37
36
|
async function getVercelOidcToken(options) {
|
|
38
37
|
let token = "";
|
|
39
38
|
let err;
|
|
40
39
|
try {
|
|
41
|
-
token = getVercelOidcTokenSync();
|
|
40
|
+
token = (0, import_get_vercel_oidc_token_sync.getVercelOidcTokenSync)();
|
|
42
41
|
} catch (error) {
|
|
43
42
|
err = error;
|
|
44
43
|
}
|
|
@@ -49,7 +48,7 @@ async function getVercelOidcToken(options) {
|
|
|
49
48
|
]);
|
|
50
49
|
if (!token || isExpired(getTokenPayload(token), options?.expirationBufferMs)) {
|
|
51
50
|
await refreshToken(options);
|
|
52
|
-
token = getVercelOidcTokenSync();
|
|
51
|
+
token = (0, import_get_vercel_oidc_token_sync.getVercelOidcTokenSync)();
|
|
53
52
|
}
|
|
54
53
|
} catch (error) {
|
|
55
54
|
let message = err instanceof Error ? err.message : "";
|
|
@@ -64,17 +63,7 @@ ${error.message}`;
|
|
|
64
63
|
}
|
|
65
64
|
return token;
|
|
66
65
|
}
|
|
67
|
-
function getVercelOidcTokenSync() {
|
|
68
|
-
const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
|
|
69
|
-
if (!token) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
return token;
|
|
75
|
-
}
|
|
76
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
77
67
|
0 && (module.exports = {
|
|
78
|
-
getVercelOidcToken
|
|
79
|
-
getVercelOidcTokenSync
|
|
68
|
+
getVercelOidcToken
|
|
80
69
|
});
|
|
@@ -27,7 +27,7 @@ var os = __toESM(require("os"));
|
|
|
27
27
|
var path = __toESM(require("path"));
|
|
28
28
|
var fs = __toESM(require("fs"));
|
|
29
29
|
var import_token_io = require("./token-io");
|
|
30
|
-
var
|
|
30
|
+
var import_get_vercel_oidc_token_with_refresh = require("./get-vercel-oidc-token-with-refresh");
|
|
31
31
|
var tokenUtil = __toESM(require("./token-util"));
|
|
32
32
|
import_vitest.vi.mock("./token-io");
|
|
33
33
|
import_vitest.vi.mock("./get-context", () => ({
|
|
@@ -69,7 +69,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
69
69
|
JSON.stringify({ projectId, orgId: teamId })
|
|
70
70
|
);
|
|
71
71
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
72
|
-
await (0, import_vitest.expect)((0,
|
|
72
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
73
73
|
/No authentication found/
|
|
74
74
|
);
|
|
75
75
|
});
|
|
@@ -79,14 +79,14 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
79
79
|
JSON.stringify({ token: "test-auth-token" })
|
|
80
80
|
);
|
|
81
81
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
82
|
-
await (0, import_vitest.expect)((0,
|
|
82
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
83
83
|
/project\.json not found, have you linked your project with `vc link\?`/
|
|
84
84
|
);
|
|
85
85
|
});
|
|
86
86
|
(0, import_vitest.test)("should throw helpful error when root directory cannot be found", async () => {
|
|
87
87
|
import_vitest.vi.mocked(import_token_io.findRootDir).mockReturnValue(null);
|
|
88
88
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
89
|
-
await (0, import_vitest.expect)((0,
|
|
89
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
90
90
|
/Unable to find project root directory\. Have you linked your project with `vc link\?`/
|
|
91
91
|
);
|
|
92
92
|
});
|
|
@@ -97,7 +97,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
97
97
|
);
|
|
98
98
|
import_vitest.vi.mocked(import_token_io.getUserDataDir).mockReturnValue(null);
|
|
99
99
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
100
|
-
await (0, import_vitest.expect)((0,
|
|
100
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
101
101
|
/Unable to find user data directory\. Please reach out to Vercel support\./
|
|
102
102
|
);
|
|
103
103
|
});
|
|
@@ -114,7 +114,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
114
114
|
new Error("Failed to refresh OIDC token: Unauthorized")
|
|
115
115
|
);
|
|
116
116
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
117
|
-
await (0, import_vitest.expect)((0,
|
|
117
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
118
118
|
/Failed to refresh OIDC token: Unauthorized/
|
|
119
119
|
);
|
|
120
120
|
});
|
|
@@ -133,7 +133,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
133
133
|
)
|
|
134
134
|
);
|
|
135
135
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
136
|
-
await (0, import_vitest.expect)((0,
|
|
136
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
137
137
|
/Vercel OIDC token is malformed\. Expected a string-valued token property\. Please run `vc env pull` and try again/
|
|
138
138
|
);
|
|
139
139
|
});
|
|
@@ -142,19 +142,19 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
142
142
|
import_vitest.vi.spyOn(tokenUtil, "getTokenPayload").mockImplementation(() => {
|
|
143
143
|
throw new Error("Invalid token. Please run `vc env pull` and try again");
|
|
144
144
|
});
|
|
145
|
-
await (0, import_vitest.expect)((0,
|
|
145
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
146
146
|
/Invalid token\. Please run `vc env pull` and try again/
|
|
147
147
|
);
|
|
148
148
|
});
|
|
149
149
|
(0, import_vitest.test)("should throw error when token expiry check fails", async () => {
|
|
150
150
|
process.env.VERCEL_OIDC_TOKEN = "not-a-jwt-token";
|
|
151
|
-
await (0, import_vitest.expect)((0,
|
|
151
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(
|
|
152
152
|
/Invalid token\. Please run `vc env pull` and try again/
|
|
153
153
|
);
|
|
154
154
|
});
|
|
155
155
|
(0, import_vitest.test)("should fail when no token exists and no CLI credentials available", async () => {
|
|
156
156
|
process.env.VERCEL_OIDC_TOKEN = void 0;
|
|
157
|
-
await (0, import_vitest.expect)((0,
|
|
157
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(/Invalid token/);
|
|
158
158
|
});
|
|
159
159
|
(0, import_vitest.test)("should propagate filesystem errors when saving token fails", async () => {
|
|
160
160
|
fs.writeFileSync(
|
|
@@ -177,7 +177,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
177
177
|
throw new Error("EACCES: permission denied");
|
|
178
178
|
});
|
|
179
179
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
180
|
-
await (0, import_vitest.expect)((0,
|
|
180
|
+
await (0, import_vitest.expect)((0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)()).rejects.toThrow(/EACCES|permission/i);
|
|
181
181
|
});
|
|
182
182
|
(0, import_vitest.test)("should succeed when valid token exists in env", async () => {
|
|
183
183
|
const validToken = createValidToken();
|
|
@@ -187,7 +187,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
187
187
|
name: "test-name",
|
|
188
188
|
exp: Date.now() / 1e3 + 43200
|
|
189
189
|
});
|
|
190
|
-
const token = await (0,
|
|
190
|
+
const token = await (0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)();
|
|
191
191
|
(0, import_vitest.expect)(token).toBe(validToken);
|
|
192
192
|
});
|
|
193
193
|
(0, import_vitest.test)("should refresh when token is expired but all configs are valid", async () => {
|
|
@@ -213,7 +213,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
213
213
|
exp: Date.now() / 1e3 + 43200
|
|
214
214
|
});
|
|
215
215
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
216
|
-
const token = await (0,
|
|
216
|
+
const token = await (0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)();
|
|
217
217
|
(0, import_vitest.expect)(token).toBe(newToken);
|
|
218
218
|
});
|
|
219
219
|
(0, import_vitest.test)("should use provided team and project for refresh instead of reading project.json", async () => {
|
|
@@ -237,7 +237,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
237
237
|
exp: Date.now() / 1e3 + 43200
|
|
238
238
|
});
|
|
239
239
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
240
|
-
const token = await (0,
|
|
240
|
+
const token = await (0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)({
|
|
241
241
|
team: customTeamId,
|
|
242
242
|
project: customProjectId
|
|
243
243
|
});
|
|
@@ -272,7 +272,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
272
272
|
exp: Date.now() / 1e3 + 43200
|
|
273
273
|
});
|
|
274
274
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
275
|
-
const token = await (0,
|
|
275
|
+
const token = await (0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)({
|
|
276
276
|
project: customProjectId
|
|
277
277
|
});
|
|
278
278
|
(0, import_vitest.expect)(token).toBe(newToken);
|
|
@@ -306,7 +306,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
306
306
|
exp: Date.now() / 1e3 + 43200
|
|
307
307
|
});
|
|
308
308
|
process.env.VERCEL_OIDC_TOKEN = createExpiredToken();
|
|
309
|
-
const token = await (0,
|
|
309
|
+
const token = await (0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)({
|
|
310
310
|
team: customTeamId
|
|
311
311
|
});
|
|
312
312
|
(0, import_vitest.expect)(token).toBe(newToken);
|
|
@@ -327,7 +327,7 @@ import_vitest.vi.mock("./get-context", () => ({
|
|
|
327
327
|
name: "test-name",
|
|
328
328
|
exp: Date.now() / 1e3 + 43200
|
|
329
329
|
});
|
|
330
|
-
const token = await (0,
|
|
330
|
+
const token = await (0, import_get_vercel_oidc_token_with_refresh.getVercelOidcToken)({
|
|
331
331
|
team: "custom-team",
|
|
332
332
|
project: "custom-project"
|
|
333
333
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { getContext } from './get-context';
|
|
2
|
+
export { AccessTokenMissingError, RefreshAccessTokenFailedError, } from './auth-errors';
|
|
3
|
+
export { getVercelOidcTokenSync } from './get-vercel-oidc-token-sync';
|
|
4
|
+
/**
|
|
5
|
+
* Gets the current OIDC token in Edge Runtime.
|
|
6
|
+
*
|
|
7
|
+
* Edge Runtime does not support automatic token refresh, so this returns the
|
|
8
|
+
* request-scoped token without checking expiration.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getVercelOidcToken(): Promise<string>;
|
|
11
|
+
export declare function getVercelToken(): Promise<string>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var index_edge_light_exports = {};
|
|
20
|
+
__export(index_edge_light_exports, {
|
|
21
|
+
AccessTokenMissingError: () => import_auth_errors.AccessTokenMissingError,
|
|
22
|
+
RefreshAccessTokenFailedError: () => import_auth_errors.RefreshAccessTokenFailedError,
|
|
23
|
+
getContext: () => import_get_context.getContext,
|
|
24
|
+
getVercelOidcToken: () => getVercelOidcToken,
|
|
25
|
+
getVercelOidcTokenSync: () => import_get_vercel_oidc_token_sync2.getVercelOidcTokenSync,
|
|
26
|
+
getVercelToken: () => getVercelToken
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_edge_light_exports);
|
|
29
|
+
var import_get_vercel_oidc_token_sync = require("./get-vercel-oidc-token-sync");
|
|
30
|
+
var import_get_context = require("./get-context");
|
|
31
|
+
var import_auth_errors = require("./auth-errors");
|
|
32
|
+
var import_get_vercel_oidc_token_sync2 = require("./get-vercel-oidc-token-sync");
|
|
33
|
+
async function getVercelOidcToken() {
|
|
34
|
+
return (0, import_get_vercel_oidc_token_sync.getVercelOidcTokenSync)();
|
|
35
|
+
}
|
|
36
|
+
async function getVercelToken() {
|
|
37
|
+
throw new Error("getVercelToken is not supported in Edge Runtime");
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
AccessTokenMissingError,
|
|
42
|
+
RefreshAccessTokenFailedError,
|
|
43
|
+
getContext,
|
|
44
|
+
getVercelOidcToken,
|
|
45
|
+
getVercelOidcTokenSync,
|
|
46
|
+
getVercelToken
|
|
47
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { getVercelOidcToken
|
|
1
|
+
export { getVercelOidcToken } from './get-vercel-oidc-token-with-refresh';
|
|
2
|
+
export { getVercelOidcTokenSync } from './get-vercel-oidc-token-sync';
|
|
2
3
|
export { getContext } from './get-context';
|
|
3
4
|
export { AccessTokenMissingError, RefreshAccessTokenFailedError, } from './auth-errors';
|
|
4
5
|
export { getVercelToken } from './token-util';
|
package/dist/index.js
CHANGED
|
@@ -21,12 +21,13 @@ __export(src_exports, {
|
|
|
21
21
|
AccessTokenMissingError: () => import_auth_errors.AccessTokenMissingError,
|
|
22
22
|
RefreshAccessTokenFailedError: () => import_auth_errors.RefreshAccessTokenFailedError,
|
|
23
23
|
getContext: () => import_get_context.getContext,
|
|
24
|
-
getVercelOidcToken: () =>
|
|
25
|
-
getVercelOidcTokenSync: () =>
|
|
24
|
+
getVercelOidcToken: () => import_get_vercel_oidc_token_with_refresh.getVercelOidcToken,
|
|
25
|
+
getVercelOidcTokenSync: () => import_get_vercel_oidc_token_sync.getVercelOidcTokenSync,
|
|
26
26
|
getVercelToken: () => import_token_util.getVercelToken
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(src_exports);
|
|
29
|
-
var
|
|
29
|
+
var import_get_vercel_oidc_token_with_refresh = require("./get-vercel-oidc-token-with-refresh");
|
|
30
|
+
var import_get_vercel_oidc_token_sync = require("./get-vercel-oidc-token-sync");
|
|
30
31
|
var import_get_context = require("./get-context");
|
|
31
32
|
var import_auth_errors = require("./auth-errors");
|
|
32
33
|
var import_token_util = require("./token-util");
|
package/docs/README.md
CHANGED
|
@@ -1,149 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
**@vercel/oidc**
|
|
2
|
+
|
|
3
|
+
---
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
# @vercel/oidc
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
## Classes
|
|
6
8
|
|
|
7
9
|
- [AccessTokenMissingError](classes/AccessTokenMissingError.md)
|
|
8
10
|
- [RefreshAccessTokenFailedError](classes/RefreshAccessTokenFailedError.md)
|
|
9
11
|
|
|
10
|
-
### Functions
|
|
11
|
-
|
|
12
|
-
- [getContext](README.md#getcontext)
|
|
13
|
-
- [getVercelOidcToken](README.md#getverceloidctoken)
|
|
14
|
-
- [getVercelOidcTokenSync](README.md#getverceloidctokensync)
|
|
15
|
-
- [getVercelToken](README.md#getverceltoken)
|
|
16
|
-
|
|
17
12
|
## Functions
|
|
18
13
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
#### Returns
|
|
24
|
-
|
|
25
|
-
`Context`
|
|
26
|
-
|
|
27
|
-
#### Defined in
|
|
28
|
-
|
|
29
|
-
[packages/oidc/src/get-context.ts:7](https://github.com/vercel/vercel/blob/main/packages/oidc/src/get-context.ts#L7)
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
### getVercelOidcToken
|
|
34
|
-
|
|
35
|
-
▸ **getVercelOidcToken**(`options?`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
36
|
-
|
|
37
|
-
Gets the current OIDC token from the request context or the environment variable.
|
|
38
|
-
|
|
39
|
-
Do not cache this value, as it is subject to change in production!
|
|
40
|
-
|
|
41
|
-
This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
42
|
-
It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
43
|
-
|
|
44
|
-
Unlike the `getVercelOidcTokenSync` function, this function will refresh the token if it is expired in a development environment.
|
|
45
|
-
|
|
46
|
-
**`Throws`**
|
|
47
|
-
|
|
48
|
-
If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set. If the token
|
|
49
|
-
is expired in a development environment, will also throw an error if the token cannot be refreshed: no CLI credentials are available, CLI credentials are expired, no project configuration is available
|
|
50
|
-
or the token refresh request fails.
|
|
51
|
-
|
|
52
|
-
**`Example`**
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
// Using the OIDC token
|
|
56
|
-
getVercelOidcToken()
|
|
57
|
-
.then(token => {
|
|
58
|
-
console.log('OIDC Token:', token);
|
|
59
|
-
})
|
|
60
|
-
.catch(error => {
|
|
61
|
-
console.error('Error:', error.message);
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
**`Example`**
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
// Using the OIDC token with explicit team and project (supports IDs and slugs)
|
|
69
|
-
getVercelOidcToken({ team: 'my-team', project: 'my-project' })
|
|
70
|
-
.then(token => {
|
|
71
|
-
console.log('OIDC Token:', token);
|
|
72
|
-
})
|
|
73
|
-
.catch(error => {
|
|
74
|
-
console.error('Error:', error.message);
|
|
75
|
-
});
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
#### Parameters
|
|
79
|
-
|
|
80
|
-
| Name | Type | Description |
|
|
81
|
-
| :--------- | :-------------------------- | :------------------------------------------ |
|
|
82
|
-
| `options?` | `GetVercelOidcTokenOptions` | Optional configuration for token retrieval. |
|
|
83
|
-
|
|
84
|
-
#### Returns
|
|
85
|
-
|
|
86
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
87
|
-
|
|
88
|
-
A promise that resolves to the OIDC token.
|
|
89
|
-
|
|
90
|
-
#### Defined in
|
|
91
|
-
|
|
92
|
-
[packages/oidc/src/get-vercel-oidc-token.ts:64](https://github.com/vercel/vercel/blob/main/packages/oidc/src/get-vercel-oidc-token.ts#L64)
|
|
93
|
-
|
|
94
|
-
---
|
|
95
|
-
|
|
96
|
-
### getVercelOidcTokenSync
|
|
97
|
-
|
|
98
|
-
▸ **getVercelOidcTokenSync**(): `string`
|
|
99
|
-
|
|
100
|
-
Gets the current OIDC token from the request context or the environment variable.
|
|
101
|
-
|
|
102
|
-
Do not cache this value, as it is subject to change in production!
|
|
103
|
-
|
|
104
|
-
This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
105
|
-
It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
106
|
-
|
|
107
|
-
This function will not refresh the token if it is expired. For refreshing the token, use the @{link getVercelOidcToken} function.
|
|
108
|
-
|
|
109
|
-
**`Throws`**
|
|
110
|
-
|
|
111
|
-
If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
|
|
112
|
-
|
|
113
|
-
**`Example`**
|
|
114
|
-
|
|
115
|
-
```js
|
|
116
|
-
// Using the OIDC token
|
|
117
|
-
const token = getVercelOidcTokenSync();
|
|
118
|
-
console.log('OIDC Token:', token);
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
#### Returns
|
|
122
|
-
|
|
123
|
-
`string`
|
|
124
|
-
|
|
125
|
-
The OIDC token.
|
|
126
|
-
|
|
127
|
-
#### Defined in
|
|
128
|
-
|
|
129
|
-
[packages/oidc/src/get-vercel-oidc-token.ts:124](https://github.com/vercel/vercel/blob/main/packages/oidc/src/get-vercel-oidc-token.ts#L124)
|
|
130
|
-
|
|
131
|
-
---
|
|
132
|
-
|
|
133
|
-
### getVercelToken
|
|
134
|
-
|
|
135
|
-
▸ **getVercelToken**(`options?`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
136
|
-
|
|
137
|
-
#### Parameters
|
|
138
|
-
|
|
139
|
-
| Name | Type |
|
|
140
|
-
| :--------- | :---------------------- |
|
|
141
|
-
| `options?` | `GetVercelTokenOptions` |
|
|
142
|
-
|
|
143
|
-
#### Returns
|
|
144
|
-
|
|
145
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
146
|
-
|
|
147
|
-
#### Defined in
|
|
148
|
-
|
|
149
|
-
[packages/oidc/src/token-util.ts:35](https://github.com/vercel/vercel/blob/main/packages/oidc/src/token-util.ts#L35)
|
|
14
|
+
- [getContext](functions/getContext.md)
|
|
15
|
+
- [getVercelOidcToken](functions/getVercelOidcToken.md)
|
|
16
|
+
- [getVercelOidcTokenSync](functions/getVercelOidcTokenSync.md)
|
|
17
|
+
- [getVercelToken](functions/getVercelToken.md)
|
|
@@ -1,151 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Error thrown when no authentication configuration is found.
|
|
4
|
-
This typically means the user needs to log in.
|
|
5
|
-
|
|
6
|
-
## Hierarchy
|
|
1
|
+
[**@vercel/oidc**](../README.md)
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
---
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
# Class: AccessTokenMissingError
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
Defined in: [packages/oidc/src/auth-errors.ts:5](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L5)
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
Error thrown when no authentication configuration is found.
|
|
10
|
+
This typically means the user needs to log in.
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
## Extends
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
- [`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
- [name](AccessTokenMissingError.md#name)
|
|
22
|
-
- [stack](AccessTokenMissingError.md#stack)
|
|
23
|
-
- [prepareStackTrace](AccessTokenMissingError.md#preparestacktrace)
|
|
24
|
-
- [stackTraceLimit](AccessTokenMissingError.md#stacktracelimit)
|
|
16
|
+
## Constructors
|
|
25
17
|
|
|
26
|
-
###
|
|
18
|
+
### Constructor
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
> **new AccessTokenMissingError**(): `AccessTokenMissingError`
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
Defined in: [packages/oidc/src/auth-errors.ts:7](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L7)
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
#### Returns
|
|
33
25
|
|
|
34
|
-
|
|
26
|
+
`AccessTokenMissingError`
|
|
35
27
|
|
|
36
28
|
#### Overrides
|
|
37
29
|
|
|
38
|
-
Error.constructor
|
|
39
|
-
|
|
40
|
-
#### Defined in
|
|
41
|
-
|
|
42
|
-
[packages/oidc/src/auth-errors.ts:7](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L7)
|
|
30
|
+
`Error.constructor`
|
|
43
31
|
|
|
44
32
|
## Properties
|
|
45
33
|
|
|
46
34
|
### message
|
|
47
35
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
#### Inherited from
|
|
36
|
+
> **message**: `string`
|
|
51
37
|
|
|
52
|
-
|
|
38
|
+
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
53
39
|
|
|
54
|
-
####
|
|
40
|
+
#### Inherited from
|
|
55
41
|
|
|
56
|
-
|
|
42
|
+
`Error.message`
|
|
57
43
|
|
|
58
44
|
---
|
|
59
45
|
|
|
60
46
|
### name
|
|
61
47
|
|
|
62
|
-
|
|
48
|
+
> **name**: `string` = `'AccessTokenMissingError'`
|
|
63
49
|
|
|
64
|
-
|
|
50
|
+
Defined in: [packages/oidc/src/auth-errors.ts:6](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L6)
|
|
65
51
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
#### Defined in
|
|
52
|
+
#### Overrides
|
|
69
53
|
|
|
70
|
-
|
|
54
|
+
`Error.name`
|
|
71
55
|
|
|
72
56
|
---
|
|
73
57
|
|
|
74
|
-
### stack
|
|
58
|
+
### stack?
|
|
75
59
|
|
|
76
|
-
|
|
60
|
+
> `optional` **stack?**: `string`
|
|
77
61
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
Error.stack
|
|
62
|
+
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
81
63
|
|
|
82
|
-
####
|
|
64
|
+
#### Inherited from
|
|
83
65
|
|
|
84
|
-
|
|
66
|
+
`Error.stack`
|
|
85
67
|
|
|
86
68
|
---
|
|
87
69
|
|
|
88
|
-
### prepareStackTrace
|
|
70
|
+
### prepareStackTrace?
|
|
89
71
|
|
|
90
|
-
|
|
72
|
+
> `static` `optional` **prepareStackTrace?**: (`err`, `stackTraces`) => `any`
|
|
91
73
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
▸ (`err`, `stackTraces`): `any`
|
|
74
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:28
|
|
95
75
|
|
|
96
76
|
Optional override for formatting stack traces
|
|
97
77
|
|
|
98
|
-
|
|
78
|
+
#### Parameters
|
|
79
|
+
|
|
80
|
+
##### err
|
|
99
81
|
|
|
100
|
-
https://
|
|
82
|
+
[`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
|
101
83
|
|
|
102
|
-
#####
|
|
84
|
+
##### stackTraces
|
|
103
85
|
|
|
104
|
-
|
|
105
|
-
| :------------ | :------------------------------------------------------------------------------------------------ |
|
|
106
|
-
| `err` | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
107
|
-
| `stackTraces` | `CallSite`[] |
|
|
86
|
+
`CallSite`[]
|
|
108
87
|
|
|
109
|
-
|
|
88
|
+
#### Returns
|
|
110
89
|
|
|
111
90
|
`any`
|
|
112
91
|
|
|
113
|
-
####
|
|
92
|
+
#### See
|
|
114
93
|
|
|
115
|
-
|
|
94
|
+
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
116
95
|
|
|
117
|
-
####
|
|
96
|
+
#### Inherited from
|
|
118
97
|
|
|
119
|
-
|
|
98
|
+
`Error.prepareStackTrace`
|
|
120
99
|
|
|
121
100
|
---
|
|
122
101
|
|
|
123
102
|
### stackTraceLimit
|
|
124
103
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
#### Inherited from
|
|
104
|
+
> `static` **stackTraceLimit**: `number`
|
|
128
105
|
|
|
129
|
-
|
|
106
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:30
|
|
130
107
|
|
|
131
|
-
####
|
|
108
|
+
#### Inherited from
|
|
132
109
|
|
|
133
|
-
|
|
110
|
+
`Error.stackTraceLimit`
|
|
134
111
|
|
|
135
112
|
## Methods
|
|
136
113
|
|
|
137
|
-
### captureStackTrace
|
|
114
|
+
### captureStackTrace()
|
|
115
|
+
|
|
116
|
+
> `static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void`
|
|
138
117
|
|
|
139
|
-
|
|
118
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:21
|
|
140
119
|
|
|
141
120
|
Create .stack property on a target object
|
|
142
121
|
|
|
143
122
|
#### Parameters
|
|
144
123
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
124
|
+
##### targetObject
|
|
125
|
+
|
|
126
|
+
`object`
|
|
127
|
+
|
|
128
|
+
##### constructorOpt?
|
|
129
|
+
|
|
130
|
+
[`Function`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function)
|
|
149
131
|
|
|
150
132
|
#### Returns
|
|
151
133
|
|
|
@@ -153,8 +135,4 @@ Create .stack property on a target object
|
|
|
153
135
|
|
|
154
136
|
#### Inherited from
|
|
155
137
|
|
|
156
|
-
Error.captureStackTrace
|
|
157
|
-
|
|
158
|
-
#### Defined in
|
|
159
|
-
|
|
160
|
-
node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:21
|
|
138
|
+
`Error.captureStackTrace`
|
|
@@ -1,157 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Error thrown when attempting to refresh the authentication token fails.
|
|
4
|
-
This includes cases where no refresh token is available.
|
|
1
|
+
[**@vercel/oidc**](../README.md)
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
---
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
# Class: RefreshAccessTokenFailedError
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
Defined in: [packages/oidc/src/auth-errors.ts:18](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L18)
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
Error thrown when attempting to refresh the authentication token fails.
|
|
10
|
+
This includes cases where no refresh token is available.
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
## Extends
|
|
15
13
|
|
|
16
|
-
- [
|
|
14
|
+
- [`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
## Constructors
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
- [name](RefreshAccessTokenFailedError.md#name)
|
|
22
|
-
- [stack](RefreshAccessTokenFailedError.md#stack)
|
|
23
|
-
- [prepareStackTrace](RefreshAccessTokenFailedError.md#preparestacktrace)
|
|
24
|
-
- [stackTraceLimit](RefreshAccessTokenFailedError.md#stacktracelimit)
|
|
18
|
+
### Constructor
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
> **new RefreshAccessTokenFailedError**(`cause?`): `RefreshAccessTokenFailedError`
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
Defined in: [packages/oidc/src/auth-errors.ts:20](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L20)
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
#### Parameters
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
##### cause?
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
`unknown`
|
|
35
29
|
|
|
36
|
-
####
|
|
30
|
+
#### Returns
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
| :------- | :-------- |
|
|
40
|
-
| `cause?` | `unknown` |
|
|
32
|
+
`RefreshAccessTokenFailedError`
|
|
41
33
|
|
|
42
34
|
#### Overrides
|
|
43
35
|
|
|
44
|
-
Error.constructor
|
|
45
|
-
|
|
46
|
-
#### Defined in
|
|
47
|
-
|
|
48
|
-
[packages/oidc/src/auth-errors.ts:20](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L20)
|
|
36
|
+
`Error.constructor`
|
|
49
37
|
|
|
50
38
|
## Properties
|
|
51
39
|
|
|
52
40
|
### message
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
#### Inherited from
|
|
42
|
+
> **message**: `string`
|
|
57
43
|
|
|
58
|
-
|
|
44
|
+
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
59
45
|
|
|
60
|
-
####
|
|
46
|
+
#### Inherited from
|
|
61
47
|
|
|
62
|
-
|
|
48
|
+
`Error.message`
|
|
63
49
|
|
|
64
50
|
---
|
|
65
51
|
|
|
66
52
|
### name
|
|
67
53
|
|
|
68
|
-
|
|
54
|
+
> **name**: `string` = `'RefreshAccessTokenFailedError'`
|
|
69
55
|
|
|
70
|
-
|
|
56
|
+
Defined in: [packages/oidc/src/auth-errors.ts:19](https://github.com/vercel/vercel/blob/main/packages/oidc/src/auth-errors.ts#L19)
|
|
71
57
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
#### Defined in
|
|
58
|
+
#### Overrides
|
|
75
59
|
|
|
76
|
-
|
|
60
|
+
`Error.name`
|
|
77
61
|
|
|
78
62
|
---
|
|
79
63
|
|
|
80
|
-
### stack
|
|
64
|
+
### stack?
|
|
81
65
|
|
|
82
|
-
|
|
66
|
+
> `optional` **stack?**: `string`
|
|
83
67
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
Error.stack
|
|
68
|
+
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
87
69
|
|
|
88
|
-
####
|
|
70
|
+
#### Inherited from
|
|
89
71
|
|
|
90
|
-
|
|
72
|
+
`Error.stack`
|
|
91
73
|
|
|
92
74
|
---
|
|
93
75
|
|
|
94
|
-
### prepareStackTrace
|
|
76
|
+
### prepareStackTrace?
|
|
95
77
|
|
|
96
|
-
|
|
78
|
+
> `static` `optional` **prepareStackTrace?**: (`err`, `stackTraces`) => `any`
|
|
97
79
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
▸ (`err`, `stackTraces`): `any`
|
|
80
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:28
|
|
101
81
|
|
|
102
82
|
Optional override for formatting stack traces
|
|
103
83
|
|
|
104
|
-
|
|
84
|
+
#### Parameters
|
|
85
|
+
|
|
86
|
+
##### err
|
|
105
87
|
|
|
106
|
-
https://
|
|
88
|
+
[`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)
|
|
107
89
|
|
|
108
|
-
#####
|
|
90
|
+
##### stackTraces
|
|
109
91
|
|
|
110
|
-
|
|
111
|
-
| :------------ | :------------------------------------------------------------------------------------------------ |
|
|
112
|
-
| `err` | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
113
|
-
| `stackTraces` | `CallSite`[] |
|
|
92
|
+
`CallSite`[]
|
|
114
93
|
|
|
115
|
-
|
|
94
|
+
#### Returns
|
|
116
95
|
|
|
117
96
|
`any`
|
|
118
97
|
|
|
119
|
-
####
|
|
98
|
+
#### See
|
|
120
99
|
|
|
121
|
-
|
|
100
|
+
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
122
101
|
|
|
123
|
-
####
|
|
102
|
+
#### Inherited from
|
|
124
103
|
|
|
125
|
-
|
|
104
|
+
`Error.prepareStackTrace`
|
|
126
105
|
|
|
127
106
|
---
|
|
128
107
|
|
|
129
108
|
### stackTraceLimit
|
|
130
109
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
#### Inherited from
|
|
110
|
+
> `static` **stackTraceLimit**: `number`
|
|
134
111
|
|
|
135
|
-
|
|
112
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:30
|
|
136
113
|
|
|
137
|
-
####
|
|
114
|
+
#### Inherited from
|
|
138
115
|
|
|
139
|
-
|
|
116
|
+
`Error.stackTraceLimit`
|
|
140
117
|
|
|
141
118
|
## Methods
|
|
142
119
|
|
|
143
|
-
### captureStackTrace
|
|
120
|
+
### captureStackTrace()
|
|
121
|
+
|
|
122
|
+
> `static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void`
|
|
144
123
|
|
|
145
|
-
|
|
124
|
+
Defined in: node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:21
|
|
146
125
|
|
|
147
126
|
Create .stack property on a target object
|
|
148
127
|
|
|
149
128
|
#### Parameters
|
|
150
129
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
130
|
+
##### targetObject
|
|
131
|
+
|
|
132
|
+
`object`
|
|
133
|
+
|
|
134
|
+
##### constructorOpt?
|
|
135
|
+
|
|
136
|
+
[`Function`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function)
|
|
155
137
|
|
|
156
138
|
#### Returns
|
|
157
139
|
|
|
@@ -159,8 +141,4 @@ Create .stack property on a target object
|
|
|
159
141
|
|
|
160
142
|
#### Inherited from
|
|
161
143
|
|
|
162
|
-
Error.captureStackTrace
|
|
163
|
-
|
|
164
|
-
#### Defined in
|
|
165
|
-
|
|
166
|
-
node_modules/.pnpm/@types+node@20.11.0/node_modules/@types/node/globals.d.ts:21
|
|
144
|
+
`Error.captureStackTrace`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[**@vercel/oidc**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Function: getContext()
|
|
6
|
+
|
|
7
|
+
> **getContext**(): `Context`
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/oidc/src/get-context.ts:7](https://github.com/vercel/vercel/blob/main/packages/oidc/src/get-context.ts#L7)
|
|
10
|
+
|
|
11
|
+
## Returns
|
|
12
|
+
|
|
13
|
+
`Context`
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[**@vercel/oidc**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Function: getVercelOidcToken()
|
|
6
|
+
|
|
7
|
+
> **getVercelOidcToken**(`options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/oidc/src/get-vercel-oidc-token-with-refresh.ts:64](https://github.com/vercel/vercel/blob/main/packages/oidc/src/get-vercel-oidc-token-with-refresh.ts#L64)
|
|
10
|
+
|
|
11
|
+
Gets the current OIDC token from the request context or the environment variable.
|
|
12
|
+
|
|
13
|
+
Do not cache this value, as it is subject to change in production!
|
|
14
|
+
|
|
15
|
+
This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
16
|
+
It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
17
|
+
|
|
18
|
+
Unlike the `getVercelOidcTokenSync` function, this function will refresh the token if it is expired in a development environment.
|
|
19
|
+
|
|
20
|
+
## Parameters
|
|
21
|
+
|
|
22
|
+
### options?
|
|
23
|
+
|
|
24
|
+
`GetVercelOidcTokenOptions`
|
|
25
|
+
|
|
26
|
+
Optional configuration for token retrieval.
|
|
27
|
+
|
|
28
|
+
## Returns
|
|
29
|
+
|
|
30
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
|
|
31
|
+
|
|
32
|
+
A promise that resolves to the OIDC token.
|
|
33
|
+
|
|
34
|
+
## Throws
|
|
35
|
+
|
|
36
|
+
If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set. If the token
|
|
37
|
+
is expired in a development environment, will also throw an error if the token cannot be refreshed: no CLI credentials are available, CLI credentials are expired, no project configuration is available
|
|
38
|
+
or the token refresh request fails.
|
|
39
|
+
|
|
40
|
+
## Examples
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// Using the OIDC token
|
|
44
|
+
getVercelOidcToken()
|
|
45
|
+
.then(token => {
|
|
46
|
+
console.log('OIDC Token:', token);
|
|
47
|
+
})
|
|
48
|
+
.catch(error => {
|
|
49
|
+
console.error('Error:', error.message);
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
// Using the OIDC token with explicit team and project (supports IDs and slugs)
|
|
55
|
+
getVercelOidcToken({ team: 'my-team', project: 'my-project' })
|
|
56
|
+
.then(token => {
|
|
57
|
+
console.log('OIDC Token:', token);
|
|
58
|
+
})
|
|
59
|
+
.catch(error => {
|
|
60
|
+
console.error('Error:', error.message);
|
|
61
|
+
});
|
|
62
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[**@vercel/oidc**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Function: getVercelOidcTokenSync()
|
|
6
|
+
|
|
7
|
+
> **getVercelOidcTokenSync**(): `string`
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/oidc/src/get-vercel-oidc-token-sync.ts:24](https://github.com/vercel/vercel/blob/main/packages/oidc/src/get-vercel-oidc-token-sync.ts#L24)
|
|
10
|
+
|
|
11
|
+
Gets the current OIDC token from the request context or the environment variable.
|
|
12
|
+
|
|
13
|
+
Do not cache this value, as it is subject to change in production!
|
|
14
|
+
|
|
15
|
+
This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
16
|
+
It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
17
|
+
|
|
18
|
+
This function will not refresh the token if it is expired. For refreshing the token, use the @{link getVercelOidcToken} function.
|
|
19
|
+
|
|
20
|
+
## Returns
|
|
21
|
+
|
|
22
|
+
`string`
|
|
23
|
+
|
|
24
|
+
The OIDC token.
|
|
25
|
+
|
|
26
|
+
## Throws
|
|
27
|
+
|
|
28
|
+
If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
|
|
29
|
+
|
|
30
|
+
## Example
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// Using the OIDC token
|
|
34
|
+
const token = getVercelOidcTokenSync();
|
|
35
|
+
console.log('OIDC Token:', token);
|
|
36
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[**@vercel/oidc**](../README.md)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Function: getVercelToken()
|
|
6
|
+
|
|
7
|
+
> **getVercelToken**(`options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/oidc/src/token-util.ts:35](https://github.com/vercel/vercel/blob/main/packages/oidc/src/token-util.ts#L35)
|
|
10
|
+
|
|
11
|
+
## Parameters
|
|
12
|
+
|
|
13
|
+
### options?
|
|
14
|
+
|
|
15
|
+
`GetVercelTokenOptions`
|
|
16
|
+
|
|
17
|
+
## Returns
|
|
18
|
+
|
|
19
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"edge-light": "./dist/index-edge-light.js",
|
|
13
14
|
"browser": "./dist/index-browser.js",
|
|
14
15
|
"react-native": "./dist/index-browser.js",
|
|
15
16
|
"workflow": "./dist/index-browser.js",
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
"require": "./dist/index.js"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
|
-
"version": "3.
|
|
21
|
+
"version": "3.5.0",
|
|
21
22
|
"repository": {
|
|
22
23
|
"directory": "packages/oidc",
|
|
23
24
|
"type": "git",
|
|
@@ -29,9 +30,9 @@
|
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"prettier": "3.8.3",
|
|
31
32
|
"tinyspawn": "1.3.1",
|
|
32
|
-
"typedoc": "0.
|
|
33
|
-
"typedoc-plugin-markdown": "
|
|
34
|
-
"typedoc-plugin-mdn-links": "
|
|
33
|
+
"typedoc": "0.28.19",
|
|
34
|
+
"typedoc-plugin-markdown": "4.11.0",
|
|
35
|
+
"typedoc-plugin-mdn-links": "5.1.1",
|
|
35
36
|
"vitest": "2.0.1"
|
|
36
37
|
},
|
|
37
38
|
"peerDependenciesMeta": {},
|
/package/dist/{get-vercel-oidc-token.test.d.ts → get-vercel-oidc-token-with-refresh.test.d.ts}
RENAMED
|
File without changes
|