@better-auth/oauth-provider 1.7.0-beta.3 → 1.7.0-beta.4
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-assertion-BYtMWGCE.mjs → client-assertion-DLMKVgoj.mjs} +4 -4
- package/dist/client-resource.d.mts +13 -6
- 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 +7 -6
- package/dist/index.mjs +329 -145
- package/dist/{oauth-BxP4Iupj.d.mts → oauth-Vt3lTNHX.d.mts} +67 -20
- package/dist/{oauth-Ds-ejTJY.d.mts → oauth-q7dn10NU.d.mts} +36 -7
- package/dist/{utils-_Jr_enAe.mjs → utils-DKBWQ8fe.mjs} +55 -16
- package/dist/{version-CG1YnCiF.mjs → version-nFnRm-a3.mjs} +1 -1
- package/package.json +6 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { a as OAuthClient, c as TokenEndpointAuthMethod, f as OAuthConsent, g as Prompt, i as GrantType, m as OAuthOptions, t as AuthMethod, v as Scope } from "./oauth-
|
|
1
|
+
import { a as OAuthClient, c as TokenEndpointAuthMethod, f as OAuthConsent, g as Prompt, i as GrantType, m as OAuthOptions, t as AuthMethod, v as Scope } from "./oauth-q7dn10NU.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";
|
|
5
5
|
import * as jose from "jose";
|
|
6
|
+
import { GenericEndpointContext } from "@better-auth/core";
|
|
6
7
|
import * as better_auth0 from "better-auth";
|
|
7
8
|
|
|
8
9
|
//#region src/oauth-endpoint.d.ts
|
|
@@ -59,6 +60,11 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
59
60
|
id: "oauth-provider";
|
|
60
61
|
version: string;
|
|
61
62
|
options: NoInfer<O>;
|
|
63
|
+
onRequest: (request: Request, ctx: better_auth0.AuthContext) => Promise<{
|
|
64
|
+
response: Response;
|
|
65
|
+
} | {
|
|
66
|
+
request: Request;
|
|
67
|
+
} | void>;
|
|
62
68
|
init: (ctx: better_auth0.AuthContext) => void;
|
|
63
69
|
hooks: {
|
|
64
70
|
before: {
|
|
@@ -97,23 +103,23 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
97
103
|
issuer: string;
|
|
98
104
|
authorization_endpoint: string;
|
|
99
105
|
token_endpoint: string;
|
|
100
|
-
registration_endpoint
|
|
106
|
+
registration_endpoint?: string | undefined;
|
|
101
107
|
scopes_supported?: string[] | undefined;
|
|
102
108
|
response_types_supported: "code"[];
|
|
103
109
|
response_modes_supported: "query"[];
|
|
104
110
|
grant_types_supported: GrantType[];
|
|
105
111
|
token_endpoint_auth_methods_supported?: TokenEndpointAuthMethod[] | undefined;
|
|
106
|
-
token_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
112
|
+
token_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[] | undefined;
|
|
107
113
|
service_documentation?: string | undefined;
|
|
108
114
|
ui_locales_supported?: string[] | undefined;
|
|
109
115
|
op_policy_uri?: string | undefined;
|
|
110
116
|
op_tos_uri?: string | undefined;
|
|
111
117
|
revocation_endpoint?: string | undefined;
|
|
112
118
|
revocation_endpoint_auth_methods_supported?: AuthMethod[] | undefined;
|
|
113
|
-
revocation_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
119
|
+
revocation_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[] | undefined;
|
|
114
120
|
introspection_endpoint?: string | undefined;
|
|
115
121
|
introspection_endpoint_auth_methods_supported?: AuthMethod[] | undefined;
|
|
116
|
-
introspection_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
122
|
+
introspection_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[] | undefined;
|
|
117
123
|
code_challenge_methods_supported: "S256"[];
|
|
118
124
|
authorization_response_iss_parameter_supported?: boolean | undefined;
|
|
119
125
|
client_id_metadata_document_supported?: boolean | undefined;
|
|
@@ -123,23 +129,23 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
123
129
|
authorization_endpoint: string;
|
|
124
130
|
token_endpoint: string;
|
|
125
131
|
jwks_uri?: string;
|
|
126
|
-
registration_endpoint
|
|
132
|
+
registration_endpoint?: string;
|
|
127
133
|
scopes_supported?: string[];
|
|
128
134
|
response_types_supported: "code"[];
|
|
129
135
|
response_modes_supported: "query"[];
|
|
130
136
|
grant_types_supported: GrantType[];
|
|
131
137
|
token_endpoint_auth_methods_supported?: TokenEndpointAuthMethod[];
|
|
132
|
-
token_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
138
|
+
token_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[];
|
|
133
139
|
service_documentation?: string;
|
|
134
140
|
ui_locales_supported?: string[];
|
|
135
141
|
op_policy_uri?: string;
|
|
136
142
|
op_tos_uri?: string;
|
|
137
143
|
revocation_endpoint?: string;
|
|
138
144
|
revocation_endpoint_auth_methods_supported?: AuthMethod[];
|
|
139
|
-
revocation_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
145
|
+
revocation_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[];
|
|
140
146
|
introspection_endpoint?: string;
|
|
141
147
|
introspection_endpoint_auth_methods_supported?: AuthMethod[];
|
|
142
|
-
introspection_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
148
|
+
introspection_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[];
|
|
143
149
|
code_challenge_methods_supported: "S256"[];
|
|
144
150
|
authorization_response_iss_parameter_supported?: boolean;
|
|
145
151
|
client_id_metadata_document_supported?: boolean;
|
|
@@ -167,23 +173,23 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
167
173
|
issuer: string;
|
|
168
174
|
authorization_endpoint: string;
|
|
169
175
|
token_endpoint: string;
|
|
170
|
-
registration_endpoint
|
|
176
|
+
registration_endpoint?: string | undefined;
|
|
171
177
|
scopes_supported?: string[] | undefined;
|
|
172
178
|
response_types_supported: "code"[];
|
|
173
179
|
response_modes_supported: "query"[];
|
|
174
180
|
grant_types_supported: GrantType[];
|
|
175
181
|
token_endpoint_auth_methods_supported?: TokenEndpointAuthMethod[] | undefined;
|
|
176
|
-
token_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
182
|
+
token_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[] | undefined;
|
|
177
183
|
service_documentation?: string | undefined;
|
|
178
184
|
ui_locales_supported?: string[] | undefined;
|
|
179
185
|
op_policy_uri?: string | undefined;
|
|
180
186
|
op_tos_uri?: string | undefined;
|
|
181
187
|
revocation_endpoint?: string | undefined;
|
|
182
188
|
revocation_endpoint_auth_methods_supported?: AuthMethod[] | undefined;
|
|
183
|
-
revocation_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
189
|
+
revocation_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[] | undefined;
|
|
184
190
|
introspection_endpoint?: string | undefined;
|
|
185
191
|
introspection_endpoint_auth_methods_supported?: AuthMethod[] | undefined;
|
|
186
|
-
introspection_endpoint_auth_signing_alg_values_supported?: better_auth0.
|
|
192
|
+
introspection_endpoint_auth_signing_alg_values_supported?: better_auth0.PrivateKeyJwtSigningAlgorithm[] | undefined;
|
|
187
193
|
code_challenge_methods_supported: "S256"[];
|
|
188
194
|
authorization_response_iss_parameter_supported?: boolean | undefined;
|
|
189
195
|
client_id_metadata_document_supported?: boolean | undefined;
|
|
@@ -205,6 +211,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
205
211
|
S256: "S256";
|
|
206
212
|
}>>>;
|
|
207
213
|
nonce: z.ZodOptional<z.ZodString>;
|
|
214
|
+
resource: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
208
215
|
prompt: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodEnum<{
|
|
209
216
|
none: "none";
|
|
210
217
|
consent: "consent";
|
|
@@ -215,11 +222,14 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
215
222
|
"select_account consent": "select_account consent";
|
|
216
223
|
}>>>;
|
|
217
224
|
}, z.core.$strip>;
|
|
218
|
-
redirectOnError: OAuthRedirectOnError<
|
|
225
|
+
redirectOnError: OAuthRedirectOnError<GenericEndpointContext>;
|
|
219
226
|
errorCodesByField: {
|
|
220
227
|
response_type: {
|
|
221
228
|
invalid: "unsupported_response_type";
|
|
222
229
|
};
|
|
230
|
+
resource: {
|
|
231
|
+
invalid: "invalid_target";
|
|
232
|
+
};
|
|
223
233
|
};
|
|
224
234
|
metadata: {
|
|
225
235
|
openapi: {
|
|
@@ -231,6 +241,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
231
241
|
schema: {
|
|
232
242
|
type: "string";
|
|
233
243
|
format?: undefined;
|
|
244
|
+
items?: undefined;
|
|
234
245
|
};
|
|
235
246
|
description: string;
|
|
236
247
|
} | {
|
|
@@ -240,6 +251,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
240
251
|
schema: {
|
|
241
252
|
type: "string";
|
|
242
253
|
format?: undefined;
|
|
254
|
+
items?: undefined;
|
|
243
255
|
};
|
|
244
256
|
description: string;
|
|
245
257
|
} | {
|
|
@@ -249,6 +261,19 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
249
261
|
schema: {
|
|
250
262
|
type: "string";
|
|
251
263
|
format: string;
|
|
264
|
+
items?: undefined;
|
|
265
|
+
};
|
|
266
|
+
description: string;
|
|
267
|
+
} | {
|
|
268
|
+
name: string;
|
|
269
|
+
in: "query";
|
|
270
|
+
required: false;
|
|
271
|
+
schema: {
|
|
272
|
+
type: "array";
|
|
273
|
+
items: {
|
|
274
|
+
type: "string";
|
|
275
|
+
};
|
|
276
|
+
format?: undefined;
|
|
252
277
|
};
|
|
253
278
|
description: string;
|
|
254
279
|
})[];
|
|
@@ -429,7 +454,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
429
454
|
code_verifier: z.ZodOptional<z.ZodString>;
|
|
430
455
|
redirect_uri: z.ZodOptional<z.ZodURL>;
|
|
431
456
|
refresh_token: z.ZodOptional<z.ZodString>;
|
|
432
|
-
resource: z.ZodOptional<z.ZodString
|
|
457
|
+
resource: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
433
458
|
scope: z.ZodOptional<z.ZodString>;
|
|
434
459
|
}, z.core.$strip>;
|
|
435
460
|
errorCodesByField: {
|
|
@@ -437,6 +462,9 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
437
462
|
missing: "invalid_request";
|
|
438
463
|
invalid: "unsupported_grant_type";
|
|
439
464
|
};
|
|
465
|
+
resource: {
|
|
466
|
+
invalid: "invalid_target";
|
|
467
|
+
};
|
|
440
468
|
};
|
|
441
469
|
metadata: {
|
|
442
470
|
allowedMediaTypes: string[];
|
|
@@ -480,7 +508,17 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
480
508
|
description: string;
|
|
481
509
|
};
|
|
482
510
|
resource: {
|
|
483
|
-
|
|
511
|
+
oneOf: ({
|
|
512
|
+
type: string;
|
|
513
|
+
description: string;
|
|
514
|
+
items?: undefined;
|
|
515
|
+
} | {
|
|
516
|
+
type: string;
|
|
517
|
+
items: {
|
|
518
|
+
type: string;
|
|
519
|
+
};
|
|
520
|
+
description: string;
|
|
521
|
+
})[];
|
|
484
522
|
description: string;
|
|
485
523
|
};
|
|
486
524
|
scope: {
|
|
@@ -603,10 +641,6 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
603
641
|
type: string;
|
|
604
642
|
description: string;
|
|
605
643
|
};
|
|
606
|
-
resource: {
|
|
607
|
-
type: string;
|
|
608
|
-
description: string;
|
|
609
|
-
};
|
|
610
644
|
};
|
|
611
645
|
required: string[];
|
|
612
646
|
};
|
|
@@ -2070,6 +2104,7 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
2070
2104
|
token: {
|
|
2071
2105
|
type: "string";
|
|
2072
2106
|
required: true;
|
|
2107
|
+
unique: true;
|
|
2073
2108
|
};
|
|
2074
2109
|
clientId: {
|
|
2075
2110
|
type: "string";
|
|
@@ -2103,6 +2138,10 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
2103
2138
|
type: "string";
|
|
2104
2139
|
required: false;
|
|
2105
2140
|
};
|
|
2141
|
+
resources: {
|
|
2142
|
+
type: "string[]";
|
|
2143
|
+
required: false;
|
|
2144
|
+
};
|
|
2106
2145
|
expiresAt: {
|
|
2107
2146
|
type: "date";
|
|
2108
2147
|
};
|
|
@@ -2162,6 +2201,10 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
2162
2201
|
type: "string";
|
|
2163
2202
|
required: false;
|
|
2164
2203
|
};
|
|
2204
|
+
resources: {
|
|
2205
|
+
type: "string[]";
|
|
2206
|
+
required: false;
|
|
2207
|
+
};
|
|
2165
2208
|
refreshId: {
|
|
2166
2209
|
type: "string";
|
|
2167
2210
|
required: false;
|
|
@@ -2208,6 +2251,10 @@ declare const oauthProvider: <O extends OAuthOptions<Scope[]>>(options: O) => {
|
|
|
2208
2251
|
type: "string";
|
|
2209
2252
|
required: false;
|
|
2210
2253
|
};
|
|
2254
|
+
resources: {
|
|
2255
|
+
type: "string[]";
|
|
2256
|
+
required: false;
|
|
2257
|
+
};
|
|
2211
2258
|
scopes: {
|
|
2212
2259
|
type: "string[]";
|
|
2213
2260
|
required: true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrivateKeyJwtSigningAlgorithm } from "@better-auth/core/oauth2";
|
|
2
2
|
import { JWSAlgorithms } from "better-auth/plugins";
|
|
3
3
|
import { JWTPayload } from "jose";
|
|
4
4
|
import { InferOptionSchema, Session, User } from "better-auth/types";
|
|
@@ -152,6 +152,7 @@ declare const schema: {
|
|
|
152
152
|
token: {
|
|
153
153
|
type: "string";
|
|
154
154
|
required: true;
|
|
155
|
+
unique: true;
|
|
155
156
|
};
|
|
156
157
|
clientId: {
|
|
157
158
|
type: "string";
|
|
@@ -185,6 +186,10 @@ declare const schema: {
|
|
|
185
186
|
type: "string";
|
|
186
187
|
required: false;
|
|
187
188
|
};
|
|
189
|
+
resources: {
|
|
190
|
+
type: "string[]";
|
|
191
|
+
required: false;
|
|
192
|
+
};
|
|
188
193
|
expiresAt: {
|
|
189
194
|
type: "date";
|
|
190
195
|
};
|
|
@@ -256,6 +261,10 @@ declare const schema: {
|
|
|
256
261
|
type: "string";
|
|
257
262
|
required: false;
|
|
258
263
|
};
|
|
264
|
+
resources: {
|
|
265
|
+
type: "string[]";
|
|
266
|
+
required: false;
|
|
267
|
+
};
|
|
259
268
|
refreshId: {
|
|
260
269
|
type: "string";
|
|
261
270
|
required: false;
|
|
@@ -302,6 +311,10 @@ declare const schema: {
|
|
|
302
311
|
type: "string";
|
|
303
312
|
required: false;
|
|
304
313
|
};
|
|
314
|
+
resources: {
|
|
315
|
+
type: "string[]";
|
|
316
|
+
required: false;
|
|
317
|
+
};
|
|
305
318
|
scopes: {
|
|
306
319
|
type: "string[]";
|
|
307
320
|
required: true;
|
|
@@ -832,8 +845,8 @@ interface OAuthOptions<Scopes extends readonly Scope[] = InternallySupportedScop
|
|
|
832
845
|
customAccessTokenClaims?: (info: {
|
|
833
846
|
/** The user object if token is associated to a user. Null if user doesn't exist. Undefined if user not applicable. */user?: (User & Record<string, unknown>) | null; /** reference of the consent/authorization */
|
|
834
847
|
referenceId?: string; /** Scopes granted for this token */
|
|
835
|
-
scopes: Scopes; /** The
|
|
836
|
-
|
|
848
|
+
scopes: Scopes; /** The resources requested. */
|
|
849
|
+
resources?: string[]; /** oAuthClient metadata */
|
|
837
850
|
metadata?: Record<string, any>;
|
|
838
851
|
}) => Awaitable<Record<string, any>>;
|
|
839
852
|
/**
|
|
@@ -1191,6 +1204,10 @@ interface OAuthAuthorizationQuery {
|
|
|
1191
1204
|
* with the Claim Value being the nonce value sent in the Authentication Request.
|
|
1192
1205
|
*/
|
|
1193
1206
|
nonce?: string;
|
|
1207
|
+
/**
|
|
1208
|
+
* Resource parameter as specified by [RFC 8707](https://www.rfc-editor.org/rfc/rfc8707.html)
|
|
1209
|
+
*/
|
|
1210
|
+
resource?: string | string[];
|
|
1194
1211
|
}
|
|
1195
1212
|
/**
|
|
1196
1213
|
* Stored within the verification.value field
|
|
@@ -1204,6 +1221,7 @@ interface VerificationValue {
|
|
|
1204
1221
|
query: OAuthAuthorizationQuery;
|
|
1205
1222
|
sessionId: string;
|
|
1206
1223
|
userId: string;
|
|
1224
|
+
resource?: string[];
|
|
1207
1225
|
referenceId?: string;
|
|
1208
1226
|
authTime?: number;
|
|
1209
1227
|
}
|
|
@@ -1369,6 +1387,10 @@ interface OAuthOpaqueAccessToken<Scopes extends readonly Scope[] = InternallySup
|
|
|
1369
1387
|
* Shall match the refreshId.scopes if refreshId is provided.
|
|
1370
1388
|
*/
|
|
1371
1389
|
scopes: Scopes;
|
|
1390
|
+
/**
|
|
1391
|
+
* Resources allowed for this access token.
|
|
1392
|
+
*/
|
|
1393
|
+
resources?: string[];
|
|
1372
1394
|
}
|
|
1373
1395
|
/**
|
|
1374
1396
|
* Refresh Token Database Schema
|
|
@@ -1396,6 +1418,10 @@ interface OAuthRefreshToken<Scopes extends readonly Scope[] = InternallySupporte
|
|
|
1396
1418
|
* Considered Immutable once granted.
|
|
1397
1419
|
*/
|
|
1398
1420
|
scopes: Scopes;
|
|
1421
|
+
/**
|
|
1422
|
+
* Resources allowed for this refresh token
|
|
1423
|
+
*/
|
|
1424
|
+
resources?: string[];
|
|
1399
1425
|
}
|
|
1400
1426
|
/**
|
|
1401
1427
|
* Consent Database Schema
|
|
@@ -1404,6 +1430,7 @@ type OAuthConsent<Scopes extends readonly Scope[] = InternallySupportedScopes[]>
|
|
|
1404
1430
|
id: string;
|
|
1405
1431
|
clientId: string;
|
|
1406
1432
|
userId: string;
|
|
1433
|
+
resources?: string[];
|
|
1407
1434
|
referenceId?: string;
|
|
1408
1435
|
scopes: Scopes;
|
|
1409
1436
|
createdAt: Date;
|
|
@@ -1457,9 +1484,11 @@ interface AuthServerMetadata {
|
|
|
1457
1484
|
/**
|
|
1458
1485
|
* The URL of the dynamic client registration endpoint.
|
|
1459
1486
|
*
|
|
1487
|
+
* This field is only present when `allowDynamicClientRegistration` is enabled.
|
|
1488
|
+
*
|
|
1460
1489
|
* @default `/oauth2/register`
|
|
1461
1490
|
*/
|
|
1462
|
-
registration_endpoint
|
|
1491
|
+
registration_endpoint?: string;
|
|
1463
1492
|
/**
|
|
1464
1493
|
* Supported scopes.
|
|
1465
1494
|
*/
|
|
@@ -1492,7 +1521,7 @@ interface AuthServerMetadata {
|
|
|
1492
1521
|
* token endpoint for the "private_key_jwt" and "client_secret_jwt"
|
|
1493
1522
|
* authentication methods (see field token_endpoint_auth_methods_supported).
|
|
1494
1523
|
*/
|
|
1495
|
-
token_endpoint_auth_signing_alg_values_supported?:
|
|
1524
|
+
token_endpoint_auth_signing_alg_values_supported?: PrivateKeyJwtSigningAlgorithm[];
|
|
1496
1525
|
/**
|
|
1497
1526
|
* URL of a page containing human-readable information
|
|
1498
1527
|
* that developers might want or need to know when using the
|
|
@@ -1538,7 +1567,7 @@ interface AuthServerMetadata {
|
|
|
1538
1567
|
* token endpoint for the "private_key_jwt" and "client_secret_jwt"
|
|
1539
1568
|
* authentication methods (see field revocation_endpoint_auth_methods_supported).
|
|
1540
1569
|
*/
|
|
1541
|
-
revocation_endpoint_auth_signing_alg_values_supported?:
|
|
1570
|
+
revocation_endpoint_auth_signing_alg_values_supported?: PrivateKeyJwtSigningAlgorithm[];
|
|
1542
1571
|
/**
|
|
1543
1572
|
* URL of the authorization server's OAuth 2.0
|
|
1544
1573
|
* introspection endpoint [RFC7662](https://datatracker.ietf.org/doc/html/rfc7662)
|
|
@@ -1559,7 +1588,7 @@ interface AuthServerMetadata {
|
|
|
1559
1588
|
* the "private_key_jwt" and "client_secret_jwt" authentication methods
|
|
1560
1589
|
* (see field introspection_endpoint_auth_methods_supported).
|
|
1561
1590
|
*/
|
|
1562
|
-
introspection_endpoint_auth_signing_alg_values_supported?:
|
|
1591
|
+
introspection_endpoint_auth_signing_alg_values_supported?: PrivateKeyJwtSigningAlgorithm[];
|
|
1563
1592
|
/**
|
|
1564
1593
|
* Supported code challenge methods.
|
|
1565
1594
|
*
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { APIError } from "better-call";
|
|
2
|
+
import { decodeBasicCredentials } from "@better-auth/core/oauth2";
|
|
2
3
|
import { constantTimeEqual, makeSignature, symmetricDecrypt, symmetricEncrypt } from "better-auth/crypto";
|
|
3
4
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
4
|
-
import {
|
|
5
|
+
import { base64Url } from "@better-auth/utils/base64";
|
|
5
6
|
import { createHash } from "@better-auth/utils/hash";
|
|
6
7
|
//#region src/utils/index.ts
|
|
7
8
|
var TTLCache = class {
|
|
@@ -74,6 +75,47 @@ function resolveSessionAuthTime(value) {
|
|
|
74
75
|
if (!nested || typeof nested !== "object") return;
|
|
75
76
|
return normalizeTimestampValue(nested.createdAt) ?? normalizeTimestampValue(nested.created_at);
|
|
76
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Normalizes OAuth resource values into a non-empty string array.
|
|
80
|
+
*/
|
|
81
|
+
function toResourceList(value) {
|
|
82
|
+
if (typeof value === "string") return [value];
|
|
83
|
+
if (!value?.length) return void 0;
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Normalizes audience values for JWT claims.
|
|
88
|
+
*/
|
|
89
|
+
function toAudienceClaim(audience) {
|
|
90
|
+
if (typeof audience === "string") return audience;
|
|
91
|
+
if (!audience?.length) return void 0;
|
|
92
|
+
return audience.length === 1 ? audience.at(0) : audience;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Checks the resource parameter, if provided,
|
|
96
|
+
* and returns either a valid audience or a tagged validation error.
|
|
97
|
+
*/
|
|
98
|
+
async function checkResource(ctx, opts, resource, scopes) {
|
|
99
|
+
const normalizedResource = toResourceList(resource);
|
|
100
|
+
const audience = normalizedResource ? [...normalizedResource] : void 0;
|
|
101
|
+
if (audience) {
|
|
102
|
+
const hasOpenId = scopes.includes("openid");
|
|
103
|
+
const baseUrl = ctx.context.baseURL;
|
|
104
|
+
const userInfoEndpoint = `${baseUrl}/oauth2/userinfo`;
|
|
105
|
+
if (hasOpenId && !audience.includes(userInfoEndpoint)) audience.push(userInfoEndpoint);
|
|
106
|
+
const filteredValidAudiences = opts.validAudiences?.filter((aud) => aud.length);
|
|
107
|
+
const validAudiences = new Set(filteredValidAudiences?.length ? filteredValidAudiences : [baseUrl]);
|
|
108
|
+
if (hasOpenId) validAudiences.add(userInfoEndpoint);
|
|
109
|
+
for (const aud of audience) if (!validAudiences.has(aud)) return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: "invalid_resource"
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
success: true,
|
|
116
|
+
audience: toAudienceClaim(audience)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
77
119
|
const cachedTrustedClients = new TTLCache();
|
|
78
120
|
async function verifyOAuthQueryParams(oauth_query, secret) {
|
|
79
121
|
const queryParams = new URLSearchParams(oauth_query);
|
|
@@ -228,23 +270,20 @@ async function getStoredToken(storageMethod = "hashed", token, type) {
|
|
|
228
270
|
*
|
|
229
271
|
* @internal
|
|
230
272
|
*/
|
|
273
|
+
const BASIC_SCHEME_PREFIX = /^Basic +/i;
|
|
231
274
|
function basicToClientCredentials(authorization) {
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
275
|
+
if (!BASIC_SCHEME_PREFIX.test(authorization)) return;
|
|
276
|
+
try {
|
|
277
|
+
const { clientId, clientSecret } = decodeBasicCredentials(authorization);
|
|
278
|
+
return {
|
|
279
|
+
client_id: clientId,
|
|
280
|
+
client_secret: clientSecret
|
|
281
|
+
};
|
|
282
|
+
} catch {
|
|
283
|
+
throw new APIError("BAD_REQUEST", {
|
|
241
284
|
error_description: "invalid authorization header format",
|
|
242
285
|
error: "invalid_client"
|
|
243
286
|
});
|
|
244
|
-
return {
|
|
245
|
-
client_id: id,
|
|
246
|
-
client_secret: secret
|
|
247
|
-
};
|
|
248
287
|
}
|
|
249
288
|
}
|
|
250
289
|
/**
|
|
@@ -324,7 +363,7 @@ async function extractClientCredentials(ctx, opts, expectedAudience) {
|
|
|
324
363
|
error_description: "client_assertion cannot be combined with client_secret or Basic auth",
|
|
325
364
|
error: "invalid_client"
|
|
326
365
|
});
|
|
327
|
-
const { verifyClientAssertion: verify } = await import("./client-assertion-
|
|
366
|
+
const { verifyClientAssertion: verify } = await import("./client-assertion-DLMKVgoj.mjs").then((n) => n.t);
|
|
328
367
|
const result = await verify(ctx, opts, body.client_assertion, body.client_assertion_type, body.client_id, expectedAudience);
|
|
329
368
|
return {
|
|
330
369
|
method: "private_key_jwt",
|
|
@@ -450,4 +489,4 @@ function isPKCERequired(client, requestedScopes) {
|
|
|
450
489
|
return false;
|
|
451
490
|
}
|
|
452
491
|
//#endregion
|
|
453
|
-
export {
|
|
492
|
+
export { toAudienceClaim as C, verifyOAuthQueryParams as D, validateClientCredentials as E, storeToken as S, toResourceList as T, resolveSessionAuthTime as _, getClient as a, signedQueryIssuedAtParam as b, getSignedQueryIssuedAt as c, mergeDiscoveryMetadata as d, normalizeTimestampValue as f, removePromptFromQuery as g, postLoginClearedParam as h, extractClientCredentials as i, getStoredToken as l, parsePrompt as m, decryptStoredClientSecret as n, getJwtPlugin as o, parseClientMetadata as p, destructureCredentials as r, getOAuthProviderPlugin as s, checkResource as t, isPKCERequired as u, resolveSubjectIdentifier as v, toClientDiscoveryArray as w, storeClientSecret as x, searchParamsToQuery as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/oauth-provider",
|
|
3
|
-
"version": "1.7.0-beta.
|
|
3
|
+
"version": "1.7.0-beta.4",
|
|
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.7.0-beta.
|
|
68
|
-
"better-auth": "1.7.0-beta.
|
|
67
|
+
"@better-auth/core": "1.7.0-beta.4",
|
|
68
|
+
"better-auth": "1.7.0-beta.4"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@better-auth/utils": "0.4.
|
|
71
|
+
"@better-auth/utils": "0.4.1",
|
|
72
72
|
"@better-fetch/fetch": "1.1.21",
|
|
73
73
|
"better-call": "1.3.5",
|
|
74
|
-
"@better-auth/core": "^1.7.0-beta.
|
|
75
|
-
"better-auth": "^1.7.0-beta.
|
|
74
|
+
"@better-auth/core": "^1.7.0-beta.4",
|
|
75
|
+
"better-auth": "^1.7.0-beta.4"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsdown",
|