@aura-stack/auth 0.2.0 → 0.4.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 +3 -2
- package/dist/@types/router.d.d.ts +3 -2
- package/dist/actions/callback/access-token.cjs +52 -41
- package/dist/actions/callback/access-token.d.ts +5 -4
- package/dist/actions/callback/access-token.js +3 -2
- package/dist/actions/callback/callback.cjs +69 -52
- package/dist/actions/callback/callback.d.ts +26 -3
- package/dist/actions/callback/callback.js +6 -5
- package/dist/actions/callback/userinfo.cjs +54 -43
- package/dist/actions/callback/userinfo.d.ts +3 -2
- package/dist/actions/callback/userinfo.js +3 -2
- package/dist/actions/csrfToken/csrfToken.cjs +2 -2
- package/dist/actions/csrfToken/csrfToken.d.ts +3 -1
- package/dist/actions/csrfToken/csrfToken.js +2 -2
- package/dist/actions/index.cjs +93 -71
- package/dist/actions/index.d.ts +3 -2
- package/dist/actions/index.js +15 -14
- package/dist/actions/session/session.d.ts +3 -1
- package/dist/actions/session/session.js +2 -2
- package/dist/actions/signIn/authorization.cjs +40 -40
- package/dist/actions/signIn/authorization.d.ts +3 -2
- package/dist/actions/signIn/authorization.js +2 -2
- package/dist/actions/signIn/signIn.cjs +63 -50
- package/dist/actions/signIn/signIn.d.ts +25 -3
- package/dist/actions/signIn/signIn.js +4 -3
- package/dist/actions/signOut/signOut.cjs +66 -66
- package/dist/actions/signOut/signOut.d.ts +9 -1
- package/dist/actions/signOut/signOut.js +4 -4
- package/dist/assert.d.ts +3 -2
- package/dist/{chunk-2RXNXMCZ.js → chunk-3EUWD5BB.js} +15 -7
- package/dist/{chunk-NEVKX6K2.js → chunk-A3N4PVAT.js} +3 -3
- package/dist/chunk-B737EUJV.js +22 -0
- package/dist/{chunk-7H3OR6UU.js → chunk-EMKJA2GJ.js} +18 -10
- package/dist/{chunk-4V4JNXVF.js → chunk-GA2SMTJO.js} +9 -6
- package/dist/chunk-HP34YGGJ.js +22 -0
- package/dist/{chunk-QDO2KSRJ.js → chunk-HT4YLL7N.js} +1 -1
- package/dist/{chunk-ZLR3LI6X.js → chunk-IVET23KF.js} +7 -4
- package/dist/{chunk-PTJUYB33.js → chunk-JVFTCTTE.js} +1 -1
- package/dist/{chunk-UEH3LVON.js → chunk-KSWLO5ZU.js} +21 -16
- package/dist/{chunk-QEZL7EYN.js → chunk-N4SX7TZT.js} +3 -3
- package/dist/{chunk-IMICRJ5U.js → chunk-W6LG7BFW.js} +14 -14
- package/dist/{chunk-WD7AUHQ5.js → chunk-YRCB5FLE.js} +8 -8
- package/dist/chunk-ZNCZVF6U.js +14 -0
- package/dist/cookie.cjs +14 -14
- package/dist/cookie.d.ts +3 -2
- package/dist/cookie.js +1 -1
- package/dist/errors.d.ts +3 -2
- package/dist/{index-EqsoyjrF.d.ts → index-B8jeIElf.d.ts} +57 -8
- package/dist/index.cjs +159 -95
- package/dist/index.d.ts +66 -5
- package/dist/index.js +23 -19
- package/dist/jose.cjs +2 -2
- package/dist/oauth/bitbucket.d.ts +3 -2
- package/dist/oauth/discord.d.ts +3 -2
- package/dist/oauth/figma.d.ts +3 -2
- package/dist/oauth/github.d.ts +3 -2
- package/dist/oauth/gitlab.d.ts +3 -2
- package/dist/oauth/index.cjs +85 -41
- package/dist/oauth/index.d.ts +3 -2
- package/dist/oauth/index.js +16 -8
- 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 +3 -2
- package/dist/oauth/strava.d.ts +3 -2
- package/dist/oauth/x.d.ts +3 -2
- package/dist/request.cjs +38 -0
- package/dist/request.d.ts +13 -0
- package/dist/request.js +6 -0
- package/dist/schemas.cjs +40 -40
- package/dist/schemas.d.ts +15 -15
- package/dist/schemas.js +1 -1
- package/dist/secure.cjs +5 -5
- package/dist/secure.d.ts +3 -2
- package/dist/utils.d.ts +3 -3
- package/package.json +7 -5
package/dist/index.cjs
CHANGED
|
@@ -30,12 +30,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
createAuth: () => createAuth
|
|
33
|
+
createAuth: () => createAuth,
|
|
34
|
+
createClient: () => import_router7.createClient
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(index_exports);
|
|
36
37
|
var import_config2 = require("dotenv/config");
|
|
37
38
|
var import_router7 = require("@aura-stack/router");
|
|
38
39
|
|
|
40
|
+
// src/jose.ts
|
|
41
|
+
var import_config = require("dotenv/config");
|
|
42
|
+
var import_jose = require("@aura-stack/jose");
|
|
43
|
+
|
|
44
|
+
// src/secure.ts
|
|
45
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
46
|
+
|
|
39
47
|
// src/utils.ts
|
|
40
48
|
var import_router = require("@aura-stack/router");
|
|
41
49
|
|
|
@@ -208,13 +216,6 @@ var formatZodError = (error) => {
|
|
|
208
216
|
}, {});
|
|
209
217
|
};
|
|
210
218
|
|
|
211
|
-
// src/jose.ts
|
|
212
|
-
var import_config = require("dotenv/config");
|
|
213
|
-
var import_jose = require("@aura-stack/jose");
|
|
214
|
-
|
|
215
|
-
// src/secure.ts
|
|
216
|
-
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
217
|
-
|
|
218
219
|
// src/assert.ts
|
|
219
220
|
var isValidURL = (value) => {
|
|
220
221
|
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
|
|
@@ -227,10 +228,10 @@ var isJWTPayloadWithToken = (payload) => {
|
|
|
227
228
|
|
|
228
229
|
// src/secure.ts
|
|
229
230
|
var generateSecure = (length = 32) => {
|
|
230
|
-
return
|
|
231
|
+
return import_crypto.default.randomBytes(length).toString("base64url");
|
|
231
232
|
};
|
|
232
233
|
var createHash = (data, base = "hex") => {
|
|
233
|
-
return
|
|
234
|
+
return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
|
|
234
235
|
};
|
|
235
236
|
var createPKCE = async (verifier) => {
|
|
236
237
|
const codeVerifier = verifier ?? generateSecure(86);
|
|
@@ -265,7 +266,7 @@ var verifyCSRF = async (jose, cookie, header) => {
|
|
|
265
266
|
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
266
267
|
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
267
268
|
}
|
|
268
|
-
if (!
|
|
269
|
+
if (!import_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
|
|
269
270
|
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
270
271
|
}
|
|
271
272
|
return true;
|
|
@@ -274,7 +275,7 @@ var verifyCSRF = async (jose, cookie, header) => {
|
|
|
274
275
|
}
|
|
275
276
|
};
|
|
276
277
|
var createDerivedSalt = (secret) => {
|
|
277
|
-
return
|
|
278
|
+
return import_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
|
|
278
279
|
};
|
|
279
280
|
|
|
280
281
|
// src/jose.ts
|
|
@@ -404,7 +405,7 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
404
405
|
const hostPrefix = useSecure ? "__Host-" : "";
|
|
405
406
|
return {
|
|
406
407
|
sessionToken: {
|
|
407
|
-
name: `${securePrefix}${prefix}.${overrides?.sessionToken?.name ?? "
|
|
408
|
+
name: `${securePrefix}${prefix}.${overrides?.sessionToken?.name ?? "session_token"}`,
|
|
408
409
|
attributes: defineSecureCookieOptions(
|
|
409
410
|
useSecure,
|
|
410
411
|
{
|
|
@@ -426,7 +427,7 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
426
427
|
)
|
|
427
428
|
},
|
|
428
429
|
csrfToken: {
|
|
429
|
-
name: `${hostPrefix}${prefix}.${overrides?.csrfToken?.name ?? "
|
|
430
|
+
name: `${hostPrefix}${prefix}.${overrides?.csrfToken?.name ?? "csrf_token"}`,
|
|
430
431
|
attributes: defineSecureCookieOptions(
|
|
431
432
|
useSecure,
|
|
432
433
|
{
|
|
@@ -436,37 +437,37 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
436
437
|
overrides?.csrfToken?.attributes?.strategy ?? "host"
|
|
437
438
|
)
|
|
438
439
|
},
|
|
439
|
-
|
|
440
|
-
name: `${securePrefix}${prefix}.${overrides?.
|
|
440
|
+
redirectTo: {
|
|
441
|
+
name: `${securePrefix}${prefix}.${overrides?.redirectTo?.name ?? "redirect_to"}`,
|
|
441
442
|
attributes: defineSecureCookieOptions(
|
|
442
443
|
useSecure,
|
|
443
444
|
{
|
|
444
445
|
...oauthCookieOptions,
|
|
445
|
-
...overrides?.
|
|
446
|
+
...overrides?.redirectTo?.attributes
|
|
446
447
|
},
|
|
447
|
-
overrides?.
|
|
448
|
+
overrides?.redirectTo?.attributes?.strategy ?? "secure"
|
|
448
449
|
)
|
|
449
450
|
},
|
|
450
|
-
|
|
451
|
-
name: `${securePrefix}${prefix}.${overrides?.
|
|
451
|
+
redirectURI: {
|
|
452
|
+
name: `${securePrefix}${prefix}.${overrides?.redirectURI?.name ?? "redirect_uri"}`,
|
|
452
453
|
attributes: defineSecureCookieOptions(
|
|
453
454
|
useSecure,
|
|
454
455
|
{
|
|
455
456
|
...oauthCookieOptions,
|
|
456
|
-
...overrides?.
|
|
457
|
+
...overrides?.redirectURI?.attributes
|
|
457
458
|
},
|
|
458
|
-
overrides?.
|
|
459
|
+
overrides?.redirectURI?.attributes?.strategy ?? "secure"
|
|
459
460
|
)
|
|
460
461
|
},
|
|
461
|
-
|
|
462
|
-
name: `${securePrefix}${prefix}.${overrides?.
|
|
462
|
+
codeVerifier: {
|
|
463
|
+
name: `${securePrefix}${prefix}.${overrides?.codeVerifier?.name ?? "code_verifier"}`,
|
|
463
464
|
attributes: defineSecureCookieOptions(
|
|
464
465
|
useSecure,
|
|
465
466
|
{
|
|
466
467
|
...oauthCookieOptions,
|
|
467
|
-
...overrides?.
|
|
468
|
+
...overrides?.codeVerifier?.attributes
|
|
468
469
|
},
|
|
469
|
-
overrides?.
|
|
470
|
+
overrides?.codeVerifier?.attributes?.strategy ?? "secure"
|
|
470
471
|
)
|
|
471
472
|
}
|
|
472
473
|
};
|
|
@@ -623,29 +624,67 @@ var strava = {
|
|
|
623
624
|
}
|
|
624
625
|
};
|
|
625
626
|
|
|
627
|
+
// src/oauth/mailchimp.ts
|
|
628
|
+
var mailchimp = {
|
|
629
|
+
id: "mailchimp",
|
|
630
|
+
name: "Mailchimp",
|
|
631
|
+
authorizeURL: "https://login.mailchimp.com/oauth2/authorize",
|
|
632
|
+
accessToken: "https://login.mailchimp.com/oauth2/token",
|
|
633
|
+
userInfo: "https://login.mailchimp.com/oauth2/metadata",
|
|
634
|
+
scope: "",
|
|
635
|
+
responseType: "code",
|
|
636
|
+
profile(profile) {
|
|
637
|
+
return {
|
|
638
|
+
sub: profile.user_id,
|
|
639
|
+
name: profile.accountname,
|
|
640
|
+
email: profile.login.login_email,
|
|
641
|
+
image: null
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/oauth/pinterest.ts
|
|
647
|
+
var pinterest = {
|
|
648
|
+
id: "pinterest",
|
|
649
|
+
name: "Pinterest",
|
|
650
|
+
authorizeURL: "https://api.pinterest.com/oauth/",
|
|
651
|
+
accessToken: "https://api.pinterest.com/v5/oauth/token",
|
|
652
|
+
userInfo: "https://api.pinterest.com/v5/user_account",
|
|
653
|
+
scope: "user_accounts:read",
|
|
654
|
+
responseType: "code",
|
|
655
|
+
profile(profile) {
|
|
656
|
+
return {
|
|
657
|
+
sub: profile.id,
|
|
658
|
+
name: profile.username,
|
|
659
|
+
email: null,
|
|
660
|
+
image: profile.profile_image
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
|
|
626
665
|
// src/schemas.ts
|
|
627
|
-
var
|
|
628
|
-
var OAuthProviderConfigSchema = (0,
|
|
629
|
-
authorizeURL: (0,
|
|
630
|
-
accessToken: (0,
|
|
631
|
-
scope: (0,
|
|
632
|
-
userInfo: (0,
|
|
633
|
-
responseType: (0,
|
|
634
|
-
clientId: (0,
|
|
635
|
-
clientSecret: (0,
|
|
666
|
+
var import_zod = require("zod");
|
|
667
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
668
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
669
|
+
accessToken: (0, import_zod.string)().url(),
|
|
670
|
+
scope: (0, import_zod.string)().optional(),
|
|
671
|
+
userInfo: (0, import_zod.string)().url(),
|
|
672
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
673
|
+
clientId: (0, import_zod.string)(),
|
|
674
|
+
clientSecret: (0, import_zod.string)()
|
|
636
675
|
});
|
|
637
676
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
638
|
-
redirectURI: (0,
|
|
639
|
-
state: (0,
|
|
640
|
-
codeChallenge: (0,
|
|
641
|
-
codeChallengeMethod: (0,
|
|
677
|
+
redirectURI: (0, import_zod.string)(),
|
|
678
|
+
state: (0, import_zod.string)(),
|
|
679
|
+
codeChallenge: (0, import_zod.string)(),
|
|
680
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
642
681
|
});
|
|
643
|
-
var OAuthAuthorizationResponse = (0,
|
|
644
|
-
state: (0,
|
|
645
|
-
code: (0,
|
|
682
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
683
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
684
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
646
685
|
});
|
|
647
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
648
|
-
error: (0,
|
|
686
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
687
|
+
error: (0, import_zod.enum)([
|
|
649
688
|
"invalid_request",
|
|
650
689
|
"unauthorized_client",
|
|
651
690
|
"access_denied",
|
|
@@ -654,24 +693,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
|
654
693
|
"server_error",
|
|
655
694
|
"temporarily_unavailable"
|
|
656
695
|
]),
|
|
657
|
-
error_description: (0,
|
|
658
|
-
error_uri: (0,
|
|
659
|
-
state: (0,
|
|
696
|
+
error_description: (0, import_zod.string)().optional(),
|
|
697
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
698
|
+
state: (0, import_zod.string)()
|
|
660
699
|
});
|
|
661
700
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
662
|
-
redirectURI: (0,
|
|
663
|
-
code: (0,
|
|
664
|
-
codeVerifier: (0,
|
|
701
|
+
redirectURI: (0, import_zod.string)(),
|
|
702
|
+
code: (0, import_zod.string)(),
|
|
703
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
665
704
|
});
|
|
666
|
-
var OAuthAccessTokenResponse = (0,
|
|
667
|
-
access_token: (0,
|
|
668
|
-
token_type: (0,
|
|
669
|
-
expires_in: (0,
|
|
670
|
-
refresh_token: (0,
|
|
671
|
-
scope: (0,
|
|
705
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
706
|
+
access_token: (0, import_zod.string)(),
|
|
707
|
+
token_type: (0, import_zod.string)().optional(),
|
|
708
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
709
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
710
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
672
711
|
});
|
|
673
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
674
|
-
error: (0,
|
|
712
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
713
|
+
error: (0, import_zod.enum)([
|
|
675
714
|
"invalid_request",
|
|
676
715
|
"invalid_client",
|
|
677
716
|
"invalid_grant",
|
|
@@ -679,16 +718,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
|
679
718
|
"unsupported_grant_type",
|
|
680
719
|
"invalid_scope"
|
|
681
720
|
]),
|
|
682
|
-
error_description: (0,
|
|
683
|
-
error_uri: (0,
|
|
721
|
+
error_description: (0, import_zod.string)().optional(),
|
|
722
|
+
error_uri: (0, import_zod.string)().optional()
|
|
684
723
|
});
|
|
685
|
-
var OAuthErrorResponse = (0,
|
|
686
|
-
error: (0,
|
|
687
|
-
error_description: (0,
|
|
724
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
725
|
+
error: (0, import_zod.string)(),
|
|
726
|
+
error_description: (0, import_zod.string)().optional()
|
|
688
727
|
});
|
|
689
|
-
var OAuthEnvSchema = (0,
|
|
690
|
-
clientId:
|
|
691
|
-
clientSecret:
|
|
728
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
729
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
730
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
692
731
|
});
|
|
693
732
|
|
|
694
733
|
// src/oauth/index.ts
|
|
@@ -700,7 +739,9 @@ var builtInOAuthProviders = {
|
|
|
700
739
|
gitlab,
|
|
701
740
|
spotify,
|
|
702
741
|
x,
|
|
703
|
-
strava
|
|
742
|
+
strava,
|
|
743
|
+
mailchimp,
|
|
744
|
+
pinterest
|
|
704
745
|
};
|
|
705
746
|
var defineOAuthEnvironment = (oauth) => {
|
|
706
747
|
const env = process.env;
|
|
@@ -735,9 +776,17 @@ var createBuiltInOAuthProviders = (oauth = []) => {
|
|
|
735
776
|
};
|
|
736
777
|
|
|
737
778
|
// src/actions/signIn/signIn.ts
|
|
738
|
-
var
|
|
779
|
+
var import_zod2 = require("zod");
|
|
739
780
|
var import_router2 = require("@aura-stack/router");
|
|
740
781
|
|
|
782
|
+
// src/headers.ts
|
|
783
|
+
var cacheControl = {
|
|
784
|
+
"Cache-Control": "no-store",
|
|
785
|
+
Pragma: "no-cache",
|
|
786
|
+
Expires: "0",
|
|
787
|
+
Vary: "Cookie"
|
|
788
|
+
};
|
|
789
|
+
|
|
741
790
|
// src/actions/signIn/authorization.ts
|
|
742
791
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
743
792
|
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
@@ -813,9 +862,14 @@ var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
|
813
862
|
var signInConfig = (oauth) => {
|
|
814
863
|
return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
|
|
815
864
|
schemas: {
|
|
816
|
-
params:
|
|
817
|
-
oauth:
|
|
818
|
-
|
|
865
|
+
params: import_zod2.z.object({
|
|
866
|
+
oauth: import_zod2.z.enum(
|
|
867
|
+
Object.keys(oauth),
|
|
868
|
+
"The OAuth provider is not supported or invalid."
|
|
869
|
+
)
|
|
870
|
+
}),
|
|
871
|
+
searchParams: import_zod2.z.object({
|
|
872
|
+
redirectTo: import_zod2.z.string().optional()
|
|
819
873
|
})
|
|
820
874
|
}
|
|
821
875
|
});
|
|
@@ -827,8 +881,8 @@ var signInAction = (oauth) => {
|
|
|
827
881
|
async (ctx) => {
|
|
828
882
|
const {
|
|
829
883
|
request,
|
|
830
|
-
|
|
831
|
-
|
|
884
|
+
params: { oauth: oauth2 },
|
|
885
|
+
searchParams: { redirectTo },
|
|
832
886
|
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
833
887
|
} = ctx;
|
|
834
888
|
const state = generateSecure();
|
|
@@ -836,7 +890,7 @@ var signInAction = (oauth) => {
|
|
|
836
890
|
const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
|
|
837
891
|
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
838
892
|
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
839
|
-
const headers =
|
|
893
|
+
const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirectURI.name, redirectURI, cookies.redirectURI.attributes).setCookie(cookies.redirectTo.name, redirectToValue, cookies.redirectTo.attributes).setCookie(cookies.codeVerifier.name, codeVerifier, cookies.codeVerifier.attributes).toHeaders();
|
|
840
894
|
return Response.json(
|
|
841
895
|
{ oauth: oauth2 },
|
|
842
896
|
{
|
|
@@ -850,15 +904,18 @@ var signInAction = (oauth) => {
|
|
|
850
904
|
};
|
|
851
905
|
|
|
852
906
|
// src/actions/callback/callback.ts
|
|
853
|
-
var
|
|
907
|
+
var import_zod3 = require("zod");
|
|
854
908
|
var import_router3 = require("@aura-stack/router");
|
|
855
909
|
|
|
856
|
-
// src/
|
|
857
|
-
var
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
910
|
+
// src/request.ts
|
|
911
|
+
var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
|
|
912
|
+
const controller = new AbortController();
|
|
913
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
914
|
+
const response = await fetch(url, {
|
|
915
|
+
...options2,
|
|
916
|
+
signal: controller.signal
|
|
917
|
+
}).finally(() => clearTimeout(timeoutId));
|
|
918
|
+
return response;
|
|
862
919
|
};
|
|
863
920
|
|
|
864
921
|
// src/actions/callback/userinfo.ts
|
|
@@ -874,7 +931,7 @@ var getDefaultUserInfo = (profile) => {
|
|
|
874
931
|
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
875
932
|
const userinfoEndpoint = oauthConfig.userInfo;
|
|
876
933
|
try {
|
|
877
|
-
const response = await
|
|
934
|
+
const response = await fetchAsync(userinfoEndpoint, {
|
|
878
935
|
method: "GET",
|
|
879
936
|
headers: {
|
|
880
937
|
Accept: "application/json",
|
|
@@ -910,7 +967,7 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
|
|
|
910
967
|
}
|
|
911
968
|
const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
|
|
912
969
|
try {
|
|
913
|
-
const response = await
|
|
970
|
+
const response = await fetchAsync(accessToken, {
|
|
914
971
|
method: "POST",
|
|
915
972
|
headers: {
|
|
916
973
|
Accept: "application/json",
|
|
@@ -944,9 +1001,15 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
|
|
|
944
1001
|
var callbackConfig = (oauth) => {
|
|
945
1002
|
return (0, import_router3.createEndpointConfig)("/callback/:oauth", {
|
|
946
1003
|
schemas: {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
1004
|
+
params: import_zod3.z.object({
|
|
1005
|
+
oauth: import_zod3.z.enum(
|
|
1006
|
+
Object.keys(oauth),
|
|
1007
|
+
"The OAuth provider is not supported or invalid."
|
|
1008
|
+
)
|
|
1009
|
+
}),
|
|
1010
|
+
searchParams: import_zod3.z.object({
|
|
1011
|
+
code: import_zod3.z.string("Missing code parameter in the OAuth authorization response."),
|
|
1012
|
+
state: import_zod3.z.string("Missing state parameter in the OAuth authorization response.")
|
|
950
1013
|
})
|
|
951
1014
|
},
|
|
952
1015
|
middlewares: [
|
|
@@ -974,9 +1037,9 @@ var callbackAction = (oauth) => {
|
|
|
974
1037
|
} = ctx;
|
|
975
1038
|
const oauthConfig = providers[oauth2];
|
|
976
1039
|
const cookieState = getCookie(request, cookies.state.name);
|
|
977
|
-
const cookieRedirectTo = getCookie(request, cookies.
|
|
978
|
-
const cookieRedirectURI = getCookie(request, cookies.
|
|
979
|
-
const codeVerifier = getCookie(request, cookies.
|
|
1040
|
+
const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
|
|
1041
|
+
const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
|
|
1042
|
+
const codeVerifier = getCookie(request, cookies.codeVerifier.name);
|
|
980
1043
|
if (!equals(cookieState, state)) {
|
|
981
1044
|
throw new AuthSecurityError(
|
|
982
1045
|
"MISMATCHING_STATE",
|
|
@@ -994,7 +1057,7 @@ var callbackAction = (oauth) => {
|
|
|
994
1057
|
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
995
1058
|
const sessionCookie = await createSessionCookie(jose, userInfo);
|
|
996
1059
|
const csrfToken = await createCSRF(jose);
|
|
997
|
-
const headers = new import_router3.HeadersBuilder(cacheControl).setHeader("Location", sanitized).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.
|
|
1060
|
+
const headers = new import_router3.HeadersBuilder(cacheControl).setHeader("Location", sanitized).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirectURI.name, "", expiredCookieAttributes).setCookie(cookies.redirectTo.name, "", expiredCookieAttributes).setCookie(cookies.codeVerifier.name, "", expiredCookieAttributes).toHeaders();
|
|
998
1061
|
return Response.json({ oauth: oauth2 }, { status: 302, headers });
|
|
999
1062
|
},
|
|
1000
1063
|
callbackConfig(oauth)
|
|
@@ -1021,13 +1084,13 @@ var sessionAction = (0, import_router4.createEndpoint)("GET", "/session", async
|
|
|
1021
1084
|
});
|
|
1022
1085
|
|
|
1023
1086
|
// src/actions/signOut/signOut.ts
|
|
1024
|
-
var
|
|
1087
|
+
var import_zod4 = require("zod");
|
|
1025
1088
|
var import_router5 = require("@aura-stack/router");
|
|
1026
1089
|
var config = (0, import_router5.createEndpointConfig)({
|
|
1027
1090
|
schemas: {
|
|
1028
|
-
searchParams:
|
|
1029
|
-
token_type_hint:
|
|
1030
|
-
redirectTo:
|
|
1091
|
+
searchParams: import_zod4.z.object({
|
|
1092
|
+
token_type_hint: import_zod4.z.literal("session_token"),
|
|
1093
|
+
redirectTo: import_zod4.z.string().optional()
|
|
1031
1094
|
})
|
|
1032
1095
|
}
|
|
1033
1096
|
});
|
|
@@ -1126,5 +1189,6 @@ var createAuth = (authConfig) => {
|
|
|
1126
1189
|
};
|
|
1127
1190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1128
1191
|
0 && (module.exports = {
|
|
1129
|
-
createAuth
|
|
1192
|
+
createAuth,
|
|
1193
|
+
createClient
|
|
1130
1194
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { d as AuthConfig, e as
|
|
2
|
-
export {
|
|
3
|
-
import '
|
|
1
|
+
import { d as AuthConfig, e as JoseInstance } from './index-B8jeIElf.js';
|
|
2
|
+
export { f as AuthInstance, C as CookieConfig, E as ErrorType, O as OAuthProvider, g as OAuthProviderConfig, h as OAuthProviderCredentials, S as Session, U as User } from './index-B8jeIElf.js';
|
|
3
|
+
import * as _aura_stack_router from '@aura-stack/router';
|
|
4
|
+
export { createClient } from '@aura-stack/router';
|
|
5
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
6
|
+
import * as zod from 'zod';
|
|
4
7
|
import './schemas.js';
|
|
5
8
|
import '@aura-stack/router/cookie';
|
|
9
|
+
import '@aura-stack/jose';
|
|
6
10
|
import '@aura-stack/jose/jose';
|
|
7
11
|
import './@types/utility.js';
|
|
8
12
|
|
|
@@ -28,6 +32,63 @@ import './@types/utility.js';
|
|
|
28
32
|
* }]
|
|
29
33
|
* })
|
|
30
34
|
*/
|
|
31
|
-
declare const createAuth: (authConfig: AuthConfig) =>
|
|
35
|
+
declare const createAuth: (authConfig: AuthConfig) => {
|
|
36
|
+
handlers: _aura_stack_router.Router<[_aura_stack_router.RouteEndpoint<"GET", "/signIn/:oauth", {
|
|
37
|
+
schemas?: {
|
|
38
|
+
params: zod.ZodObject<{
|
|
39
|
+
oauth: zod.ZodEnum<{
|
|
40
|
+
[x: string & Record<never, never>]: string & Record<never, never>;
|
|
41
|
+
github: "github";
|
|
42
|
+
bitbucket: "bitbucket";
|
|
43
|
+
figma: "figma";
|
|
44
|
+
discord: "discord";
|
|
45
|
+
gitlab: "gitlab";
|
|
46
|
+
spotify: "spotify";
|
|
47
|
+
x: "x";
|
|
48
|
+
strava: "strava";
|
|
49
|
+
mailchimp: "mailchimp";
|
|
50
|
+
pinterest: "pinterest";
|
|
51
|
+
}>;
|
|
52
|
+
}, zod_v4_core.$strip>;
|
|
53
|
+
searchParams: zod.ZodObject<{
|
|
54
|
+
redirectTo: zod.ZodOptional<zod.ZodString>;
|
|
55
|
+
}, zod_v4_core.$strip>;
|
|
56
|
+
} | undefined;
|
|
57
|
+
}>, _aura_stack_router.RouteEndpoint<"GET", "/callback/:oauth", {
|
|
58
|
+
schemas?: {
|
|
59
|
+
params: zod.ZodObject<{
|
|
60
|
+
oauth: zod.ZodEnum<{
|
|
61
|
+
[x: string & Record<never, never>]: string & Record<never, never>;
|
|
62
|
+
github: "github";
|
|
63
|
+
bitbucket: "bitbucket";
|
|
64
|
+
figma: "figma";
|
|
65
|
+
discord: "discord";
|
|
66
|
+
gitlab: "gitlab";
|
|
67
|
+
spotify: "spotify";
|
|
68
|
+
x: "x";
|
|
69
|
+
strava: "strava";
|
|
70
|
+
mailchimp: "mailchimp";
|
|
71
|
+
pinterest: "pinterest";
|
|
72
|
+
}>;
|
|
73
|
+
}, zod_v4_core.$strip>;
|
|
74
|
+
searchParams: zod.ZodObject<{
|
|
75
|
+
code: zod.ZodString;
|
|
76
|
+
state: zod.ZodString;
|
|
77
|
+
}, zod_v4_core.$strip>;
|
|
78
|
+
} | undefined;
|
|
79
|
+
}>, _aura_stack_router.RouteEndpoint<"GET", "/session", {
|
|
80
|
+
schemas?: _aura_stack_router.EndpointSchemas | undefined;
|
|
81
|
+
}>, _aura_stack_router.RouteEndpoint<"POST", "/signOut", {
|
|
82
|
+
schemas?: {
|
|
83
|
+
searchParams: zod.ZodObject<{
|
|
84
|
+
token_type_hint: zod.ZodLiteral<"session_token">;
|
|
85
|
+
redirectTo: zod.ZodOptional<zod.ZodString>;
|
|
86
|
+
}, zod_v4_core.$strip>;
|
|
87
|
+
} | undefined;
|
|
88
|
+
}>, _aura_stack_router.RouteEndpoint<"GET", "/csrfToken", {
|
|
89
|
+
schemas?: _aura_stack_router.EndpointSchemas | undefined;
|
|
90
|
+
}>]>;
|
|
91
|
+
jose: JoseInstance;
|
|
92
|
+
};
|
|
32
93
|
|
|
33
|
-
export { AuthConfig,
|
|
94
|
+
export { AuthConfig, JoseInstance, createAuth };
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createBuiltInOAuthProviders
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EMKJA2GJ.js";
|
|
4
|
+
import "./chunk-42XB3YCW.js";
|
|
5
|
+
import "./chunk-FKRDCWBF.js";
|
|
4
6
|
import "./chunk-IKHPGFCW.js";
|
|
5
7
|
import "./chunk-KRNOMBXQ.js";
|
|
8
|
+
import "./chunk-B737EUJV.js";
|
|
9
|
+
import "./chunk-HP34YGGJ.js";
|
|
6
10
|
import "./chunk-E3OXBRYF.js";
|
|
7
11
|
import "./chunk-6R2YZ4AC.js";
|
|
8
|
-
import "./chunk-42XB3YCW.js";
|
|
9
12
|
import "./chunk-ITQ7352M.js";
|
|
10
|
-
import {
|
|
11
|
-
csrfTokenAction
|
|
12
|
-
} from "./chunk-QDO2KSRJ.js";
|
|
13
13
|
import {
|
|
14
14
|
signInAction
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-3EUWD5BB.js";
|
|
16
|
+
import {
|
|
17
|
+
callbackAction
|
|
18
|
+
} from "./chunk-KSWLO5ZU.js";
|
|
19
|
+
import "./chunk-GA2SMTJO.js";
|
|
20
|
+
import "./chunk-IVET23KF.js";
|
|
16
21
|
import {
|
|
17
22
|
sessionAction
|
|
18
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-JVFTCTTE.js";
|
|
19
24
|
import {
|
|
20
|
-
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import "./chunk-QEZL7EYN.js";
|
|
25
|
+
csrfTokenAction
|
|
26
|
+
} from "./chunk-HT4YLL7N.js";
|
|
23
27
|
import {
|
|
24
|
-
|
|
25
|
-
} from "./chunk-
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-4V4JNXVF.js";
|
|
28
|
+
signOutAction
|
|
29
|
+
} from "./chunk-A3N4PVAT.js";
|
|
30
|
+
import "./chunk-N4SX7TZT.js";
|
|
28
31
|
import "./chunk-FIPU4MLT.js";
|
|
29
32
|
import "./chunk-IUYZQTJV.js";
|
|
30
|
-
import "./chunk-FKRDCWBF.js";
|
|
31
33
|
import {
|
|
32
34
|
createCookieStore
|
|
33
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-W6LG7BFW.js";
|
|
34
36
|
import "./chunk-STHEPPUZ.js";
|
|
35
37
|
import {
|
|
36
38
|
createJoseInstance
|
|
37
39
|
} from "./chunk-TLE4PXY3.js";
|
|
38
|
-
import "./chunk-WD7AUHQ5.js";
|
|
39
40
|
import "./chunk-N2APGLXA.js";
|
|
40
41
|
import {
|
|
41
42
|
onErrorHandler,
|
|
@@ -43,10 +44,12 @@ import {
|
|
|
43
44
|
} from "./chunk-CXLATHS5.js";
|
|
44
45
|
import "./chunk-EIL2FPSS.js";
|
|
45
46
|
import "./chunk-RRLIF4PQ.js";
|
|
47
|
+
import "./chunk-ZNCZVF6U.js";
|
|
48
|
+
import "./chunk-YRCB5FLE.js";
|
|
46
49
|
|
|
47
50
|
// src/index.ts
|
|
48
51
|
import "dotenv/config";
|
|
49
|
-
import { createRouter } from "@aura-stack/router";
|
|
52
|
+
import { createRouter, createClient } from "@aura-stack/router";
|
|
50
53
|
var createInternalConfig = (authConfig) => {
|
|
51
54
|
const useSecure = authConfig?.trustedProxyHeaders ?? false;
|
|
52
55
|
return {
|
|
@@ -82,5 +85,6 @@ var createAuth = (authConfig) => {
|
|
|
82
85
|
};
|
|
83
86
|
};
|
|
84
87
|
export {
|
|
85
|
-
createAuth
|
|
88
|
+
createAuth,
|
|
89
|
+
createClient
|
|
86
90
|
};
|
package/dist/jose.cjs
CHANGED
|
@@ -37,7 +37,7 @@ var import_config = require("dotenv/config");
|
|
|
37
37
|
var import_jose = require("@aura-stack/jose");
|
|
38
38
|
|
|
39
39
|
// src/secure.ts
|
|
40
|
-
var
|
|
40
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
41
41
|
|
|
42
42
|
// src/utils.ts
|
|
43
43
|
var import_router = require("@aura-stack/router");
|
|
@@ -56,7 +56,7 @@ var AuthInternalError = class extends Error {
|
|
|
56
56
|
|
|
57
57
|
// src/secure.ts
|
|
58
58
|
var createDerivedSalt = (secret) => {
|
|
59
|
-
return
|
|
59
|
+
return import_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
// src/jose.ts
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { B as BitbucketProfile,
|
|
1
|
+
export { B as BitbucketProfile, v as bitbucket } from '../index-B8jeIElf.js';
|
|
2
2
|
import '../@types/utility.js';
|
|
3
|
-
import 'zod
|
|
3
|
+
import 'zod';
|
|
4
4
|
import '../schemas.js';
|
|
5
5
|
import '@aura-stack/router/cookie';
|
|
6
|
+
import '@aura-stack/jose';
|
|
6
7
|
import '@aura-stack/jose/jose';
|
package/dist/oauth/discord.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { D as DiscordProfile, N as Nameplate,
|
|
2
|
-
import 'zod
|
|
1
|
+
export { D as DiscordProfile, N as Nameplate, t as discord } from '../index-B8jeIElf.js';
|
|
2
|
+
import 'zod';
|
|
3
3
|
import '../schemas.js';
|
|
4
4
|
import '@aura-stack/router/cookie';
|
|
5
|
+
import '@aura-stack/jose';
|
|
5
6
|
import '@aura-stack/jose/jose';
|
|
6
7
|
import '../@types/utility.js';
|