@better-auth/oauth-provider 1.6.8 → 1.6.10
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/client-resource.d.mts +1 -1
- package/dist/client-resource.mjs +2 -2
- package/dist/client.d.mts +1 -1
- package/dist/client.mjs +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +70 -29
- package/dist/{oauth-DMjvJjmR.d.mts → oauth-CqgT-XaR.d.mts} +12 -2
- package/dist/{oauth-By0LyEmY.d.mts → oauth-DBCeGXT3.d.mts} +13 -1
- package/dist/{utils-B9Pj9EPf.mjs → utils-LAthGy-x.mjs} +15 -11
- package/dist/{version-DJz94mwS.mjs → version-Cg-c01N0.mjs} +1 -1
- package/package.json +5 -5
package/dist/client-resource.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { S as handleMcpErrors, a as getOAuthProviderPlugin, i as getJwtPlugin } from "./utils-LAthGy-x.mjs";
|
|
2
|
+
import { t as PACKAGE_VERSION } from "./version-Cg-c01N0.mjs";
|
|
3
3
|
import { verifyAccessToken } from "better-auth/oauth2";
|
|
4
4
|
import { APIError } from "better-call";
|
|
5
5
|
import { logger } from "@better-auth/core/env";
|
package/dist/client.d.mts
CHANGED
package/dist/client.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
import { n as oauthProvider, t as getOAuthProviderState } from "./oauth-
|
|
1
|
+
import { _ as Scope, a as OAuthClient, b as Awaitable, c as TokenEndpointAuthMethod, d as OAuthConsent, f as OAuthOpaqueAccessToken, g as SchemaClient, h as Prompt, i as GrantType, l as AuthorizePrompt, m as OAuthRefreshToken, n as AuthServerMetadata, o as OIDCMetadata, p as OAuthOptions, r as BearerMethodsSupported, s as ResourceServerMetadata, t as AuthMethod, u as OAuthAuthorizationQuery, v as StoreTokenType, y as VerificationValue } from "./oauth-CqgT-XaR.mjs";
|
|
2
|
+
import { n as oauthProvider, t as getOAuthProviderState } from "./oauth-DBCeGXT3.mjs";
|
|
3
3
|
import { verifyAccessToken } from "better-auth/oauth2";
|
|
4
4
|
import { JWSAlgorithms, JwtOptions } from "better-auth/plugins";
|
|
5
5
|
import { JWTPayload } from "jose";
|
|
@@ -61,4 +61,4 @@ declare const oauthProviderOpenIdConfigMetadata: <Auth extends {
|
|
|
61
61
|
headers?: HeadersInit;
|
|
62
62
|
}) => (request: Request) => Promise<Response>;
|
|
63
63
|
//#endregion
|
|
64
|
-
export { AuthServerMetadata, AuthorizePrompt, OAuthAuthorizationQuery, OAuthClient, OAuthConsent, OAuthOpaqueAccessToken, OAuthOptions, OAuthRefreshToken, OIDCMetadata, Prompt, ResourceServerMetadata, SchemaClient, Scope, StoreTokenType, VerificationValue, authServerMetadata, getOAuthProviderState, mcpHandler, oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata, oidcServerMetadata };
|
|
64
|
+
export { AuthMethod, AuthServerMetadata, AuthorizePrompt, BearerMethodsSupported, GrantType, OAuthAuthorizationQuery, OAuthClient, OAuthConsent, OAuthOpaqueAccessToken, OAuthOptions, OAuthRefreshToken, OIDCMetadata, Prompt, ResourceServerMetadata, SchemaClient, Scope, StoreTokenType, TokenEndpointAuthMethod, VerificationValue, authServerMetadata, getOAuthProviderState, mcpHandler, oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata, oidcServerMetadata };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { C as mcpHandler, _ as signedQueryIssuedAtParam, b as validateClientCredentials, c as isPKCERequired, d as parsePrompt, f as postLoginClearedParam, g as searchParamsToQuery, h as resolveSubjectIdentifier, i as getJwtPlugin, l as normalizeTimestampValue, m as resolveSessionAuthTime, n as decryptStoredClientSecret, o as getSignedQueryIssuedAt, p as removePromptFromQuery, r as getClient, s as getStoredToken, t as basicToClientCredentials, u as parseClientMetadata, v as storeClientSecret, x as verifyOAuthQueryParams, y as storeToken } from "./utils-LAthGy-x.mjs";
|
|
2
|
+
import { t as PACKAGE_VERSION } from "./version-Cg-c01N0.mjs";
|
|
3
3
|
import { APIError, createAuthEndpoint, createAuthMiddleware, getOAuthState, getSessionFromCtx, sessionMiddleware } from "better-auth/api";
|
|
4
4
|
import { generateCodeChallenge, getJwks, verifyJwsAccessToken } from "better-auth/oauth2";
|
|
5
5
|
import { APIError as APIError$1 } from "better-call";
|
|
@@ -16,7 +16,8 @@ import { signJWT, toExpJWT } from "better-auth/plugins";
|
|
|
16
16
|
import { SignJWT, compactVerify, createLocalJWKSet, decodeJwt } from "jose";
|
|
17
17
|
//#region src/consent.ts
|
|
18
18
|
async function consentEndpoint(ctx, opts) {
|
|
19
|
-
const
|
|
19
|
+
const oauthRequest = await oAuthState.get();
|
|
20
|
+
const _query = oauthRequest?.query;
|
|
20
21
|
if (!_query) throw new APIError("BAD_REQUEST", {
|
|
21
22
|
error_description: "missing oauth query",
|
|
22
23
|
error: "invalid_request"
|
|
@@ -40,6 +41,17 @@ async function consentEndpoint(ctx, opts) {
|
|
|
40
41
|
url: formatErrorURL(query.get("redirect_uri") ?? "", "access_denied", "User denied access", query.get("state") ?? void 0, getIssuer(ctx, opts))
|
|
41
42
|
};
|
|
42
43
|
const session = await getSessionFromCtx(ctx);
|
|
44
|
+
const hasLoginPrompt = parsePrompt(query.get("prompt") ?? "").has("login");
|
|
45
|
+
const hasSatisfiedLoginPrompt = hasLoginPrompt && sessionSatisfiesLoginPrompt(session?.session.createdAt, oauthRequest?.signedQueryIssuedAt);
|
|
46
|
+
if (hasLoginPrompt && !hasSatisfiedLoginPrompt) {
|
|
47
|
+
ctx?.headers?.set("accept", "application/json");
|
|
48
|
+
ctx.query = searchParamsToQuery(query);
|
|
49
|
+
const { url } = await authorizeEndpoint(ctx, opts);
|
|
50
|
+
return {
|
|
51
|
+
redirect: true,
|
|
52
|
+
url
|
|
53
|
+
};
|
|
54
|
+
}
|
|
43
55
|
const referenceId = await opts.postLogin?.consentReferenceId?.({
|
|
44
56
|
user: session?.user,
|
|
45
57
|
session: session?.session,
|
|
@@ -90,14 +102,21 @@ async function consentEndpoint(ctx, opts) {
|
|
|
90
102
|
});
|
|
91
103
|
if (requestedScopes) query.set("scope", consent.scopes.join(" "));
|
|
92
104
|
ctx?.headers?.set("accept", "application/json");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
let authorizationQuery = removePromptFromQuery(query, "consent");
|
|
106
|
+
if (hasSatisfiedLoginPrompt) authorizationQuery = removePromptFromQuery(authorizationQuery, "login");
|
|
107
|
+
ctx.query = searchParamsToQuery(authorizationQuery);
|
|
108
|
+
const { url } = await authorizeEndpoint(ctx, opts, { postLogin: oauthRequest?.postLoginClearedForSession !== void 0 && oauthRequest.postLoginClearedForSession === session?.session.id });
|
|
96
109
|
return {
|
|
97
110
|
redirect: true,
|
|
98
111
|
url
|
|
99
112
|
};
|
|
100
113
|
}
|
|
114
|
+
function sessionSatisfiesLoginPrompt(sessionCreatedAt, signedQueryIssuedAt) {
|
|
115
|
+
if (!signedQueryIssuedAt) return false;
|
|
116
|
+
const normalized = normalizeTimestampValue(sessionCreatedAt);
|
|
117
|
+
if (!normalized) return false;
|
|
118
|
+
return normalized.getTime() >= signedQueryIssuedAt.getTime();
|
|
119
|
+
}
|
|
101
120
|
//#endregion
|
|
102
121
|
//#region src/continue.ts
|
|
103
122
|
async function continueEndpoint(ctx, opts) {
|
|
@@ -116,7 +135,7 @@ async function selected(ctx, opts) {
|
|
|
116
135
|
error: "invalid_request"
|
|
117
136
|
});
|
|
118
137
|
ctx.headers?.set("accept", "application/json");
|
|
119
|
-
ctx.query =
|
|
138
|
+
ctx.query = searchParamsToQuery(removePromptFromQuery(new URLSearchParams(_query), "select_account"));
|
|
120
139
|
const { url } = await authorizeEndpoint(ctx, opts);
|
|
121
140
|
return {
|
|
122
141
|
redirect: true,
|
|
@@ -131,7 +150,7 @@ async function created(ctx, opts) {
|
|
|
131
150
|
});
|
|
132
151
|
const query = new URLSearchParams(_query);
|
|
133
152
|
ctx.headers?.set("accept", "application/json");
|
|
134
|
-
ctx.query =
|
|
153
|
+
ctx.query = searchParamsToQuery(removePromptFromQuery(query, "create"));
|
|
135
154
|
const { url } = await authorizeEndpoint(ctx, opts);
|
|
136
155
|
return {
|
|
137
156
|
redirect: true,
|
|
@@ -936,7 +955,7 @@ async function validateRefreshToken(ctx, opts, token, clientId) {
|
|
|
936
955
|
model: "session",
|
|
937
956
|
where: [{
|
|
938
957
|
field: "id",
|
|
939
|
-
value:
|
|
958
|
+
value: sessionId
|
|
940
959
|
}]
|
|
941
960
|
});
|
|
942
961
|
if (!session || session.expiresAt < /* @__PURE__ */ new Date()) sessionId = void 0;
|
|
@@ -2458,7 +2477,8 @@ const schema = {
|
|
|
2458
2477
|
references: {
|
|
2459
2478
|
model: "user",
|
|
2460
2479
|
field: "id"
|
|
2461
|
-
}
|
|
2480
|
+
},
|
|
2481
|
+
index: true
|
|
2462
2482
|
},
|
|
2463
2483
|
createdAt: {
|
|
2464
2484
|
type: "date",
|
|
@@ -2557,7 +2577,8 @@ const schema = {
|
|
|
2557
2577
|
references: {
|
|
2558
2578
|
model: "oauthClient",
|
|
2559
2579
|
field: "clientId"
|
|
2560
|
-
}
|
|
2580
|
+
},
|
|
2581
|
+
index: true
|
|
2561
2582
|
},
|
|
2562
2583
|
sessionId: {
|
|
2563
2584
|
type: "string",
|
|
@@ -2566,7 +2587,8 @@ const schema = {
|
|
|
2566
2587
|
model: "session",
|
|
2567
2588
|
field: "id",
|
|
2568
2589
|
onDelete: "set null"
|
|
2569
|
-
}
|
|
2590
|
+
},
|
|
2591
|
+
index: true
|
|
2570
2592
|
},
|
|
2571
2593
|
userId: {
|
|
2572
2594
|
type: "string",
|
|
@@ -2574,7 +2596,8 @@ const schema = {
|
|
|
2574
2596
|
references: {
|
|
2575
2597
|
model: "user",
|
|
2576
2598
|
field: "id"
|
|
2577
|
-
}
|
|
2599
|
+
},
|
|
2600
|
+
index: true
|
|
2578
2601
|
},
|
|
2579
2602
|
referenceId: {
|
|
2580
2603
|
type: "string",
|
|
@@ -2608,7 +2631,8 @@ const schema = {
|
|
|
2608
2631
|
references: {
|
|
2609
2632
|
model: "oauthClient",
|
|
2610
2633
|
field: "clientId"
|
|
2611
|
-
}
|
|
2634
|
+
},
|
|
2635
|
+
index: true
|
|
2612
2636
|
},
|
|
2613
2637
|
sessionId: {
|
|
2614
2638
|
type: "string",
|
|
@@ -2617,7 +2641,8 @@ const schema = {
|
|
|
2617
2641
|
model: "session",
|
|
2618
2642
|
field: "id",
|
|
2619
2643
|
onDelete: "set null"
|
|
2620
|
-
}
|
|
2644
|
+
},
|
|
2645
|
+
index: true
|
|
2621
2646
|
},
|
|
2622
2647
|
userId: {
|
|
2623
2648
|
type: "string",
|
|
@@ -2625,7 +2650,8 @@ const schema = {
|
|
|
2625
2650
|
references: {
|
|
2626
2651
|
model: "user",
|
|
2627
2652
|
field: "id"
|
|
2628
|
-
}
|
|
2653
|
+
},
|
|
2654
|
+
index: true
|
|
2629
2655
|
},
|
|
2630
2656
|
referenceId: {
|
|
2631
2657
|
type: "string",
|
|
@@ -2637,7 +2663,8 @@ const schema = {
|
|
|
2637
2663
|
references: {
|
|
2638
2664
|
model: "oauthRefreshToken",
|
|
2639
2665
|
field: "id"
|
|
2640
|
-
}
|
|
2666
|
+
},
|
|
2667
|
+
index: true
|
|
2641
2668
|
},
|
|
2642
2669
|
expiresAt: { type: "date" },
|
|
2643
2670
|
createdAt: { type: "date" },
|
|
@@ -2656,7 +2683,8 @@ const schema = {
|
|
|
2656
2683
|
references: {
|
|
2657
2684
|
model: "oauthClient",
|
|
2658
2685
|
field: "clientId"
|
|
2659
|
-
}
|
|
2686
|
+
},
|
|
2687
|
+
index: true
|
|
2660
2688
|
},
|
|
2661
2689
|
userId: {
|
|
2662
2690
|
type: "string",
|
|
@@ -2664,7 +2692,8 @@ const schema = {
|
|
|
2664
2692
|
references: {
|
|
2665
2693
|
model: "user",
|
|
2666
2694
|
field: "id"
|
|
2667
|
-
}
|
|
2695
|
+
},
|
|
2696
|
+
index: true
|
|
2668
2697
|
},
|
|
2669
2698
|
referenceId: {
|
|
2670
2699
|
type: "string",
|
|
@@ -2776,10 +2805,18 @@ const oauthProvider = (options) => {
|
|
|
2776
2805
|
handler: createAuthMiddleware(async (ctx) => {
|
|
2777
2806
|
const query = ctx.body.oauth_query;
|
|
2778
2807
|
if (!await verifyOAuthQueryParams(query, ctx.context.secret)) throw new APIError("BAD_REQUEST", { error: "invalid_signature" });
|
|
2808
|
+
const signedQueryIssuedAt = getSignedQueryIssuedAt(query);
|
|
2779
2809
|
const queryParams = new URLSearchParams(query);
|
|
2810
|
+
const postLoginClearedForSession = queryParams.get("ba_pl") ?? void 0;
|
|
2780
2811
|
queryParams.delete("sig");
|
|
2781
2812
|
queryParams.delete("exp");
|
|
2782
|
-
|
|
2813
|
+
queryParams.delete(signedQueryIssuedAtParam);
|
|
2814
|
+
queryParams.delete(postLoginClearedParam);
|
|
2815
|
+
await oAuthState.set({
|
|
2816
|
+
query: queryParams.toString(),
|
|
2817
|
+
signedQueryIssuedAt: signedQueryIssuedAt ?? void 0,
|
|
2818
|
+
postLoginClearedForSession
|
|
2819
|
+
});
|
|
2783
2820
|
if (ctx.path === "/sign-in/social" || ctx.path === "/sign-in/oauth2") {
|
|
2784
2821
|
if (ctx.body.additionalData?.query) return;
|
|
2785
2822
|
if (!ctx.body.additionalData) ctx.body.additionalData = {};
|
|
@@ -2803,7 +2840,7 @@ const oauthProvider = (options) => {
|
|
|
2803
2840
|
const secFetchMode = ctx.request?.headers?.get("sec-fetch-mode")?.toLowerCase();
|
|
2804
2841
|
const acceptHeader = ctx.request?.headers?.get("accept")?.toLowerCase() ?? "";
|
|
2805
2842
|
if (!(secFetchMode === "navigate" || !secFetchMode && (acceptHeader.includes("text/html") || acceptHeader.includes("application/xhtml+xml")))) ctx.headers?.set("accept", "application/json");
|
|
2806
|
-
ctx.query =
|
|
2843
|
+
ctx.query = searchParamsToQuery(removePromptFromQuery(query, "login"));
|
|
2807
2844
|
return await authorizeEndpoint(ctx, opts);
|
|
2808
2845
|
})
|
|
2809
2846
|
}]
|
|
@@ -3811,7 +3848,7 @@ async function authorizeEndpoint(ctx, opts, settings) {
|
|
|
3811
3848
|
});
|
|
3812
3849
|
if (signupRedirect) {
|
|
3813
3850
|
if (promptNone) return redirectWithPromptNoneError(ctx, opts, query, "interaction_required", "End-User interaction is required");
|
|
3814
|
-
return redirectWithPromptCode(ctx, opts, "create", typeof signupRedirect === "string" ? signupRedirect : void 0);
|
|
3851
|
+
return redirectWithPromptCode(ctx, opts, "create", { page: typeof signupRedirect === "string" ? signupRedirect : void 0 });
|
|
3815
3852
|
}
|
|
3816
3853
|
}
|
|
3817
3854
|
if (!settings?.postLogin && opts.postLogin) {
|
|
@@ -3825,7 +3862,7 @@ async function authorizeEndpoint(ctx, opts, settings) {
|
|
|
3825
3862
|
return redirectWithPromptCode(ctx, opts, "post_login");
|
|
3826
3863
|
}
|
|
3827
3864
|
}
|
|
3828
|
-
if (promptSet?.has("consent")) return redirectWithPromptCode(ctx, opts, "consent");
|
|
3865
|
+
if (promptSet?.has("consent")) return redirectWithPromptCode(ctx, opts, "consent", { sessionId: session.session.id });
|
|
3829
3866
|
const referenceId = await opts.postLogin?.consentReferenceId?.({
|
|
3830
3867
|
user: session.user,
|
|
3831
3868
|
session: session.session,
|
|
@@ -3858,7 +3895,7 @@ async function authorizeEndpoint(ctx, opts, settings) {
|
|
|
3858
3895
|
});
|
|
3859
3896
|
if (!consent || !requestedScopes.every((val) => consent.scopes.includes(val))) {
|
|
3860
3897
|
if (promptNone) return redirectWithPromptNoneError(ctx, opts, query, "consent_required", "End-User consent is required");
|
|
3861
|
-
return redirectWithPromptCode(ctx, opts, "consent");
|
|
3898
|
+
return redirectWithPromptCode(ctx, opts, "consent", { sessionId: session.session.id });
|
|
3862
3899
|
}
|
|
3863
3900
|
return redirectWithAuthorizationCode(ctx, opts, {
|
|
3864
3901
|
query,
|
|
@@ -3905,8 +3942,8 @@ async function redirectWithAuthorizationCode(ctx, opts, verificationValue) {
|
|
|
3905
3942
|
redirectUriWithCode.searchParams.set("iss", getIssuer(ctx, opts));
|
|
3906
3943
|
return handleRedirect(ctx, redirectUriWithCode.toString());
|
|
3907
3944
|
}
|
|
3908
|
-
async function redirectWithPromptCode(ctx, opts, type,
|
|
3909
|
-
const queryParams = await signParams(ctx, opts);
|
|
3945
|
+
async function redirectWithPromptCode(ctx, opts, type, options) {
|
|
3946
|
+
const queryParams = await signParams(ctx, opts, { postLoginClearedForSession: type === "consent" && opts.postLogin ? options?.sessionId : void 0 });
|
|
3910
3947
|
let path = opts.loginPage;
|
|
3911
3948
|
if (type === "select_account") path = opts.selectAccount?.page ?? opts.loginPage;
|
|
3912
3949
|
else if (type === "post_login") {
|
|
@@ -3914,12 +3951,16 @@ async function redirectWithPromptCode(ctx, opts, type, page) {
|
|
|
3914
3951
|
path = opts.postLogin?.page;
|
|
3915
3952
|
} else if (type === "consent") path = opts.consentPage;
|
|
3916
3953
|
else if (type === "create") path = opts.signup?.page ?? opts.loginPage;
|
|
3917
|
-
return handleRedirect(ctx, `${page ?? path}?${queryParams}`);
|
|
3954
|
+
return handleRedirect(ctx, `${options?.page ?? path}?${queryParams}`);
|
|
3918
3955
|
}
|
|
3919
|
-
async function signParams(ctx, opts) {
|
|
3920
|
-
const
|
|
3956
|
+
async function signParams(ctx, opts, flags) {
|
|
3957
|
+
const issuedAt = Date.now();
|
|
3958
|
+
const exp = Math.floor(issuedAt / 1e3) + (opts.codeExpiresIn ?? 600);
|
|
3921
3959
|
const params = serializeAuthorizationQuery(ctx.query);
|
|
3922
3960
|
params.set("exp", String(exp));
|
|
3961
|
+
params.set(signedQueryIssuedAtParam, String(issuedAt));
|
|
3962
|
+
params.delete(postLoginClearedParam);
|
|
3963
|
+
if (flags?.postLoginClearedForSession) params.set(postLoginClearedParam, flags.postLoginClearedForSession);
|
|
3923
3964
|
const signature = await makeSignature(params.toString(), ctx.context.secret);
|
|
3924
3965
|
params.append("sig", signature);
|
|
3925
3966
|
return params.toString();
|
|
@@ -45,6 +45,7 @@ declare const schema: {
|
|
|
45
45
|
model: string;
|
|
46
46
|
field: string;
|
|
47
47
|
};
|
|
48
|
+
index: true;
|
|
48
49
|
};
|
|
49
50
|
createdAt: {
|
|
50
51
|
type: "date";
|
|
@@ -150,6 +151,7 @@ declare const schema: {
|
|
|
150
151
|
model: string;
|
|
151
152
|
field: string;
|
|
152
153
|
};
|
|
154
|
+
index: true;
|
|
153
155
|
};
|
|
154
156
|
sessionId: {
|
|
155
157
|
type: "string";
|
|
@@ -159,6 +161,7 @@ declare const schema: {
|
|
|
159
161
|
field: string;
|
|
160
162
|
onDelete: "set null";
|
|
161
163
|
};
|
|
164
|
+
index: true;
|
|
162
165
|
};
|
|
163
166
|
userId: {
|
|
164
167
|
type: "string";
|
|
@@ -167,6 +170,7 @@ declare const schema: {
|
|
|
167
170
|
model: string;
|
|
168
171
|
field: string;
|
|
169
172
|
};
|
|
173
|
+
index: true;
|
|
170
174
|
};
|
|
171
175
|
referenceId: {
|
|
172
176
|
type: "string";
|
|
@@ -218,6 +222,7 @@ declare const schema: {
|
|
|
218
222
|
model: string;
|
|
219
223
|
field: string;
|
|
220
224
|
};
|
|
225
|
+
index: true;
|
|
221
226
|
};
|
|
222
227
|
sessionId: {
|
|
223
228
|
type: "string";
|
|
@@ -227,6 +232,7 @@ declare const schema: {
|
|
|
227
232
|
field: string;
|
|
228
233
|
onDelete: "set null";
|
|
229
234
|
};
|
|
235
|
+
index: true;
|
|
230
236
|
};
|
|
231
237
|
userId: {
|
|
232
238
|
type: "string";
|
|
@@ -235,6 +241,7 @@ declare const schema: {
|
|
|
235
241
|
model: string;
|
|
236
242
|
field: string;
|
|
237
243
|
};
|
|
244
|
+
index: true;
|
|
238
245
|
};
|
|
239
246
|
referenceId: {
|
|
240
247
|
type: "string";
|
|
@@ -247,6 +254,7 @@ declare const schema: {
|
|
|
247
254
|
model: string;
|
|
248
255
|
field: string;
|
|
249
256
|
};
|
|
257
|
+
index: true;
|
|
250
258
|
};
|
|
251
259
|
expiresAt: {
|
|
252
260
|
type: "date";
|
|
@@ -270,6 +278,7 @@ declare const schema: {
|
|
|
270
278
|
model: string;
|
|
271
279
|
field: string;
|
|
272
280
|
};
|
|
281
|
+
index: true;
|
|
273
282
|
};
|
|
274
283
|
userId: {
|
|
275
284
|
type: "string";
|
|
@@ -278,6 +287,7 @@ declare const schema: {
|
|
|
278
287
|
model: string;
|
|
279
288
|
field: string;
|
|
280
289
|
};
|
|
290
|
+
index: true;
|
|
281
291
|
};
|
|
282
292
|
referenceId: {
|
|
283
293
|
type: "string";
|
|
@@ -1287,7 +1297,7 @@ interface OAuthOpaqueAccessToken<Scopes extends readonly Scope[] = InternallySup
|
|
|
1287
1297
|
*/
|
|
1288
1298
|
interface OAuthRefreshToken<Scopes extends readonly Scope[] = InternallySupportedScopes[]> {
|
|
1289
1299
|
token: string;
|
|
1290
|
-
sessionId
|
|
1300
|
+
sessionId?: string;
|
|
1291
1301
|
userId: string;
|
|
1292
1302
|
referenceId?: string;
|
|
1293
1303
|
clientId?: string;
|
|
@@ -1649,4 +1659,4 @@ interface ResourceServerMetadata {
|
|
|
1649
1659
|
dpop_bound_access_tokens_required?: boolean;
|
|
1650
1660
|
}
|
|
1651
1661
|
//#endregion
|
|
1652
|
-
export {
|
|
1662
|
+
export { Scope as _, OAuthClient as a, Awaitable as b, TokenEndpointAuthMethod as c, OAuthConsent as d, OAuthOpaqueAccessToken as f, SchemaClient as g, Prompt as h, GrantType as i, AuthorizePrompt as l, OAuthRefreshToken as m, AuthServerMetadata as n, OIDCMetadata as o, OAuthOptions as p, BearerMethodsSupported as r, ResourceServerMetadata as s, AuthMethod as t, OAuthAuthorizationQuery as u, StoreTokenType as v, VerificationValue as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as Scope, a as OAuthClient, d as OAuthConsent, n as AuthServerMetadata, o as OIDCMetadata, p as OAuthOptions } from "./oauth-CqgT-XaR.mjs";
|
|
2
2
|
import * as better_call0 from "better-call";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import * as better_auth_plugins0 from "better-auth/plugins";
|
|
@@ -15,6 +15,8 @@ declare module "@better-auth/core" {
|
|
|
15
15
|
}
|
|
16
16
|
declare const getOAuthProviderState: () => Promise<{
|
|
17
17
|
query?: string;
|
|
18
|
+
signedQueryIssuedAt?: Date;
|
|
19
|
+
postLoginClearedForSession?: string;
|
|
18
20
|
} | null>;
|
|
19
21
|
/**
|
|
20
22
|
* oAuth 2.1 provider plugin for Better Auth.
|
|
@@ -1819,6 +1821,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
1819
1821
|
model: string;
|
|
1820
1822
|
field: string;
|
|
1821
1823
|
};
|
|
1824
|
+
index: true;
|
|
1822
1825
|
};
|
|
1823
1826
|
createdAt: {
|
|
1824
1827
|
type: "date";
|
|
@@ -1919,6 +1922,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
1919
1922
|
model: string;
|
|
1920
1923
|
field: string;
|
|
1921
1924
|
};
|
|
1925
|
+
index: true;
|
|
1922
1926
|
};
|
|
1923
1927
|
sessionId: {
|
|
1924
1928
|
type: "string";
|
|
@@ -1928,6 +1932,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
1928
1932
|
field: string;
|
|
1929
1933
|
onDelete: "set null";
|
|
1930
1934
|
};
|
|
1935
|
+
index: true;
|
|
1931
1936
|
};
|
|
1932
1937
|
userId: {
|
|
1933
1938
|
type: "string";
|
|
@@ -1936,6 +1941,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
1936
1941
|
model: string;
|
|
1937
1942
|
field: string;
|
|
1938
1943
|
};
|
|
1944
|
+
index: true;
|
|
1939
1945
|
};
|
|
1940
1946
|
referenceId: {
|
|
1941
1947
|
type: "string";
|
|
@@ -1975,6 +1981,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
1975
1981
|
model: string;
|
|
1976
1982
|
field: string;
|
|
1977
1983
|
};
|
|
1984
|
+
index: true;
|
|
1978
1985
|
};
|
|
1979
1986
|
sessionId: {
|
|
1980
1987
|
type: "string";
|
|
@@ -1984,6 +1991,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
1984
1991
|
field: string;
|
|
1985
1992
|
onDelete: "set null";
|
|
1986
1993
|
};
|
|
1994
|
+
index: true;
|
|
1987
1995
|
};
|
|
1988
1996
|
userId: {
|
|
1989
1997
|
type: "string";
|
|
@@ -1992,6 +2000,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
1992
2000
|
model: string;
|
|
1993
2001
|
field: string;
|
|
1994
2002
|
};
|
|
2003
|
+
index: true;
|
|
1995
2004
|
};
|
|
1996
2005
|
referenceId: {
|
|
1997
2006
|
type: "string";
|
|
@@ -2004,6 +2013,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
2004
2013
|
model: string;
|
|
2005
2014
|
field: string;
|
|
2006
2015
|
};
|
|
2016
|
+
index: true;
|
|
2007
2017
|
};
|
|
2008
2018
|
expiresAt: {
|
|
2009
2019
|
type: "date";
|
|
@@ -2027,6 +2037,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
2027
2037
|
model: string;
|
|
2028
2038
|
field: string;
|
|
2029
2039
|
};
|
|
2040
|
+
index: true;
|
|
2030
2041
|
};
|
|
2031
2042
|
userId: {
|
|
2032
2043
|
type: "string";
|
|
@@ -2035,6 +2046,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
2035
2046
|
model: string;
|
|
2036
2047
|
field: string;
|
|
2037
2048
|
};
|
|
2049
|
+
index: true;
|
|
2038
2050
|
};
|
|
2039
2051
|
referenceId: {
|
|
2040
2052
|
type: "string";
|
|
@@ -369,20 +369,24 @@ function searchParamsToQuery(params) {
|
|
|
369
369
|
}
|
|
370
370
|
return result;
|
|
371
371
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
372
|
+
const signedQueryIssuedAtParam = "ba_iat";
|
|
373
|
+
const postLoginClearedParam = "ba_pl";
|
|
374
|
+
function getSignedQueryIssuedAt(oauthQuery) {
|
|
375
|
+
const raw = new URLSearchParams(oauthQuery).get(signedQueryIssuedAtParam);
|
|
376
|
+
if (!raw) return null;
|
|
377
|
+
const issuedAt = Number(raw);
|
|
378
|
+
if (!Number.isFinite(issuedAt) || issuedAt <= 0) return null;
|
|
379
|
+
return new Date(issuedAt);
|
|
380
|
+
}
|
|
381
|
+
function removePromptFromQuery(query, prompt) {
|
|
382
|
+
const nextQuery = new URLSearchParams(query);
|
|
383
|
+
const prompts = nextQuery.get("prompt")?.split(" ");
|
|
380
384
|
const foundPrompt = prompts?.findIndex((v) => v === prompt) ?? -1;
|
|
381
385
|
if (foundPrompt >= 0) {
|
|
382
386
|
prompts?.splice(foundPrompt, 1);
|
|
383
|
-
prompts?.length ?
|
|
387
|
+
prompts?.length ? nextQuery.set("prompt", prompts.join(" ")) : nextQuery.delete("prompt");
|
|
384
388
|
}
|
|
385
|
-
return
|
|
389
|
+
return nextQuery;
|
|
386
390
|
}
|
|
387
391
|
var PKCERequirementErrors = /* @__PURE__ */ function(PKCERequirementErrors) {
|
|
388
392
|
PKCERequirementErrors["PUBLIC_CLIENT"] = "pkce is required for public clients";
|
|
@@ -411,4 +415,4 @@ function isPKCERequired(client, requestedScopes) {
|
|
|
411
415
|
return false;
|
|
412
416
|
}
|
|
413
417
|
//#endregion
|
|
414
|
-
export {
|
|
418
|
+
export { mcpHandler as C, handleMcpErrors as S, signedQueryIssuedAtParam as _, getOAuthProviderPlugin as a, validateClientCredentials as b, isPKCERequired as c, parsePrompt as d, postLoginClearedParam as f, searchParamsToQuery as g, resolveSubjectIdentifier as h, getJwtPlugin as i, normalizeTimestampValue as l, resolveSessionAuthTime as m, decryptStoredClientSecret as n, getSignedQueryIssuedAt as o, removePromptFromQuery as p, getClient as r, getStoredToken as s, basicToClientCredentials as t, parseClientMetadata as u, storeClientSecret as v, verifyOAuthQueryParams as x, storeToken as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/oauth-provider",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.10",
|
|
4
4
|
"description": "An oauth provider plugin for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
65
65
|
"listhen": "^1.9.0",
|
|
66
66
|
"tsdown": "0.21.1",
|
|
67
|
-
"@better-auth/core": "1.6.
|
|
68
|
-
"better-auth": "1.6.
|
|
67
|
+
"@better-auth/core": "1.6.10",
|
|
68
|
+
"better-auth": "1.6.10"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@better-auth/utils": "0.4.0",
|
|
72
72
|
"@better-fetch/fetch": "1.1.21",
|
|
73
73
|
"better-call": "1.3.5",
|
|
74
|
-
"@better-auth/core": "^1.6.
|
|
75
|
-
"better-auth": "^1.6.
|
|
74
|
+
"@better-auth/core": "^1.6.10",
|
|
75
|
+
"better-auth": "^1.6.10"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsdown",
|