@aura-stack/auth 0.1.0 → 0.2.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/dist/@types/index.d.ts +5 -5
- package/dist/@types/router.d.d.ts +5 -5
- package/dist/@types/utility.d.ts +1 -5
- package/dist/actions/callback/access-token.cjs +95 -74
- package/dist/actions/callback/access-token.d.ts +7 -7
- package/dist/actions/callback/access-token.js +5 -3
- package/dist/actions/callback/callback.cjs +171 -249
- package/dist/actions/callback/callback.d.ts +6 -6
- package/dist/actions/callback/callback.js +10 -10
- package/dist/actions/callback/userinfo.cjs +81 -57
- package/dist/actions/callback/userinfo.d.ts +5 -5
- package/dist/actions/callback/userinfo.js +7 -5
- package/dist/actions/csrfToken/csrfToken.cjs +36 -105
- package/dist/actions/csrfToken/csrfToken.js +6 -6
- package/dist/actions/index.cjs +309 -444
- package/dist/actions/index.d.ts +5 -5
- package/dist/actions/index.js +19 -19
- package/dist/actions/session/session.cjs +25 -109
- package/dist/actions/session/session.js +4 -5
- package/dist/actions/signIn/authorization.cjs +96 -87
- package/dist/actions/signIn/authorization.d.ts +5 -5
- package/dist/actions/signIn/authorization.js +5 -5
- package/dist/actions/signIn/signIn.cjs +133 -242
- package/dist/actions/signIn/signIn.d.ts +6 -6
- package/dist/actions/signIn/signIn.js +8 -9
- package/dist/actions/signOut/signOut.cjs +136 -282
- package/dist/actions/signOut/signOut.js +8 -9
- package/dist/assert.cjs +5 -0
- package/dist/assert.d.ts +10 -1
- package/dist/assert.js +3 -1
- package/dist/chunk-3EUWD5BB.js +63 -0
- package/dist/chunk-6R2YZ4AC.js +22 -0
- package/dist/chunk-A3N4PVAT.js +70 -0
- package/dist/chunk-B737EUJV.js +22 -0
- package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
- package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
- package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
- package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
- package/dist/chunk-HP34YGGJ.js +22 -0
- package/dist/chunk-HT4YLL7N.js +35 -0
- package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
- package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
- package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
- package/dist/chunk-KSWLO5ZU.js +102 -0
- package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
- package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
- package/dist/chunk-RRLIF4PQ.js +55 -0
- package/dist/chunk-TLE4PXY3.js +39 -0
- package/dist/chunk-W6LG7BFW.js +197 -0
- package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
- package/dist/chunk-ZNCZVF6U.js +14 -0
- package/dist/cookie.cjs +140 -99
- package/dist/cookie.d.ts +35 -44
- package/dist/cookie.js +10 -17
- package/dist/errors.cjs +85 -0
- package/dist/errors.d.ts +49 -0
- package/dist/errors.js +18 -0
- package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
- package/dist/index.cjs +543 -443
- package/dist/index.d.ts +6 -6
- package/dist/index.js +42 -28
- package/dist/jose.cjs +25 -14
- package/dist/jose.d.ts +4 -1
- package/dist/jose.js +5 -4
- package/dist/oauth/bitbucket.d.ts +5 -5
- package/dist/oauth/discord.cjs +0 -1
- package/dist/oauth/discord.d.ts +5 -5
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/figma.d.ts +5 -5
- package/dist/oauth/github.d.ts +5 -5
- package/dist/oauth/gitlab.d.ts +5 -5
- package/dist/oauth/index.cjs +176 -6
- package/dist/oauth/index.d.ts +5 -5
- package/dist/oauth/index.js +19 -4
- package/dist/oauth/mailchimp.cjs +46 -0
- package/dist/oauth/mailchimp.d.ts +7 -0
- package/dist/oauth/mailchimp.js +6 -0
- package/dist/oauth/pinterest.cjs +46 -0
- package/dist/oauth/pinterest.d.ts +7 -0
- package/dist/oauth/pinterest.js +6 -0
- package/dist/oauth/spotify.d.ts +5 -5
- package/dist/oauth/strava.cjs +46 -0
- package/dist/oauth/strava.d.ts +7 -0
- package/dist/oauth/strava.js +6 -0
- package/dist/oauth/x.d.ts +5 -5
- package/dist/{response.cjs → request.cjs} +14 -10
- package/dist/request.d.ts +13 -0
- package/dist/request.js +6 -0
- package/dist/schemas.cjs +43 -37
- package/dist/schemas.d.ts +67 -64
- package/dist/schemas.js +3 -1
- package/dist/secure.cjs +32 -24
- package/dist/secure.d.ts +5 -5
- package/dist/secure.js +4 -3
- package/dist/utils.cjs +90 -15
- package/dist/utils.d.ts +11 -2
- package/dist/utils.js +8 -4
- package/package.json +8 -7
- package/dist/chunk-FJUDBLCP.js +0 -59
- package/dist/chunk-HGJ4TXY4.js +0 -137
- package/dist/chunk-JAPMIE6S.js +0 -10
- package/dist/chunk-LLR722CL.js +0 -96
- package/dist/chunk-SJPDVKUS.js +0 -112
- package/dist/chunk-SMQO5WD7.js +0 -30
- package/dist/chunk-UTDLUEEG.js +0 -31
- package/dist/chunk-ZV4BH47P.js +0 -154
- package/dist/error.cjs +0 -88
- package/dist/error.d.ts +0 -62
- package/dist/error.js +0 -16
- package/dist/response.d.ts +0 -10
- package/dist/response.js +0 -6
package/dist/secure.js
CHANGED
|
@@ -5,9 +5,10 @@ import {
|
|
|
5
5
|
createPKCE,
|
|
6
6
|
generateSecure,
|
|
7
7
|
verifyCSRF
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-N2APGLXA.js";
|
|
9
|
+
import "./chunk-CXLATHS5.js";
|
|
10
|
+
import "./chunk-EIL2FPSS.js";
|
|
11
|
+
import "./chunk-RRLIF4PQ.js";
|
|
11
12
|
export {
|
|
12
13
|
createCSRF,
|
|
13
14
|
createDerivedSalt,
|
package/dist/utils.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
23
|
equals: () => equals,
|
|
24
|
+
formatZodError: () => formatZodError,
|
|
24
25
|
getNormalizedOriginPath: () => getNormalizedOriginPath,
|
|
25
26
|
isValidRelativePath: () => isValidRelativePath,
|
|
26
27
|
onErrorHandler: () => onErrorHandler,
|
|
@@ -28,21 +29,53 @@ __export(utils_exports, {
|
|
|
28
29
|
toCastCase: () => toCastCase,
|
|
29
30
|
toISOString: () => toISOString,
|
|
30
31
|
toSnakeCase: () => toSnakeCase,
|
|
31
|
-
toUpperCase: () => toUpperCase
|
|
32
|
+
toUpperCase: () => toUpperCase,
|
|
33
|
+
useSecureCookies: () => useSecureCookies
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(utils_exports);
|
|
34
36
|
var import_router = require("@aura-stack/router");
|
|
35
37
|
|
|
36
|
-
// src/
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
// src/errors.ts
|
|
39
|
+
var OAuthProtocolError = class extends Error {
|
|
40
|
+
type = "OAUTH_PROTOCOL_ERROR";
|
|
41
|
+
error;
|
|
42
|
+
errorURI;
|
|
43
|
+
constructor(error, description, errorURI, options) {
|
|
44
|
+
super(description, options);
|
|
45
|
+
this.error = error;
|
|
46
|
+
this.errorURI = errorURI;
|
|
47
|
+
this.name = new.target.name;
|
|
48
|
+
Error.captureStackTrace(this, new.target);
|
|
42
49
|
}
|
|
43
50
|
};
|
|
44
|
-
var
|
|
45
|
-
|
|
51
|
+
var AuthInternalError = class extends Error {
|
|
52
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
53
|
+
code;
|
|
54
|
+
constructor(code, message, options) {
|
|
55
|
+
super(message, options);
|
|
56
|
+
this.code = code;
|
|
57
|
+
this.name = new.target.name;
|
|
58
|
+
Error.captureStackTrace(this, new.target);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var AuthSecurityError = class extends Error {
|
|
62
|
+
type = "AUTH_SECURITY_ERROR";
|
|
63
|
+
code;
|
|
64
|
+
constructor(code, message, options) {
|
|
65
|
+
super(message, options);
|
|
66
|
+
this.code = code;
|
|
67
|
+
this.name = new.target.name;
|
|
68
|
+
Error.captureStackTrace(this, new.target);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var isOAuthProtocolError = (error) => {
|
|
72
|
+
return error instanceof OAuthProtocolError;
|
|
73
|
+
};
|
|
74
|
+
var isAuthInternalError = (error) => {
|
|
75
|
+
return error instanceof AuthInternalError;
|
|
76
|
+
};
|
|
77
|
+
var isAuthSecurityError = (error) => {
|
|
78
|
+
return error instanceof AuthSecurityError;
|
|
46
79
|
};
|
|
47
80
|
|
|
48
81
|
// src/utils.ts
|
|
@@ -106,13 +139,35 @@ var isValidRelativePath = (path) => {
|
|
|
106
139
|
var onErrorHandler = (error) => {
|
|
107
140
|
if ((0, import_router.isRouterError)(error)) {
|
|
108
141
|
const { message, status, statusText } = error;
|
|
109
|
-
return Response.json({
|
|
142
|
+
return Response.json({ type: "ROUTER_ERROR", code: "ROUTER_INTERNAL_ERROR", message }, { status, statusText });
|
|
143
|
+
}
|
|
144
|
+
if ((0, import_router.isInvalidZodSchemaError)(error)) {
|
|
145
|
+
return Response.json({ type: "ROUTER_ERROR", code: "INVALID_REQUEST", message: error.errors }, { status: 422 });
|
|
110
146
|
}
|
|
111
|
-
if (
|
|
112
|
-
const {
|
|
113
|
-
return Response.json(
|
|
147
|
+
if (isOAuthProtocolError(error)) {
|
|
148
|
+
const { error: errorCode, message, type, errorURI } = error;
|
|
149
|
+
return Response.json(
|
|
150
|
+
{
|
|
151
|
+
type,
|
|
152
|
+
error: errorCode,
|
|
153
|
+
error_description: message,
|
|
154
|
+
error_uri: errorURI
|
|
155
|
+
},
|
|
156
|
+
{ status: 400 }
|
|
157
|
+
);
|
|
114
158
|
}
|
|
115
|
-
|
|
159
|
+
if (isAuthInternalError(error) || isAuthSecurityError(error)) {
|
|
160
|
+
const { type, code, message } = error;
|
|
161
|
+
return Response.json(
|
|
162
|
+
{
|
|
163
|
+
type,
|
|
164
|
+
code,
|
|
165
|
+
message
|
|
166
|
+
},
|
|
167
|
+
{ status: 400 }
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return Response.json({ type: "SERVER_ERROR", code: "server_error", message: "An unexpected error occurred" }, { status: 500 });
|
|
116
171
|
};
|
|
117
172
|
var getNormalizedOriginPath = (path) => {
|
|
118
173
|
try {
|
|
@@ -127,9 +182,28 @@ var getNormalizedOriginPath = (path) => {
|
|
|
127
182
|
var toISOString = (date) => {
|
|
128
183
|
return new Date(date).toISOString();
|
|
129
184
|
};
|
|
185
|
+
var useSecureCookies = (request, trustedProxyHeaders) => {
|
|
186
|
+
return trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || (request.headers.get("Forwarded")?.includes("proto=https") ?? false) : request.url.startsWith("https://");
|
|
187
|
+
};
|
|
188
|
+
var formatZodError = (error) => {
|
|
189
|
+
if (!error.issues || error.issues.length === 0) {
|
|
190
|
+
return {};
|
|
191
|
+
}
|
|
192
|
+
return error.issues.reduce((previous, issue) => {
|
|
193
|
+
const key = issue.path.join(".");
|
|
194
|
+
return {
|
|
195
|
+
...previous,
|
|
196
|
+
[key]: {
|
|
197
|
+
code: issue.code,
|
|
198
|
+
message: issue.message
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}, {});
|
|
202
|
+
};
|
|
130
203
|
// Annotate the CommonJS export names for ESM import in node:
|
|
131
204
|
0 && (module.exports = {
|
|
132
205
|
equals,
|
|
206
|
+
formatZodError,
|
|
133
207
|
getNormalizedOriginPath,
|
|
134
208
|
isValidRelativePath,
|
|
135
209
|
onErrorHandler,
|
|
@@ -137,5 +211,6 @@ var toISOString = (date) => {
|
|
|
137
211
|
toCastCase,
|
|
138
212
|
toISOString,
|
|
139
213
|
toSnakeCase,
|
|
140
|
-
toUpperCase
|
|
214
|
+
toUpperCase,
|
|
215
|
+
useSecureCookies
|
|
141
216
|
});
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { RouterConfig } from '@aura-stack/router';
|
|
2
|
+
import { i as APIErrorMap } from './index-DkaLJFn8.js';
|
|
3
|
+
import { ZodError } from 'zod';
|
|
4
|
+
import './schemas.js';
|
|
5
|
+
import '@aura-stack/router/cookie';
|
|
6
|
+
import '@aura-stack/jose';
|
|
7
|
+
import '@aura-stack/jose/jose';
|
|
8
|
+
import './@types/utility.js';
|
|
2
9
|
|
|
3
10
|
declare const toSnakeCase: (str: string) => string;
|
|
4
11
|
declare const toUpperCase: (str: string) => string;
|
|
5
|
-
declare const toCastCase: <Obj extends Record<string,
|
|
12
|
+
declare const toCastCase: <Obj extends Record<string, string>, Type extends "snake" | "upper">(obj: Obj, type?: Type) => Type extends "snake" ? { [K in keyof Obj as `${string & K}`]: Obj[K]; } : { [K in keyof Obj as Uppercase<string & K>]: Obj[K]; };
|
|
6
13
|
declare const equals: (a: string | number | undefined | null, b: string | number | undefined | null) => boolean;
|
|
7
14
|
/**
|
|
8
15
|
* Sanitizes a URL by removing dangerous patterns that could be used for path traversal
|
|
@@ -41,5 +48,7 @@ declare const onErrorHandler: RouterConfig["onError"];
|
|
|
41
48
|
*/
|
|
42
49
|
declare const getNormalizedOriginPath: (path: string) => string;
|
|
43
50
|
declare const toISOString: (date: Date | string | number) => string;
|
|
51
|
+
declare const useSecureCookies: (request: Request, trustedProxyHeaders: boolean) => boolean;
|
|
52
|
+
declare const formatZodError: <T extends Record<string, unknown> = Record<string, unknown>>(error: ZodError<T>) => APIErrorMap;
|
|
44
53
|
|
|
45
|
-
export { equals, getNormalizedOriginPath, isValidRelativePath, onErrorHandler, sanitizeURL, toCastCase, toISOString, toSnakeCase, toUpperCase };
|
|
54
|
+
export { equals, formatZodError, getNormalizedOriginPath, isValidRelativePath, onErrorHandler, sanitizeURL, toCastCase, toISOString, toSnakeCase, toUpperCase, useSecureCookies };
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
equals,
|
|
3
|
+
formatZodError,
|
|
3
4
|
getNormalizedOriginPath,
|
|
4
5
|
isValidRelativePath,
|
|
5
6
|
onErrorHandler,
|
|
@@ -7,11 +8,13 @@ import {
|
|
|
7
8
|
toCastCase,
|
|
8
9
|
toISOString,
|
|
9
10
|
toSnakeCase,
|
|
10
|
-
toUpperCase
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
toUpperCase,
|
|
12
|
+
useSecureCookies
|
|
13
|
+
} from "./chunk-CXLATHS5.js";
|
|
14
|
+
import "./chunk-RRLIF4PQ.js";
|
|
13
15
|
export {
|
|
14
16
|
equals,
|
|
17
|
+
formatZodError,
|
|
15
18
|
getNormalizedOriginPath,
|
|
16
19
|
isValidRelativePath,
|
|
17
20
|
onErrorHandler,
|
|
@@ -19,5 +22,6 @@ export {
|
|
|
19
22
|
toCastCase,
|
|
20
23
|
toISOString,
|
|
21
24
|
toSnakeCase,
|
|
22
|
-
toUpperCase
|
|
25
|
+
toUpperCase,
|
|
26
|
+
useSecureCookies
|
|
23
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aura-stack/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Core auth for @aura-stack/auth",
|
|
@@ -44,15 +44,16 @@
|
|
|
44
44
|
},
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@aura-stack/router": "^0.
|
|
48
|
-
"cookie": "^1.0.2",
|
|
47
|
+
"@aura-stack/router": "^0.5.0",
|
|
49
48
|
"dotenv": "^17.2.3",
|
|
50
|
-
"zod": "^4.
|
|
51
|
-
"@aura-stack/jose": "0.
|
|
49
|
+
"zod": "^4.3.5",
|
|
50
|
+
"@aura-stack/jose": "0.2.0"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
53
|
+
"@types/node": "^24.9.2",
|
|
54
|
+
"typescript": "^5.9.2",
|
|
55
|
+
"@aura-stack/tsup-config": "0.0.0",
|
|
56
|
+
"@aura-stack/tsconfig": "0.0.0"
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
58
59
|
"dev": "tsup --watch",
|
package/dist/chunk-FJUDBLCP.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// src/error.ts
|
|
2
|
-
var AuthError = class extends Error {
|
|
3
|
-
constructor(type, message) {
|
|
4
|
-
super(message);
|
|
5
|
-
this.type = type;
|
|
6
|
-
this.name = "AuthError";
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
var InvalidCsrfTokenError = class extends AuthError {
|
|
10
|
-
constructor(message = "The provided CSRF token is invalid or has expired") {
|
|
11
|
-
super("invalid_csrf_token", message);
|
|
12
|
-
this.name = "InvalidCsrfTokenError";
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var InvalidRedirectToError = class extends AuthError {
|
|
16
|
-
constructor(message = "The redirectTo parameter does not match the hosted origin.") {
|
|
17
|
-
super("invalid_redirect_to", message);
|
|
18
|
-
this.name = "InvalidRedirectToError";
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var isAuthError = (error) => {
|
|
22
|
-
return error instanceof AuthError;
|
|
23
|
-
};
|
|
24
|
-
var throwAuthError = (error, message) => {
|
|
25
|
-
if (error instanceof Error) {
|
|
26
|
-
if (isAuthError(error)) {
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
throw new AuthError("invalid_request", error.message ?? message);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var ERROR_RESPONSE = {
|
|
33
|
-
AUTHORIZATION: {
|
|
34
|
-
INVALID_REQUEST: "invalid_request",
|
|
35
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
36
|
-
ACCESS_DENIED: "access_denied",
|
|
37
|
-
UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
|
|
38
|
-
INVALID_SCOPE: "invalid_scope",
|
|
39
|
-
SERVER_ERROR: "server_error",
|
|
40
|
-
TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
|
|
41
|
-
},
|
|
42
|
-
ACCESS_TOKEN: {
|
|
43
|
-
INVALID_REQUEST: "invalid_request",
|
|
44
|
-
INVALID_CLIENT: "invalid_client",
|
|
45
|
-
INVALID_GRANT: "invalid_grant",
|
|
46
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
47
|
-
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
48
|
-
INVALID_SCOPE: "invalid_scope"
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export {
|
|
53
|
-
AuthError,
|
|
54
|
-
InvalidCsrfTokenError,
|
|
55
|
-
InvalidRedirectToError,
|
|
56
|
-
isAuthError,
|
|
57
|
-
throwAuthError,
|
|
58
|
-
ERROR_RESPONSE
|
|
59
|
-
};
|
package/dist/chunk-HGJ4TXY4.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getUserInfo
|
|
3
|
-
} from "./chunk-RLT4RFKV.js";
|
|
4
|
-
import {
|
|
5
|
-
createAccessToken
|
|
6
|
-
} from "./chunk-UJJ7R56J.js";
|
|
7
|
-
import {
|
|
8
|
-
createSessionCookie,
|
|
9
|
-
expireCookie,
|
|
10
|
-
getCookie,
|
|
11
|
-
secureCookieOptions,
|
|
12
|
-
setCookie
|
|
13
|
-
} from "./chunk-ZV4BH47P.js";
|
|
14
|
-
import {
|
|
15
|
-
cacheControl
|
|
16
|
-
} from "./chunk-STHEPPUZ.js";
|
|
17
|
-
import {
|
|
18
|
-
createCSRF
|
|
19
|
-
} from "./chunk-GZU3RBTB.js";
|
|
20
|
-
import {
|
|
21
|
-
equals,
|
|
22
|
-
isValidRelativePath,
|
|
23
|
-
sanitizeURL
|
|
24
|
-
} from "./chunk-256KIVJL.js";
|
|
25
|
-
import {
|
|
26
|
-
AuthError,
|
|
27
|
-
ERROR_RESPONSE,
|
|
28
|
-
isAuthError
|
|
29
|
-
} from "./chunk-FJUDBLCP.js";
|
|
30
|
-
import {
|
|
31
|
-
AuraResponse
|
|
32
|
-
} from "./chunk-JAPMIE6S.js";
|
|
33
|
-
import {
|
|
34
|
-
OAuthAuthorizationErrorResponse,
|
|
35
|
-
OAuthAuthorizationResponse
|
|
36
|
-
} from "./chunk-HMRKN75I.js";
|
|
37
|
-
|
|
38
|
-
// src/actions/callback/callback.ts
|
|
39
|
-
import z from "zod";
|
|
40
|
-
import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router";
|
|
41
|
-
var callbackConfig = (oauth) => {
|
|
42
|
-
return createEndpointConfig("/callback/:oauth", {
|
|
43
|
-
schemas: {
|
|
44
|
-
searchParams: OAuthAuthorizationResponse,
|
|
45
|
-
params: z.object({
|
|
46
|
-
oauth: z.enum(Object.keys(oauth))
|
|
47
|
-
})
|
|
48
|
-
},
|
|
49
|
-
middlewares: [
|
|
50
|
-
(ctx) => {
|
|
51
|
-
const response = OAuthAuthorizationErrorResponse.safeParse(ctx.searchParams);
|
|
52
|
-
if (response.success) {
|
|
53
|
-
const { error, error_description } = response.data;
|
|
54
|
-
throw new AuthError(error, error_description ?? "OAuth Authorization Error");
|
|
55
|
-
}
|
|
56
|
-
return ctx;
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
var callbackAction = (oauth) => {
|
|
62
|
-
return createEndpoint(
|
|
63
|
-
"GET",
|
|
64
|
-
"/callback/:oauth",
|
|
65
|
-
async (ctx) => {
|
|
66
|
-
const {
|
|
67
|
-
request,
|
|
68
|
-
params: { oauth: oauth2 },
|
|
69
|
-
searchParams: { code, state },
|
|
70
|
-
context: { oauth: providers, cookies, jose, trustedProxyHeaders }
|
|
71
|
-
} = ctx;
|
|
72
|
-
try {
|
|
73
|
-
const oauthConfig = providers[oauth2];
|
|
74
|
-
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
|
|
75
|
-
const cookieState = getCookie(request, "state", cookieOptions);
|
|
76
|
-
const cookieRedirectTo = getCookie(request, "redirect_to", cookieOptions);
|
|
77
|
-
const cookieRedirectURI = getCookie(request, "redirect_uri", cookieOptions);
|
|
78
|
-
const codeVerifier = getCookie(request, "code_verifier", cookieOptions);
|
|
79
|
-
if (!equals(cookieState, state)) {
|
|
80
|
-
throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Mismatching state");
|
|
81
|
-
}
|
|
82
|
-
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier);
|
|
83
|
-
const sanitized = sanitizeURL(cookieRedirectTo);
|
|
84
|
-
if (!isValidRelativePath(sanitized)) {
|
|
85
|
-
throw new AuthError(
|
|
86
|
-
ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST,
|
|
87
|
-
"Invalid redirect path. Potential open redirect attack detected."
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
const headers = new Headers(cacheControl);
|
|
91
|
-
headers.set("Location", sanitized);
|
|
92
|
-
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
93
|
-
const sessionCookie = await createSessionCookie(userInfo, cookieOptions, jose);
|
|
94
|
-
const csrfToken = await createCSRF(jose);
|
|
95
|
-
const csrfCookie = setCookie(
|
|
96
|
-
"csrfToken",
|
|
97
|
-
csrfToken,
|
|
98
|
-
secureCookieOptions(
|
|
99
|
-
request,
|
|
100
|
-
{
|
|
101
|
-
...cookies,
|
|
102
|
-
strategy: "host"
|
|
103
|
-
},
|
|
104
|
-
trustedProxyHeaders
|
|
105
|
-
)
|
|
106
|
-
);
|
|
107
|
-
headers.set("Set-Cookie", sessionCookie);
|
|
108
|
-
headers.append("Set-Cookie", expireCookie("state", cookieOptions));
|
|
109
|
-
headers.append("Set-Cookie", expireCookie("redirect_uri", cookieOptions));
|
|
110
|
-
headers.append("Set-Cookie", expireCookie("redirect_to", cookieOptions));
|
|
111
|
-
headers.append("Set-Cookie", expireCookie("code_verifier", cookieOptions));
|
|
112
|
-
headers.append("Set-Cookie", csrfCookie);
|
|
113
|
-
return Response.json({ oauth: oauth2 }, { status: 302, headers });
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (isAuthError(error)) {
|
|
116
|
-
const { type, message } = error;
|
|
117
|
-
return AuraResponse.json(
|
|
118
|
-
{ error: type, error_description: message },
|
|
119
|
-
{ status: statusCode.BAD_REQUEST }
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
return AuraResponse.json(
|
|
123
|
-
{
|
|
124
|
-
error: ERROR_RESPONSE.ACCESS_TOKEN.INVALID_CLIENT,
|
|
125
|
-
error_description: "An unexpected error occurred"
|
|
126
|
-
},
|
|
127
|
-
{ status: statusCode.INTERNAL_SERVER_ERROR }
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
callbackConfig(oauth)
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export {
|
|
136
|
-
callbackAction
|
|
137
|
-
};
|
package/dist/chunk-JAPMIE6S.js
DELETED
package/dist/chunk-LLR722CL.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createAuthorizationURL,
|
|
3
|
-
createRedirectTo,
|
|
4
|
-
createRedirectURI
|
|
5
|
-
} from "./chunk-CAKJT3KS.js";
|
|
6
|
-
import {
|
|
7
|
-
oauthCookie,
|
|
8
|
-
secureCookieOptions,
|
|
9
|
-
setCookie
|
|
10
|
-
} from "./chunk-ZV4BH47P.js";
|
|
11
|
-
import {
|
|
12
|
-
createPKCE,
|
|
13
|
-
generateSecure
|
|
14
|
-
} from "./chunk-GZU3RBTB.js";
|
|
15
|
-
import {
|
|
16
|
-
ERROR_RESPONSE,
|
|
17
|
-
isAuthError
|
|
18
|
-
} from "./chunk-FJUDBLCP.js";
|
|
19
|
-
import {
|
|
20
|
-
AuraResponse
|
|
21
|
-
} from "./chunk-JAPMIE6S.js";
|
|
22
|
-
|
|
23
|
-
// src/actions/signIn/signIn.ts
|
|
24
|
-
import z from "zod";
|
|
25
|
-
import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router";
|
|
26
|
-
var signInConfig = (oauth) => {
|
|
27
|
-
return createEndpointConfig("/signIn/:oauth", {
|
|
28
|
-
schemas: {
|
|
29
|
-
params: z.object({
|
|
30
|
-
oauth: z.enum(Object.keys(oauth)),
|
|
31
|
-
redirectTo: z.string().optional()
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
var signInAction = (oauth) => {
|
|
37
|
-
return createEndpoint(
|
|
38
|
-
"GET",
|
|
39
|
-
"/signIn/:oauth",
|
|
40
|
-
async (ctx) => {
|
|
41
|
-
const {
|
|
42
|
-
request,
|
|
43
|
-
params: { oauth: oauth2, redirectTo },
|
|
44
|
-
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
45
|
-
} = ctx;
|
|
46
|
-
try {
|
|
47
|
-
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
|
|
48
|
-
const state = generateSecure();
|
|
49
|
-
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
|
|
50
|
-
const stateCookie = setCookie("state", state, oauthCookie(cookieOptions));
|
|
51
|
-
const redirectURICookie = setCookie("redirect_uri", redirectURI, oauthCookie(cookieOptions));
|
|
52
|
-
const redirectToCookie = setCookie(
|
|
53
|
-
"redirect_to",
|
|
54
|
-
createRedirectTo(request, redirectTo, trustedProxyHeaders),
|
|
55
|
-
oauthCookie(cookieOptions)
|
|
56
|
-
);
|
|
57
|
-
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
58
|
-
const codeVerifierCookie = setCookie("code_verifier", codeVerifier, oauthCookie(cookieOptions));
|
|
59
|
-
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
60
|
-
const headers = new Headers();
|
|
61
|
-
headers.set("Location", authorization);
|
|
62
|
-
headers.append("Set-Cookie", stateCookie);
|
|
63
|
-
headers.append("Set-Cookie", redirectURICookie);
|
|
64
|
-
headers.append("Set-Cookie", redirectToCookie);
|
|
65
|
-
headers.append("Set-Cookie", codeVerifierCookie);
|
|
66
|
-
return Response.json(
|
|
67
|
-
{ oauth: oauth2 },
|
|
68
|
-
{
|
|
69
|
-
status: 302,
|
|
70
|
-
headers
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
if (isAuthError(error)) {
|
|
75
|
-
const { type, message } = error;
|
|
76
|
-
return AuraResponse.json(
|
|
77
|
-
{ error: type, error_description: message },
|
|
78
|
-
{ status: statusCode.BAD_REQUEST }
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
return AuraResponse.json(
|
|
82
|
-
{
|
|
83
|
-
error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
|
|
84
|
-
error_description: "An unexpected error occurred"
|
|
85
|
-
},
|
|
86
|
-
{ status: statusCode.INTERNAL_SERVER_ERROR }
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
signInConfig(oauth)
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export {
|
|
95
|
-
signInAction
|
|
96
|
-
};
|
package/dist/chunk-SJPDVKUS.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRedirectTo
|
|
3
|
-
} from "./chunk-CAKJT3KS.js";
|
|
4
|
-
import {
|
|
5
|
-
expireCookie,
|
|
6
|
-
getCookie,
|
|
7
|
-
secureCookieOptions
|
|
8
|
-
} from "./chunk-ZV4BH47P.js";
|
|
9
|
-
import {
|
|
10
|
-
cacheControl
|
|
11
|
-
} from "./chunk-STHEPPUZ.js";
|
|
12
|
-
import {
|
|
13
|
-
verifyCSRF
|
|
14
|
-
} from "./chunk-GZU3RBTB.js";
|
|
15
|
-
import {
|
|
16
|
-
getNormalizedOriginPath
|
|
17
|
-
} from "./chunk-256KIVJL.js";
|
|
18
|
-
import {
|
|
19
|
-
InvalidCsrfTokenError,
|
|
20
|
-
InvalidRedirectToError
|
|
21
|
-
} from "./chunk-FJUDBLCP.js";
|
|
22
|
-
import {
|
|
23
|
-
AuraResponse
|
|
24
|
-
} from "./chunk-JAPMIE6S.js";
|
|
25
|
-
|
|
26
|
-
// src/actions/signOut/signOut.ts
|
|
27
|
-
import z from "zod";
|
|
28
|
-
import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router";
|
|
29
|
-
var config = createEndpointConfig({
|
|
30
|
-
schemas: {
|
|
31
|
-
searchParams: z.object({
|
|
32
|
-
token_type_hint: z.literal("session_token"),
|
|
33
|
-
redirectTo: z.string().optional()
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
var signOutAction = createEndpoint(
|
|
38
|
-
"POST",
|
|
39
|
-
"/signOut",
|
|
40
|
-
async (ctx) => {
|
|
41
|
-
const {
|
|
42
|
-
request,
|
|
43
|
-
headers,
|
|
44
|
-
searchParams: { redirectTo },
|
|
45
|
-
context: { cookies, jose, trustedProxyHeaders }
|
|
46
|
-
} = ctx;
|
|
47
|
-
try {
|
|
48
|
-
const cookiesOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
|
|
49
|
-
const session = getCookie(request, "sessionToken", cookiesOptions);
|
|
50
|
-
const csrfToken = getCookie(request, "csrfToken", {
|
|
51
|
-
...cookiesOptions,
|
|
52
|
-
prefix: cookiesOptions.secure ? "__Host-" : ""
|
|
53
|
-
});
|
|
54
|
-
const header = headers.get("X-CSRF-Token");
|
|
55
|
-
if (!header || !session || !csrfToken) {
|
|
56
|
-
throw new Error("Missing CSRF token or session token");
|
|
57
|
-
}
|
|
58
|
-
await verifyCSRF(jose, csrfToken, header);
|
|
59
|
-
await jose.decodeJWT(session);
|
|
60
|
-
const normalizedOriginPath = getNormalizedOriginPath(request.url);
|
|
61
|
-
const location = createRedirectTo(
|
|
62
|
-
new Request(normalizedOriginPath, {
|
|
63
|
-
headers
|
|
64
|
-
}),
|
|
65
|
-
redirectTo
|
|
66
|
-
);
|
|
67
|
-
const responseHeaders = new Headers(cacheControl);
|
|
68
|
-
responseHeaders.append("Set-Cookie", expireCookie("sessionToken", cookiesOptions));
|
|
69
|
-
responseHeaders.append(
|
|
70
|
-
"Set-Cookie",
|
|
71
|
-
expireCookie("csrfToken", { ...cookiesOptions, prefix: cookiesOptions.secure ? "__Host-" : "" })
|
|
72
|
-
);
|
|
73
|
-
responseHeaders.append("Location", location);
|
|
74
|
-
return Response.json(
|
|
75
|
-
{ message: "Signed out successfully" },
|
|
76
|
-
{ status: statusCode.ACCEPTED, headers: responseHeaders }
|
|
77
|
-
);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (error instanceof InvalidCsrfTokenError) {
|
|
80
|
-
return AuraResponse.json(
|
|
81
|
-
{
|
|
82
|
-
error: "invalid_csrf_token",
|
|
83
|
-
error_description: "The provided CSRF token is invalid or has expired"
|
|
84
|
-
},
|
|
85
|
-
{ status: statusCode.UNAUTHORIZED }
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
if (error instanceof InvalidRedirectToError) {
|
|
89
|
-
const { type, message } = error;
|
|
90
|
-
return AuraResponse.json(
|
|
91
|
-
{
|
|
92
|
-
error: type,
|
|
93
|
-
error_description: message
|
|
94
|
-
},
|
|
95
|
-
{ status: statusCode.BAD_REQUEST }
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
return AuraResponse.json(
|
|
99
|
-
{
|
|
100
|
-
error: "invalid_session_token",
|
|
101
|
-
error_description: "The provided sessionToken is invalid or has already expired"
|
|
102
|
-
},
|
|
103
|
-
{ status: statusCode.UNAUTHORIZED }
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
config
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
export {
|
|
111
|
-
signOutAction
|
|
112
|
-
};
|