@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/@types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import 'zod
|
|
1
|
+
import 'zod';
|
|
2
2
|
import '../schemas.js';
|
|
3
3
|
import '@aura-stack/router/cookie';
|
|
4
|
+
import '@aura-stack/jose';
|
|
4
5
|
import '@aura-stack/jose/jose';
|
|
5
|
-
export { i as APIErrorMap,
|
|
6
|
+
export { i as APIErrorMap, a0 as AccessTokenError, d as AuthConfig, f as AuthInstance, b as AuthInternalErrorCode, A as AuthRuntimeConfig, c as AuthSecurityErrorCode, $ as AuthorizationError, C as CookieConfig, Z as CookieName, a as CookieStoreConfig, Y as CookieStrategyAttributes, E as ErrorType, V as HostCookie, J as JWTPayloadWithToken, Q as JWTStandardClaims, e as JoseInstance, a2 as OAuthEnv, _ as OAuthError, O as OAuthProvider, g as OAuthProviderConfig, h as OAuthProviderCredentials, j as OAuthProviderRecord, R as RouterGlobalContext, T as SecureCookie, S as Session, W as StandardCookie, a1 as TokenRevocationError, U as User } from '../index-B8jeIElf.js';
|
|
6
7
|
export { LiteralUnion, Prettify } from './utility.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { R as RouterGlobalContext } from '../index-
|
|
2
|
-
import 'zod
|
|
1
|
+
import { R as RouterGlobalContext } 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 './utility.js';
|
|
7
8
|
|
|
@@ -24,6 +24,17 @@ __export(access_token_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(access_token_exports);
|
|
26
26
|
|
|
27
|
+
// src/request.ts
|
|
28
|
+
var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
31
|
+
const response = await fetch(url, {
|
|
32
|
+
...options2,
|
|
33
|
+
signal: controller.signal
|
|
34
|
+
}).finally(() => clearTimeout(timeoutId));
|
|
35
|
+
return response;
|
|
36
|
+
};
|
|
37
|
+
|
|
27
38
|
// src/utils.ts
|
|
28
39
|
var import_router = require("@aura-stack/router");
|
|
29
40
|
|
|
@@ -69,28 +80,28 @@ var formatZodError = (error) => {
|
|
|
69
80
|
};
|
|
70
81
|
|
|
71
82
|
// src/schemas.ts
|
|
72
|
-
var
|
|
73
|
-
var OAuthProviderConfigSchema = (0,
|
|
74
|
-
authorizeURL: (0,
|
|
75
|
-
accessToken: (0,
|
|
76
|
-
scope: (0,
|
|
77
|
-
userInfo: (0,
|
|
78
|
-
responseType: (0,
|
|
79
|
-
clientId: (0,
|
|
80
|
-
clientSecret: (0,
|
|
83
|
+
var import_zod = require("zod");
|
|
84
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
85
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
86
|
+
accessToken: (0, import_zod.string)().url(),
|
|
87
|
+
scope: (0, import_zod.string)().optional(),
|
|
88
|
+
userInfo: (0, import_zod.string)().url(),
|
|
89
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
90
|
+
clientId: (0, import_zod.string)(),
|
|
91
|
+
clientSecret: (0, import_zod.string)()
|
|
81
92
|
});
|
|
82
93
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
83
|
-
redirectURI: (0,
|
|
84
|
-
state: (0,
|
|
85
|
-
codeChallenge: (0,
|
|
86
|
-
codeChallengeMethod: (0,
|
|
94
|
+
redirectURI: (0, import_zod.string)(),
|
|
95
|
+
state: (0, import_zod.string)(),
|
|
96
|
+
codeChallenge: (0, import_zod.string)(),
|
|
97
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
87
98
|
});
|
|
88
|
-
var OAuthAuthorizationResponse = (0,
|
|
89
|
-
state: (0,
|
|
90
|
-
code: (0,
|
|
99
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
100
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
101
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
91
102
|
});
|
|
92
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
93
|
-
error: (0,
|
|
103
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
104
|
+
error: (0, import_zod.enum)([
|
|
94
105
|
"invalid_request",
|
|
95
106
|
"unauthorized_client",
|
|
96
107
|
"access_denied",
|
|
@@ -99,24 +110,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
|
99
110
|
"server_error",
|
|
100
111
|
"temporarily_unavailable"
|
|
101
112
|
]),
|
|
102
|
-
error_description: (0,
|
|
103
|
-
error_uri: (0,
|
|
104
|
-
state: (0,
|
|
113
|
+
error_description: (0, import_zod.string)().optional(),
|
|
114
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
115
|
+
state: (0, import_zod.string)()
|
|
105
116
|
});
|
|
106
117
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
107
|
-
redirectURI: (0,
|
|
108
|
-
code: (0,
|
|
109
|
-
codeVerifier: (0,
|
|
118
|
+
redirectURI: (0, import_zod.string)(),
|
|
119
|
+
code: (0, import_zod.string)(),
|
|
120
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
110
121
|
});
|
|
111
|
-
var OAuthAccessTokenResponse = (0,
|
|
112
|
-
access_token: (0,
|
|
113
|
-
token_type: (0,
|
|
114
|
-
expires_in: (0,
|
|
115
|
-
refresh_token: (0,
|
|
116
|
-
scope: (0,
|
|
122
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
123
|
+
access_token: (0, import_zod.string)(),
|
|
124
|
+
token_type: (0, import_zod.string)().optional(),
|
|
125
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
126
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
127
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
117
128
|
});
|
|
118
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
119
|
-
error: (0,
|
|
129
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
130
|
+
error: (0, import_zod.enum)([
|
|
120
131
|
"invalid_request",
|
|
121
132
|
"invalid_client",
|
|
122
133
|
"invalid_grant",
|
|
@@ -124,16 +135,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
|
124
135
|
"unsupported_grant_type",
|
|
125
136
|
"invalid_scope"
|
|
126
137
|
]),
|
|
127
|
-
error_description: (0,
|
|
128
|
-
error_uri: (0,
|
|
138
|
+
error_description: (0, import_zod.string)().optional(),
|
|
139
|
+
error_uri: (0, import_zod.string)().optional()
|
|
129
140
|
});
|
|
130
|
-
var OAuthErrorResponse = (0,
|
|
131
|
-
error: (0,
|
|
132
|
-
error_description: (0,
|
|
141
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
142
|
+
error: (0, import_zod.string)(),
|
|
143
|
+
error_description: (0, import_zod.string)().optional()
|
|
133
144
|
});
|
|
134
|
-
var OAuthEnvSchema = (0,
|
|
135
|
-
clientId:
|
|
136
|
-
clientSecret:
|
|
145
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
146
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
147
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
137
148
|
});
|
|
138
149
|
|
|
139
150
|
// src/actions/callback/access-token.ts
|
|
@@ -145,7 +156,7 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
|
|
|
145
156
|
}
|
|
146
157
|
const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
|
|
147
158
|
try {
|
|
148
|
-
const response = await
|
|
159
|
+
const response = await fetchAsync(accessToken, {
|
|
149
160
|
method: "POST",
|
|
150
161
|
headers: {
|
|
151
162
|
Accept: "application/json",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { h as OAuthProviderCredentials } from '../../index-
|
|
2
|
-
import 'zod
|
|
1
|
+
import { h as OAuthProviderCredentials } 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';
|
|
7
8
|
|
|
@@ -18,10 +19,10 @@ import '../../@types/utility.js';
|
|
|
18
19
|
*/
|
|
19
20
|
declare const createAccessToken: (oauthConfig: OAuthProviderCredentials, redirectURI: string, code: string, codeVerifier: string) => Promise<{
|
|
20
21
|
access_token: string;
|
|
21
|
-
token_type
|
|
22
|
+
token_type?: string | undefined;
|
|
22
23
|
expires_in?: number | undefined;
|
|
23
24
|
refresh_token?: string | undefined;
|
|
24
|
-
scope?: string | undefined;
|
|
25
|
+
scope?: string | null | undefined;
|
|
25
26
|
}>;
|
|
26
27
|
|
|
27
28
|
export { createAccessToken };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAccessToken
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-WD7AUHQ5.js";
|
|
3
|
+
} from "../../chunk-GA2SMTJO.js";
|
|
5
4
|
import "../../chunk-CXLATHS5.js";
|
|
6
5
|
import "../../chunk-RRLIF4PQ.js";
|
|
6
|
+
import "../../chunk-ZNCZVF6U.js";
|
|
7
|
+
import "../../chunk-YRCB5FLE.js";
|
|
7
8
|
export {
|
|
8
9
|
createAccessToken
|
|
9
10
|
};
|
|
@@ -33,11 +33,11 @@ __export(callback_exports, {
|
|
|
33
33
|
callbackAction: () => callbackAction
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(callback_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_zod2 = require("zod");
|
|
37
37
|
var import_router2 = require("@aura-stack/router");
|
|
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");
|
|
@@ -146,7 +146,7 @@ var formatZodError = (error) => {
|
|
|
146
146
|
|
|
147
147
|
// src/secure.ts
|
|
148
148
|
var generateSecure = (length = 32) => {
|
|
149
|
-
return
|
|
149
|
+
return import_crypto.default.randomBytes(length).toString("base64url");
|
|
150
150
|
};
|
|
151
151
|
var createCSRF = async (jose, csrfCookie) => {
|
|
152
152
|
try {
|
|
@@ -170,29 +170,40 @@ var cacheControl = {
|
|
|
170
170
|
Vary: "Cookie"
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
+
// src/request.ts
|
|
174
|
+
var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
|
|
175
|
+
const controller = new AbortController();
|
|
176
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
177
|
+
const response = await fetch(url, {
|
|
178
|
+
...options2,
|
|
179
|
+
signal: controller.signal
|
|
180
|
+
}).finally(() => clearTimeout(timeoutId));
|
|
181
|
+
return response;
|
|
182
|
+
};
|
|
183
|
+
|
|
173
184
|
// src/schemas.ts
|
|
174
|
-
var
|
|
175
|
-
var OAuthProviderConfigSchema = (0,
|
|
176
|
-
authorizeURL: (0,
|
|
177
|
-
accessToken: (0,
|
|
178
|
-
scope: (0,
|
|
179
|
-
userInfo: (0,
|
|
180
|
-
responseType: (0,
|
|
181
|
-
clientId: (0,
|
|
182
|
-
clientSecret: (0,
|
|
185
|
+
var import_zod = require("zod");
|
|
186
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
187
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
188
|
+
accessToken: (0, import_zod.string)().url(),
|
|
189
|
+
scope: (0, import_zod.string)().optional(),
|
|
190
|
+
userInfo: (0, import_zod.string)().url(),
|
|
191
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
192
|
+
clientId: (0, import_zod.string)(),
|
|
193
|
+
clientSecret: (0, import_zod.string)()
|
|
183
194
|
});
|
|
184
195
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
185
|
-
redirectURI: (0,
|
|
186
|
-
state: (0,
|
|
187
|
-
codeChallenge: (0,
|
|
188
|
-
codeChallengeMethod: (0,
|
|
196
|
+
redirectURI: (0, import_zod.string)(),
|
|
197
|
+
state: (0, import_zod.string)(),
|
|
198
|
+
codeChallenge: (0, import_zod.string)(),
|
|
199
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
189
200
|
});
|
|
190
|
-
var OAuthAuthorizationResponse = (0,
|
|
191
|
-
state: (0,
|
|
192
|
-
code: (0,
|
|
201
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
202
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
203
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
193
204
|
});
|
|
194
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
195
|
-
error: (0,
|
|
205
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
206
|
+
error: (0, import_zod.enum)([
|
|
196
207
|
"invalid_request",
|
|
197
208
|
"unauthorized_client",
|
|
198
209
|
"access_denied",
|
|
@@ -201,24 +212,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
|
201
212
|
"server_error",
|
|
202
213
|
"temporarily_unavailable"
|
|
203
214
|
]),
|
|
204
|
-
error_description: (0,
|
|
205
|
-
error_uri: (0,
|
|
206
|
-
state: (0,
|
|
215
|
+
error_description: (0, import_zod.string)().optional(),
|
|
216
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
217
|
+
state: (0, import_zod.string)()
|
|
207
218
|
});
|
|
208
219
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
209
|
-
redirectURI: (0,
|
|
210
|
-
code: (0,
|
|
211
|
-
codeVerifier: (0,
|
|
220
|
+
redirectURI: (0, import_zod.string)(),
|
|
221
|
+
code: (0, import_zod.string)(),
|
|
222
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
212
223
|
});
|
|
213
|
-
var OAuthAccessTokenResponse = (0,
|
|
214
|
-
access_token: (0,
|
|
215
|
-
token_type: (0,
|
|
216
|
-
expires_in: (0,
|
|
217
|
-
refresh_token: (0,
|
|
218
|
-
scope: (0,
|
|
224
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
225
|
+
access_token: (0, import_zod.string)(),
|
|
226
|
+
token_type: (0, import_zod.string)().optional(),
|
|
227
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
228
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
229
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
219
230
|
});
|
|
220
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
221
|
-
error: (0,
|
|
231
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
232
|
+
error: (0, import_zod.enum)([
|
|
222
233
|
"invalid_request",
|
|
223
234
|
"invalid_client",
|
|
224
235
|
"invalid_grant",
|
|
@@ -226,16 +237,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
|
226
237
|
"unsupported_grant_type",
|
|
227
238
|
"invalid_scope"
|
|
228
239
|
]),
|
|
229
|
-
error_description: (0,
|
|
230
|
-
error_uri: (0,
|
|
240
|
+
error_description: (0, import_zod.string)().optional(),
|
|
241
|
+
error_uri: (0, import_zod.string)().optional()
|
|
231
242
|
});
|
|
232
|
-
var OAuthErrorResponse = (0,
|
|
233
|
-
error: (0,
|
|
234
|
-
error_description: (0,
|
|
243
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
244
|
+
error: (0, import_zod.string)(),
|
|
245
|
+
error_description: (0, import_zod.string)().optional()
|
|
235
246
|
});
|
|
236
|
-
var OAuthEnvSchema = (0,
|
|
237
|
-
clientId:
|
|
238
|
-
clientSecret:
|
|
247
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
248
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
249
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
239
250
|
});
|
|
240
251
|
|
|
241
252
|
// src/actions/callback/userinfo.ts
|
|
@@ -251,7 +262,7 @@ var getDefaultUserInfo = (profile) => {
|
|
|
251
262
|
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
252
263
|
const userinfoEndpoint = oauthConfig.userInfo;
|
|
253
264
|
try {
|
|
254
|
-
const response = await
|
|
265
|
+
const response = await fetchAsync(userinfoEndpoint, {
|
|
255
266
|
method: "GET",
|
|
256
267
|
headers: {
|
|
257
268
|
Accept: "application/json",
|
|
@@ -287,7 +298,7 @@ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) =>
|
|
|
287
298
|
}
|
|
288
299
|
const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
|
|
289
300
|
try {
|
|
290
|
-
const response = await
|
|
301
|
+
const response = await fetchAsync(accessToken, {
|
|
291
302
|
method: "POST",
|
|
292
303
|
headers: {
|
|
293
304
|
Accept: "application/json",
|
|
@@ -360,9 +371,15 @@ var createSessionCookie = async (jose, session) => {
|
|
|
360
371
|
var callbackConfig = (oauth) => {
|
|
361
372
|
return (0, import_router2.createEndpointConfig)("/callback/:oauth", {
|
|
362
373
|
schemas: {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
374
|
+
params: import_zod2.z.object({
|
|
375
|
+
oauth: import_zod2.z.enum(
|
|
376
|
+
Object.keys(oauth),
|
|
377
|
+
"The OAuth provider is not supported or invalid."
|
|
378
|
+
)
|
|
379
|
+
}),
|
|
380
|
+
searchParams: import_zod2.z.object({
|
|
381
|
+
code: import_zod2.z.string("Missing code parameter in the OAuth authorization response."),
|
|
382
|
+
state: import_zod2.z.string("Missing state parameter in the OAuth authorization response.")
|
|
366
383
|
})
|
|
367
384
|
},
|
|
368
385
|
middlewares: [
|
|
@@ -390,9 +407,9 @@ var callbackAction = (oauth) => {
|
|
|
390
407
|
} = ctx;
|
|
391
408
|
const oauthConfig = providers[oauth2];
|
|
392
409
|
const cookieState = getCookie(request, cookies.state.name);
|
|
393
|
-
const cookieRedirectTo = getCookie(request, cookies.
|
|
394
|
-
const cookieRedirectURI = getCookie(request, cookies.
|
|
395
|
-
const codeVerifier = getCookie(request, cookies.
|
|
410
|
+
const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
|
|
411
|
+
const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
|
|
412
|
+
const codeVerifier = getCookie(request, cookies.codeVerifier.name);
|
|
396
413
|
if (!equals(cookieState, state)) {
|
|
397
414
|
throw new AuthSecurityError(
|
|
398
415
|
"MISMATCHING_STATE",
|
|
@@ -410,7 +427,7 @@ var callbackAction = (oauth) => {
|
|
|
410
427
|
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
411
428
|
const sessionCookie = await createSessionCookie(jose, userInfo);
|
|
412
429
|
const csrfToken = await createCSRF(jose);
|
|
413
|
-
const headers = new import_router2.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.
|
|
430
|
+
const headers = new import_router2.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();
|
|
414
431
|
return Response.json({ oauth: oauth2 }, { status: 302, headers });
|
|
415
432
|
},
|
|
416
433
|
callbackConfig(oauth)
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import * as _aura_stack_router from '@aura-stack/router';
|
|
2
|
-
import {
|
|
3
|
-
import '
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { j as OAuthProviderRecord } from '../../index-B8jeIElf.js';
|
|
4
4
|
import '../../schemas.js';
|
|
5
5
|
import '@aura-stack/router/cookie';
|
|
6
|
+
import '@aura-stack/jose';
|
|
6
7
|
import '@aura-stack/jose/jose';
|
|
7
8
|
import '../../@types/utility.js';
|
|
8
9
|
|
|
9
|
-
declare const callbackAction: (oauth:
|
|
10
|
+
declare const callbackAction: (oauth: OAuthProviderRecord) => _aura_stack_router.RouteEndpoint<"GET", "/callback/:oauth", {
|
|
11
|
+
schemas?: {
|
|
12
|
+
params: z.ZodObject<{
|
|
13
|
+
oauth: z.ZodEnum<{
|
|
14
|
+
[x: string & Record<never, never>]: string & Record<never, never>;
|
|
15
|
+
github: "github";
|
|
16
|
+
bitbucket: "bitbucket";
|
|
17
|
+
figma: "figma";
|
|
18
|
+
discord: "discord";
|
|
19
|
+
gitlab: "gitlab";
|
|
20
|
+
spotify: "spotify";
|
|
21
|
+
x: "x";
|
|
22
|
+
strava: "strava";
|
|
23
|
+
mailchimp: "mailchimp";
|
|
24
|
+
pinterest: "pinterest";
|
|
25
|
+
}>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
searchParams: z.ZodObject<{
|
|
28
|
+
code: z.ZodString;
|
|
29
|
+
state: z.ZodString;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
} | undefined;
|
|
32
|
+
}>;
|
|
10
33
|
|
|
11
34
|
export { callbackAction };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callbackAction
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
5
|
-
import "../../chunk-
|
|
6
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-KSWLO5ZU.js";
|
|
4
|
+
import "../../chunk-GA2SMTJO.js";
|
|
5
|
+
import "../../chunk-IVET23KF.js";
|
|
6
|
+
import "../../chunk-W6LG7BFW.js";
|
|
7
7
|
import "../../chunk-STHEPPUZ.js";
|
|
8
|
-
import "../../chunk-WD7AUHQ5.js";
|
|
9
8
|
import "../../chunk-N2APGLXA.js";
|
|
10
9
|
import "../../chunk-CXLATHS5.js";
|
|
11
10
|
import "../../chunk-EIL2FPSS.js";
|
|
12
11
|
import "../../chunk-RRLIF4PQ.js";
|
|
12
|
+
import "../../chunk-ZNCZVF6U.js";
|
|
13
|
+
import "../../chunk-YRCB5FLE.js";
|
|
13
14
|
export {
|
|
14
15
|
callbackAction
|
|
15
16
|
};
|
|
@@ -34,8 +34,19 @@ __export(userinfo_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(userinfo_exports);
|
|
36
36
|
|
|
37
|
+
// src/request.ts
|
|
38
|
+
var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
...options2,
|
|
43
|
+
signal: controller.signal
|
|
44
|
+
}).finally(() => clearTimeout(timeoutId));
|
|
45
|
+
return response;
|
|
46
|
+
};
|
|
47
|
+
|
|
37
48
|
// src/secure.ts
|
|
38
|
-
var
|
|
49
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
39
50
|
|
|
40
51
|
// src/utils.ts
|
|
41
52
|
var import_router = require("@aura-stack/router");
|
|
@@ -62,32 +73,32 @@ var isOAuthProtocolError = (error) => {
|
|
|
62
73
|
|
|
63
74
|
// src/secure.ts
|
|
64
75
|
var generateSecure = (length = 32) => {
|
|
65
|
-
return
|
|
76
|
+
return import_crypto.default.randomBytes(length).toString("base64url");
|
|
66
77
|
};
|
|
67
78
|
|
|
68
79
|
// src/schemas.ts
|
|
69
|
-
var
|
|
70
|
-
var OAuthProviderConfigSchema = (0,
|
|
71
|
-
authorizeURL: (0,
|
|
72
|
-
accessToken: (0,
|
|
73
|
-
scope: (0,
|
|
74
|
-
userInfo: (0,
|
|
75
|
-
responseType: (0,
|
|
76
|
-
clientId: (0,
|
|
77
|
-
clientSecret: (0,
|
|
80
|
+
var import_zod = require("zod");
|
|
81
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
82
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
83
|
+
accessToken: (0, import_zod.string)().url(),
|
|
84
|
+
scope: (0, import_zod.string)().optional(),
|
|
85
|
+
userInfo: (0, import_zod.string)().url(),
|
|
86
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
87
|
+
clientId: (0, import_zod.string)(),
|
|
88
|
+
clientSecret: (0, import_zod.string)()
|
|
78
89
|
});
|
|
79
90
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
80
|
-
redirectURI: (0,
|
|
81
|
-
state: (0,
|
|
82
|
-
codeChallenge: (0,
|
|
83
|
-
codeChallengeMethod: (0,
|
|
91
|
+
redirectURI: (0, import_zod.string)(),
|
|
92
|
+
state: (0, import_zod.string)(),
|
|
93
|
+
codeChallenge: (0, import_zod.string)(),
|
|
94
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
84
95
|
});
|
|
85
|
-
var OAuthAuthorizationResponse = (0,
|
|
86
|
-
state: (0,
|
|
87
|
-
code: (0,
|
|
96
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
97
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
98
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
88
99
|
});
|
|
89
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
90
|
-
error: (0,
|
|
100
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
101
|
+
error: (0, import_zod.enum)([
|
|
91
102
|
"invalid_request",
|
|
92
103
|
"unauthorized_client",
|
|
93
104
|
"access_denied",
|
|
@@ -96,24 +107,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
|
96
107
|
"server_error",
|
|
97
108
|
"temporarily_unavailable"
|
|
98
109
|
]),
|
|
99
|
-
error_description: (0,
|
|
100
|
-
error_uri: (0,
|
|
101
|
-
state: (0,
|
|
110
|
+
error_description: (0, import_zod.string)().optional(),
|
|
111
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
112
|
+
state: (0, import_zod.string)()
|
|
102
113
|
});
|
|
103
114
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
104
|
-
redirectURI: (0,
|
|
105
|
-
code: (0,
|
|
106
|
-
codeVerifier: (0,
|
|
115
|
+
redirectURI: (0, import_zod.string)(),
|
|
116
|
+
code: (0, import_zod.string)(),
|
|
117
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
107
118
|
});
|
|
108
|
-
var OAuthAccessTokenResponse = (0,
|
|
109
|
-
access_token: (0,
|
|
110
|
-
token_type: (0,
|
|
111
|
-
expires_in: (0,
|
|
112
|
-
refresh_token: (0,
|
|
113
|
-
scope: (0,
|
|
119
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
120
|
+
access_token: (0, import_zod.string)(),
|
|
121
|
+
token_type: (0, import_zod.string)().optional(),
|
|
122
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
123
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
124
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
114
125
|
});
|
|
115
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
116
|
-
error: (0,
|
|
126
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
127
|
+
error: (0, import_zod.enum)([
|
|
117
128
|
"invalid_request",
|
|
118
129
|
"invalid_client",
|
|
119
130
|
"invalid_grant",
|
|
@@ -121,16 +132,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
|
121
132
|
"unsupported_grant_type",
|
|
122
133
|
"invalid_scope"
|
|
123
134
|
]),
|
|
124
|
-
error_description: (0,
|
|
125
|
-
error_uri: (0,
|
|
135
|
+
error_description: (0, import_zod.string)().optional(),
|
|
136
|
+
error_uri: (0, import_zod.string)().optional()
|
|
126
137
|
});
|
|
127
|
-
var OAuthErrorResponse = (0,
|
|
128
|
-
error: (0,
|
|
129
|
-
error_description: (0,
|
|
138
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
139
|
+
error: (0, import_zod.string)(),
|
|
140
|
+
error_description: (0, import_zod.string)().optional()
|
|
130
141
|
});
|
|
131
|
-
var OAuthEnvSchema = (0,
|
|
132
|
-
clientId:
|
|
133
|
-
clientSecret:
|
|
142
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
143
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
144
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
134
145
|
});
|
|
135
146
|
|
|
136
147
|
// src/actions/callback/userinfo.ts
|
|
@@ -146,7 +157,7 @@ var getDefaultUserInfo = (profile) => {
|
|
|
146
157
|
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
147
158
|
const userinfoEndpoint = oauthConfig.userInfo;
|
|
148
159
|
try {
|
|
149
|
-
const response = await
|
|
160
|
+
const response = await fetchAsync(userinfoEndpoint, {
|
|
150
161
|
method: "GET",
|
|
151
162
|
headers: {
|
|
152
163
|
Accept: "application/json",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { h as OAuthProviderCredentials, U as User } from '../../index-
|
|
2
|
-
import 'zod
|
|
1
|
+
import { h as OAuthProviderCredentials, U as User } 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';
|
|
7
8
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getUserInfo
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-WD7AUHQ5.js";
|
|
3
|
+
} from "../../chunk-IVET23KF.js";
|
|
5
4
|
import "../../chunk-N2APGLXA.js";
|
|
6
5
|
import "../../chunk-CXLATHS5.js";
|
|
7
6
|
import "../../chunk-EIL2FPSS.js";
|
|
8
7
|
import "../../chunk-RRLIF4PQ.js";
|
|
8
|
+
import "../../chunk-ZNCZVF6U.js";
|
|
9
|
+
import "../../chunk-YRCB5FLE.js";
|
|
9
10
|
export {
|
|
10
11
|
getUserInfo
|
|
11
12
|
};
|