@aura-stack/auth 0.1.0-rc.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.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/@types/index.cjs +18 -0
- package/dist/@types/index.d.cts +9 -0
- package/dist/@types/index.d.ts +9 -0
- package/dist/@types/index.js +1 -0
- package/dist/@types/router.d.cjs +1 -0
- package/dist/@types/router.d.d.cts +16 -0
- package/dist/@types/router.d.d.ts +16 -0
- package/dist/@types/router.d.js +0 -0
- package/dist/@types/utility.cjs +18 -0
- package/dist/@types/utility.d.cts +6 -0
- package/dist/@types/utility.d.ts +6 -0
- package/dist/@types/utility.js +1 -0
- package/dist/actions/callback/access-token.cjs +170 -0
- package/dist/actions/callback/access-token.d.cts +30 -0
- package/dist/actions/callback/access-token.d.ts +30 -0
- package/dist/actions/callback/access-token.js +8 -0
- package/dist/actions/callback/callback.cjs +517 -0
- package/dist/actions/callback/callback.d.cts +13 -0
- package/dist/actions/callback/callback.d.ts +13 -0
- package/dist/actions/callback/callback.js +16 -0
- package/dist/actions/callback/userinfo.cjs +165 -0
- package/dist/actions/callback/userinfo.d.cts +22 -0
- package/dist/actions/callback/userinfo.d.ts +22 -0
- package/dist/actions/callback/userinfo.js +10 -0
- package/dist/actions/csrfToken/csrfToken.cjs +207 -0
- package/dist/actions/csrfToken/csrfToken.d.cts +5 -0
- package/dist/actions/csrfToken/csrfToken.d.ts +5 -0
- package/dist/actions/csrfToken/csrfToken.js +12 -0
- package/dist/actions/index.cjs +864 -0
- package/dist/actions/index.d.cts +14 -0
- package/dist/actions/index.d.ts +14 -0
- package/dist/actions/index.js +34 -0
- package/dist/actions/session/session.cjs +191 -0
- package/dist/actions/session/session.d.cts +5 -0
- package/dist/actions/session/session.d.ts +5 -0
- package/dist/actions/session/session.js +11 -0
- package/dist/actions/signIn/authorization.cjs +274 -0
- package/dist/actions/signIn/authorization.d.cts +45 -0
- package/dist/actions/signIn/authorization.d.ts +45 -0
- package/dist/actions/signIn/authorization.js +16 -0
- package/dist/actions/signIn/signIn.cjs +469 -0
- package/dist/actions/signIn/signIn.d.cts +13 -0
- package/dist/actions/signIn/signIn.d.ts +13 -0
- package/dist/actions/signIn/signIn.js +14 -0
- package/dist/actions/signOut/signOut.cjs +490 -0
- package/dist/actions/signOut/signOut.d.cts +8 -0
- package/dist/actions/signOut/signOut.d.ts +8 -0
- package/dist/actions/signOut/signOut.js +15 -0
- package/dist/assert.cjs +44 -0
- package/dist/assert.d.ts +5 -0
- package/dist/assert.js +10 -0
- package/dist/chunk-256KIVJL.js +99 -0
- package/dist/chunk-42XB3YCW.js +22 -0
- package/dist/chunk-6SM22VVJ.js +18 -0
- package/dist/chunk-CAKJT3KS.js +92 -0
- package/dist/chunk-E3OXBRYF.js +22 -0
- package/dist/chunk-EBPE35JT.js +31 -0
- package/dist/chunk-FIPU4MLT.js +21 -0
- package/dist/chunk-FJUDBLCP.js +59 -0
- package/dist/chunk-FKRDCWBF.js +22 -0
- package/dist/chunk-GZU3RBTB.js +62 -0
- package/dist/chunk-HGJ4TXY4.js +137 -0
- package/dist/chunk-HMRKN75I.js +74 -0
- package/dist/chunk-IKHPGFCW.js +14 -0
- package/dist/chunk-ITQ7352M.js +0 -0
- package/dist/chunk-JAPMIE6S.js +10 -0
- package/dist/chunk-KRNOMBXQ.js +22 -0
- package/dist/chunk-LLR722CL.js +96 -0
- package/dist/chunk-PG7UYFG5.js +0 -0
- package/dist/chunk-RLT4RFKV.js +45 -0
- package/dist/chunk-SJPDVKUS.js +112 -0
- package/dist/chunk-SMQO5WD7.js +30 -0
- package/dist/chunk-STHEPPUZ.js +11 -0
- package/dist/chunk-UJJ7R56J.js +52 -0
- package/dist/chunk-VFTYH33W.js +61 -0
- package/dist/chunk-X7M4CQTN.js +25 -0
- package/dist/chunk-XXJKNKGQ.js +37 -0
- package/dist/chunk-ZV4BH47P.js +154 -0
- package/dist/cookie.cjs +201 -0
- package/dist/cookie.d.ts +95 -0
- package/dist/cookie.js +36 -0
- package/dist/error.cjs +88 -0
- package/dist/error.d.ts +64 -0
- package/dist/error.js +16 -0
- package/dist/headers.cjs +35 -0
- package/dist/headers.d.ts +9 -0
- package/dist/headers.js +6 -0
- package/dist/index-CGRZ0wrw.d.ts +530 -0
- package/dist/index.cjs +1089 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +75 -0
- package/dist/jose.cjs +68 -0
- package/dist/jose.d.ts +20 -0
- package/dist/jose.js +9 -0
- package/dist/oauth/bitbucket.cjs +45 -0
- package/dist/oauth/bitbucket.d.cts +9 -0
- package/dist/oauth/bitbucket.d.ts +9 -0
- package/dist/oauth/bitbucket.js +6 -0
- package/dist/oauth/discord.cjs +55 -0
- package/dist/oauth/discord.d.cts +9 -0
- package/dist/oauth/discord.d.ts +9 -0
- package/dist/oauth/discord.js +6 -0
- package/dist/oauth/figma.cjs +46 -0
- package/dist/oauth/figma.d.cts +9 -0
- package/dist/oauth/figma.d.ts +9 -0
- package/dist/oauth/figma.js +6 -0
- package/dist/oauth/github.cjs +38 -0
- package/dist/oauth/github.d.cts +9 -0
- package/dist/oauth/github.d.ts +9 -0
- package/dist/oauth/github.js +6 -0
- package/dist/oauth/gitlab.cjs +46 -0
- package/dist/oauth/gitlab.d.cts +9 -0
- package/dist/oauth/gitlab.d.ts +9 -0
- package/dist/oauth/gitlab.js +6 -0
- package/dist/oauth/index.cjs +213 -0
- package/dist/oauth/index.d.cts +9 -0
- package/dist/oauth/index.d.ts +9 -0
- package/dist/oauth/index.js +36 -0
- package/dist/oauth/spotify.cjs +46 -0
- package/dist/oauth/spotify.d.cts +9 -0
- package/dist/oauth/spotify.d.ts +9 -0
- package/dist/oauth/spotify.js +6 -0
- package/dist/oauth/x.cjs +46 -0
- package/dist/oauth/x.d.cts +9 -0
- package/dist/oauth/x.d.ts +9 -0
- package/dist/oauth/x.js +6 -0
- package/dist/response.cjs +34 -0
- package/dist/response.d.ts +10 -0
- package/dist/response.js +6 -0
- package/dist/schemas.cjs +105 -0
- package/dist/schemas.d.ts +130 -0
- package/dist/schemas.js +20 -0
- package/dist/secure.cjs +120 -0
- package/dist/secure.d.ts +43 -0
- package/dist/secure.js +18 -0
- package/dist/utils.cjs +141 -0
- package/dist/utils.d.ts +45 -0
- package/dist/utils.js +23 -0
- package/package.json +70 -0
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
|
|
30
|
+
// src/actions/callback/userinfo.ts
|
|
31
|
+
var userinfo_exports = {};
|
|
32
|
+
__export(userinfo_exports, {
|
|
33
|
+
getUserInfo: () => getUserInfo
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(userinfo_exports);
|
|
36
|
+
|
|
37
|
+
// src/secure.ts
|
|
38
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
39
|
+
|
|
40
|
+
// src/utils.ts
|
|
41
|
+
var import_router = require("@aura-stack/router");
|
|
42
|
+
|
|
43
|
+
// src/error.ts
|
|
44
|
+
var AuthError = class extends Error {
|
|
45
|
+
constructor(type, message) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.type = type;
|
|
48
|
+
this.name = "AuthError";
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var isAuthError = (error) => {
|
|
52
|
+
return error instanceof AuthError;
|
|
53
|
+
};
|
|
54
|
+
var throwAuthError = (error, message) => {
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
if (isAuthError(error)) {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
throw new AuthError("invalid_request", error.message ?? message);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/secure.ts
|
|
64
|
+
var generateSecure = (length = 32) => {
|
|
65
|
+
return import_node_crypto.default.randomBytes(length).toString("base64url");
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/schemas.ts
|
|
69
|
+
var import_v4 = require("zod/v4");
|
|
70
|
+
var OAuthProviderConfigSchema = (0, import_v4.object)({
|
|
71
|
+
authorizeURL: (0, import_v4.url)(),
|
|
72
|
+
accessToken: (0, import_v4.url)(),
|
|
73
|
+
scope: (0, import_v4.string)().optional(),
|
|
74
|
+
userInfo: (0, import_v4.url)(),
|
|
75
|
+
responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
|
|
76
|
+
clientId: (0, import_v4.string)(),
|
|
77
|
+
clientSecret: (0, import_v4.string)()
|
|
78
|
+
});
|
|
79
|
+
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
80
|
+
redirectURI: (0, import_v4.string)(),
|
|
81
|
+
state: (0, import_v4.string)(),
|
|
82
|
+
codeChallenge: (0, import_v4.string)(),
|
|
83
|
+
codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
|
|
84
|
+
});
|
|
85
|
+
var OAuthAuthorizationResponse = (0, import_v4.object)({
|
|
86
|
+
state: (0, import_v4.string)(),
|
|
87
|
+
code: (0, import_v4.string)()
|
|
88
|
+
});
|
|
89
|
+
var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
90
|
+
error: (0, import_v4.enum)([
|
|
91
|
+
"invalid_request",
|
|
92
|
+
"unauthorized_client",
|
|
93
|
+
"access_denied",
|
|
94
|
+
"unsupported_response_type",
|
|
95
|
+
"invalid_scope",
|
|
96
|
+
"server_error",
|
|
97
|
+
"temporarily_unavailable"
|
|
98
|
+
]),
|
|
99
|
+
error_description: (0, import_v4.string)().optional(),
|
|
100
|
+
error_uri: (0, import_v4.string)().optional(),
|
|
101
|
+
state: (0, import_v4.string)()
|
|
102
|
+
});
|
|
103
|
+
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
104
|
+
redirectURI: (0, import_v4.string)(),
|
|
105
|
+
code: (0, import_v4.string)(),
|
|
106
|
+
codeVerifier: (0, import_v4.string)().min(43).max(128)
|
|
107
|
+
});
|
|
108
|
+
var OAuthAccessTokenResponse = (0, import_v4.object)({
|
|
109
|
+
access_token: (0, import_v4.string)(),
|
|
110
|
+
token_type: (0, import_v4.string)(),
|
|
111
|
+
expires_in: (0, import_v4.number)().optional(),
|
|
112
|
+
refresh_token: (0, import_v4.string)().optional(),
|
|
113
|
+
scope: (0, import_v4.string)().optional()
|
|
114
|
+
});
|
|
115
|
+
var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
116
|
+
error: (0, import_v4.enum)([
|
|
117
|
+
"invalid_request",
|
|
118
|
+
"invalid_client",
|
|
119
|
+
"invalid_grant",
|
|
120
|
+
"unauthorized_client",
|
|
121
|
+
"unsupported_grant_type",
|
|
122
|
+
"invalid_scope"
|
|
123
|
+
]),
|
|
124
|
+
error_description: (0, import_v4.string)().optional(),
|
|
125
|
+
error_uri: (0, import_v4.string)().optional()
|
|
126
|
+
});
|
|
127
|
+
var OAuthErrorResponse = (0, import_v4.object)({
|
|
128
|
+
error: (0, import_v4.string)(),
|
|
129
|
+
error_description: (0, import_v4.string)().optional()
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// src/actions/callback/userinfo.ts
|
|
133
|
+
var getDefaultUserInfo = (profile) => {
|
|
134
|
+
const sub = generateSecure(16);
|
|
135
|
+
return {
|
|
136
|
+
sub: profile?.id ?? profile?.sub ?? sub,
|
|
137
|
+
email: profile?.email,
|
|
138
|
+
name: profile?.name ?? profile?.username ?? profile?.nickname,
|
|
139
|
+
image: profile?.image ?? profile?.picture
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
143
|
+
const userinfoEndpoint = oauthConfig.userInfo;
|
|
144
|
+
try {
|
|
145
|
+
const response = await fetch(userinfoEndpoint, {
|
|
146
|
+
method: "GET",
|
|
147
|
+
headers: {
|
|
148
|
+
Accept: "application/json",
|
|
149
|
+
Authorization: `Bearer ${accessToken}`
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const json = await response.json();
|
|
153
|
+
const { success, data } = OAuthErrorResponse.safeParse(json);
|
|
154
|
+
if (success) {
|
|
155
|
+
throw new AuthError(data.error, data?.error_description ?? "An error occurred while fetching user information.");
|
|
156
|
+
}
|
|
157
|
+
return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw throwAuthError(error, "Failed to retrieve userinfo");
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
getUserInfo
|
|
165
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { O as OAuthProviderCredentials, U as User } from '../../index-B1vDUGwh.cjs';
|
|
2
|
+
import 'zod/v4';
|
|
3
|
+
import '../../jose.cjs';
|
|
4
|
+
import '@aura-stack/jose/jose';
|
|
5
|
+
import '../../schemas.cjs';
|
|
6
|
+
import 'zod/v4/core';
|
|
7
|
+
import '@aura-stack/router';
|
|
8
|
+
import 'cookie';
|
|
9
|
+
import '../../@types/utility.cjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get user information from the OAuth provider's userinfo endpoint using the provided access token.
|
|
13
|
+
* The response by default is mapped to the standardized `User` format unless a custom
|
|
14
|
+
* `profile` function is provided in the `oauthConfig`.
|
|
15
|
+
*
|
|
16
|
+
* @param oauthConfig - OAuth provider configuration
|
|
17
|
+
* @param accessToken - Access Token to access the userinfo endpoint
|
|
18
|
+
* @returns The user information retrieved from the userinfo endpoint
|
|
19
|
+
*/
|
|
20
|
+
declare const getUserInfo: (oauthConfig: OAuthProviderCredentials, accessToken: string) => Promise<User>;
|
|
21
|
+
|
|
22
|
+
export { getUserInfo };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { O as OAuthProviderCredentials, U as User } from '../../index-CGRZ0wrw.js';
|
|
2
|
+
import 'zod/v4';
|
|
3
|
+
import '../../jose.js';
|
|
4
|
+
import '@aura-stack/jose/jose';
|
|
5
|
+
import '../../schemas.js';
|
|
6
|
+
import 'zod/v4/core';
|
|
7
|
+
import '@aura-stack/router';
|
|
8
|
+
import 'cookie';
|
|
9
|
+
import '../../@types/utility.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get user information from the OAuth provider's userinfo endpoint using the provided access token.
|
|
13
|
+
* The response by default is mapped to the standardized `User` format unless a custom
|
|
14
|
+
* `profile` function is provided in the `oauthConfig`.
|
|
15
|
+
*
|
|
16
|
+
* @param oauthConfig - OAuth provider configuration
|
|
17
|
+
* @param accessToken - Access Token to access the userinfo endpoint
|
|
18
|
+
* @returns The user information retrieved from the userinfo endpoint
|
|
19
|
+
*/
|
|
20
|
+
declare const getUserInfo: (oauthConfig: OAuthProviderCredentials, accessToken: string) => Promise<User>;
|
|
21
|
+
|
|
22
|
+
export { getUserInfo };
|
|
@@ -0,0 +1,207 @@
|
|
|
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
|
+
|
|
30
|
+
// src/actions/csrfToken/csrfToken.ts
|
|
31
|
+
var csrfToken_exports = {};
|
|
32
|
+
__export(csrfToken_exports, {
|
|
33
|
+
csrfTokenAction: () => csrfTokenAction
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(csrfToken_exports);
|
|
36
|
+
var import_router2 = require("@aura-stack/router");
|
|
37
|
+
|
|
38
|
+
// src/secure.ts
|
|
39
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
40
|
+
|
|
41
|
+
// src/utils.ts
|
|
42
|
+
var import_router = require("@aura-stack/router");
|
|
43
|
+
|
|
44
|
+
// src/error.ts
|
|
45
|
+
var AuthError = class extends Error {
|
|
46
|
+
constructor(type, message) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.type = type;
|
|
49
|
+
this.name = "AuthError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/secure.ts
|
|
54
|
+
var generateSecure = (length = 32) => {
|
|
55
|
+
return import_node_crypto.default.randomBytes(length).toString("base64url");
|
|
56
|
+
};
|
|
57
|
+
var createCSRF = async (jose, csrfCookie) => {
|
|
58
|
+
try {
|
|
59
|
+
const token = generateSecure(32);
|
|
60
|
+
if (csrfCookie) {
|
|
61
|
+
await jose.verifyJWS(csrfCookie);
|
|
62
|
+
return csrfCookie;
|
|
63
|
+
}
|
|
64
|
+
return jose.signJWS({ token });
|
|
65
|
+
} catch {
|
|
66
|
+
const token = generateSecure(32);
|
|
67
|
+
return jose.signJWS({ token });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/headers.ts
|
|
72
|
+
var cacheControl = {
|
|
73
|
+
"Cache-Control": "no-store",
|
|
74
|
+
Pragma: "no-cache",
|
|
75
|
+
Expires: "0",
|
|
76
|
+
Vary: "Cookie"
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/cookie.ts
|
|
80
|
+
var import_cookie = require("cookie");
|
|
81
|
+
|
|
82
|
+
// src/assert.ts
|
|
83
|
+
var isRequest = (value) => {
|
|
84
|
+
return typeof Request !== "undefined" && value instanceof Request;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/cookie.ts
|
|
88
|
+
var import_cookie2 = require("cookie");
|
|
89
|
+
var COOKIE_NAME = "aura-auth";
|
|
90
|
+
var defaultCookieOptions = {
|
|
91
|
+
httpOnly: true,
|
|
92
|
+
sameSite: "lax",
|
|
93
|
+
path: "/",
|
|
94
|
+
maxAge: 60 * 60 * 24 * 15
|
|
95
|
+
};
|
|
96
|
+
var defaultStandardCookieConfig = {
|
|
97
|
+
secure: false,
|
|
98
|
+
httpOnly: true,
|
|
99
|
+
prefix: ""
|
|
100
|
+
};
|
|
101
|
+
var defaultSecureCookieConfig = {
|
|
102
|
+
secure: true,
|
|
103
|
+
prefix: "__Secure-"
|
|
104
|
+
};
|
|
105
|
+
var defaultHostCookieConfig = {
|
|
106
|
+
secure: true,
|
|
107
|
+
prefix: "__Host-",
|
|
108
|
+
path: "/",
|
|
109
|
+
domain: void 0
|
|
110
|
+
};
|
|
111
|
+
var expiredCookieOptions = {
|
|
112
|
+
...defaultCookieOptions,
|
|
113
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
114
|
+
maxAge: 0
|
|
115
|
+
};
|
|
116
|
+
var defineDefaultCookieOptions = (options) => {
|
|
117
|
+
return {
|
|
118
|
+
name: options?.name ?? COOKIE_NAME,
|
|
119
|
+
prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
|
|
120
|
+
...defaultCookieOptions,
|
|
121
|
+
...options
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
var setCookie = (cookieName, value, options) => {
|
|
125
|
+
const { prefix, name } = defineDefaultCookieOptions(options);
|
|
126
|
+
const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
|
|
127
|
+
return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
|
|
128
|
+
...defaultCookieOptions,
|
|
129
|
+
...options
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
var getCookie = (petition, cookie, options, optional = false) => {
|
|
133
|
+
const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ");
|
|
134
|
+
if (!cookies) {
|
|
135
|
+
if (optional) {
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
throw new AuthError("invalid_request", "No cookies found. There is no active session");
|
|
139
|
+
}
|
|
140
|
+
const { name, prefix } = defineDefaultCookieOptions(options);
|
|
141
|
+
const parsedCookies = (0, import_cookie.parse)(cookies);
|
|
142
|
+
const value = parsedCookies[`${prefix}${name}.${cookie}`];
|
|
143
|
+
if (value === void 0) {
|
|
144
|
+
if (optional) {
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`);
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
};
|
|
151
|
+
var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
|
|
152
|
+
const name = cookieOptions.name ?? COOKIE_NAME;
|
|
153
|
+
const isSecure = trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || request.headers.get("Forwarded")?.includes("proto=https") : request.url.startsWith("https://");
|
|
154
|
+
if (!cookieOptions.options?.httpOnly) {
|
|
155
|
+
console.warn(
|
|
156
|
+
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (cookieOptions.options?.domain === "*") {
|
|
160
|
+
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
|
|
161
|
+
}
|
|
162
|
+
if (!isSecure) {
|
|
163
|
+
const options = cookieOptions.options;
|
|
164
|
+
if (options?.secure) {
|
|
165
|
+
console.warn(
|
|
166
|
+
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if (options?.sameSite == "none") {
|
|
170
|
+
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
|
|
171
|
+
}
|
|
172
|
+
if (process.env.NODE_ENV === "production") {
|
|
173
|
+
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
...defaultCookieOptions,
|
|
177
|
+
...cookieOptions.options,
|
|
178
|
+
sameSite: options?.sameSite === "none" ? "lax" : options?.sameSite ?? "lax",
|
|
179
|
+
...defaultStandardCookieConfig,
|
|
180
|
+
name
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return cookieOptions.strategy === "host" ? {
|
|
184
|
+
...defaultCookieOptions,
|
|
185
|
+
...cookieOptions.options,
|
|
186
|
+
...defaultHostCookieConfig,
|
|
187
|
+
name
|
|
188
|
+
} : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/actions/csrfToken/csrfToken.ts
|
|
192
|
+
var csrfTokenAction = (0, import_router2.createEndpoint)("GET", "/csrfToken", async (ctx) => {
|
|
193
|
+
const {
|
|
194
|
+
request,
|
|
195
|
+
context: { cookies, jose, trustedProxyHeaders }
|
|
196
|
+
} = ctx;
|
|
197
|
+
const cookieOptions = secureCookieOptions(request, { ...cookies, strategy: "host" }, trustedProxyHeaders);
|
|
198
|
+
const existingCSRFToken = getCookie(request, "csrfToken", cookieOptions, true);
|
|
199
|
+
const csrfToken = await createCSRF(jose, existingCSRFToken);
|
|
200
|
+
const headers = new Headers(cacheControl);
|
|
201
|
+
headers.set("Set-Cookie", setCookie("csrfToken", csrfToken, cookieOptions));
|
|
202
|
+
return Response.json({ csrfToken }, { headers });
|
|
203
|
+
});
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
csrfTokenAction
|
|
207
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
csrfTokenAction
|
|
3
|
+
} from "../../chunk-SMQO5WD7.js";
|
|
4
|
+
import "../../chunk-ZV4BH47P.js";
|
|
5
|
+
import "../../chunk-6SM22VVJ.js";
|
|
6
|
+
import "../../chunk-STHEPPUZ.js";
|
|
7
|
+
import "../../chunk-GZU3RBTB.js";
|
|
8
|
+
import "../../chunk-256KIVJL.js";
|
|
9
|
+
import "../../chunk-FJUDBLCP.js";
|
|
10
|
+
export {
|
|
11
|
+
csrfTokenAction
|
|
12
|
+
};
|