@better-auth/core 1.4.0-beta.7 → 1.4.0-beta.8

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.
Files changed (39) hide show
  1. package/.turbo/turbo-build.log +12 -4
  2. package/build.config.ts +2 -0
  3. package/dist/db/index.cjs +16 -0
  4. package/dist/db/index.d.cts +14 -3
  5. package/dist/db/index.d.mts +14 -3
  6. package/dist/db/index.d.ts +14 -3
  7. package/dist/db/index.mjs +16 -1
  8. package/dist/env/index.cjs +315 -0
  9. package/dist/env/index.d.cts +85 -0
  10. package/dist/env/index.d.mts +85 -0
  11. package/dist/env/index.d.ts +85 -0
  12. package/dist/env/index.mjs +300 -0
  13. package/dist/index.d.cts +2 -2
  14. package/dist/index.d.mts +2 -2
  15. package/dist/index.d.ts +2 -2
  16. package/dist/oauth2/index.cjs +368 -0
  17. package/dist/oauth2/index.d.cts +277 -0
  18. package/dist/oauth2/index.d.mts +277 -0
  19. package/dist/oauth2/index.d.ts +277 -0
  20. package/dist/oauth2/index.mjs +357 -0
  21. package/dist/shared/{core.CnvFgghY.d.cts → core.DeNN5HMO.d.cts} +27 -1
  22. package/dist/shared/{core.CnvFgghY.d.mts → core.DeNN5HMO.d.mts} +27 -1
  23. package/dist/shared/{core.CnvFgghY.d.ts → core.DeNN5HMO.d.ts} +27 -1
  24. package/package.json +29 -1
  25. package/src/db/index.ts +2 -0
  26. package/src/db/schema/rate-limit.ts +21 -0
  27. package/src/db/type.ts +28 -0
  28. package/src/env/color-depth.ts +171 -0
  29. package/src/env/env-impl.ts +123 -0
  30. package/src/env/index.ts +23 -0
  31. package/src/env/logger.test.ts +33 -0
  32. package/src/env/logger.ts +145 -0
  33. package/src/oauth2/client-credentials-token.ts +102 -0
  34. package/src/oauth2/create-authorization-url.ts +85 -0
  35. package/src/oauth2/index.ts +22 -0
  36. package/src/oauth2/oauth-provider.ts +194 -0
  37. package/src/oauth2/refresh-access-token.ts +124 -0
  38. package/src/oauth2/utils.ts +36 -0
  39. package/src/oauth2/validate-authorization-code.ts +156 -0
@@ -0,0 +1,368 @@
1
+ 'use strict';
2
+
3
+ const base64 = require('@better-auth/utils/base64');
4
+ const fetch = require('@better-fetch/fetch');
5
+ const jose = require('jose');
6
+
7
+ function getOAuth2Tokens(data) {
8
+ const getDate = (seconds) => {
9
+ const now = /* @__PURE__ */ new Date();
10
+ return new Date(now.getTime() + seconds * 1e3);
11
+ };
12
+ return {
13
+ tokenType: data.token_type,
14
+ accessToken: data.access_token,
15
+ refreshToken: data.refresh_token,
16
+ accessTokenExpiresAt: data.expires_in ? getDate(data.expires_in) : void 0,
17
+ refreshTokenExpiresAt: data.refresh_token_expires_in ? getDate(data.refresh_token_expires_in) : void 0,
18
+ scopes: data?.scope ? typeof data.scope === "string" ? data.scope.split(" ") : data.scope : [],
19
+ idToken: data.id_token
20
+ };
21
+ }
22
+ async function generateCodeChallenge(codeVerifier) {
23
+ const encoder = new TextEncoder();
24
+ const data = encoder.encode(codeVerifier);
25
+ const hash = await crypto.subtle.digest("SHA-256", data);
26
+ return base64.base64Url.encode(new Uint8Array(hash), {
27
+ padding: false
28
+ });
29
+ }
30
+
31
+ async function createAuthorizationURL({
32
+ id,
33
+ options,
34
+ authorizationEndpoint,
35
+ state,
36
+ codeVerifier,
37
+ scopes,
38
+ claims,
39
+ redirectURI,
40
+ duration,
41
+ prompt,
42
+ accessType,
43
+ responseType,
44
+ display,
45
+ loginHint,
46
+ hd,
47
+ responseMode,
48
+ additionalParams,
49
+ scopeJoiner
50
+ }) {
51
+ const url = new URL(authorizationEndpoint);
52
+ url.searchParams.set("response_type", responseType || "code");
53
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
54
+ url.searchParams.set("client_id", primaryClientId);
55
+ url.searchParams.set("state", state);
56
+ url.searchParams.set("scope", scopes.join(scopeJoiner || " "));
57
+ url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
58
+ duration && url.searchParams.set("duration", duration);
59
+ display && url.searchParams.set("display", display);
60
+ loginHint && url.searchParams.set("login_hint", loginHint);
61
+ prompt && url.searchParams.set("prompt", prompt);
62
+ hd && url.searchParams.set("hd", hd);
63
+ accessType && url.searchParams.set("access_type", accessType);
64
+ responseMode && url.searchParams.set("response_mode", responseMode);
65
+ if (codeVerifier) {
66
+ const codeChallenge = await generateCodeChallenge(codeVerifier);
67
+ url.searchParams.set("code_challenge_method", "S256");
68
+ url.searchParams.set("code_challenge", codeChallenge);
69
+ }
70
+ if (claims) {
71
+ const claimsObj = claims.reduce(
72
+ (acc, claim) => {
73
+ acc[claim] = null;
74
+ return acc;
75
+ },
76
+ {}
77
+ );
78
+ url.searchParams.set(
79
+ "claims",
80
+ JSON.stringify({
81
+ id_token: { email: null, email_verified: null, ...claimsObj }
82
+ })
83
+ );
84
+ }
85
+ if (additionalParams) {
86
+ Object.entries(additionalParams).forEach(([key, value]) => {
87
+ url.searchParams.set(key, value);
88
+ });
89
+ }
90
+ return url;
91
+ }
92
+
93
+ function createAuthorizationCodeRequest({
94
+ code,
95
+ codeVerifier,
96
+ redirectURI,
97
+ options,
98
+ authentication,
99
+ deviceId,
100
+ headers,
101
+ additionalParams = {},
102
+ resource
103
+ }) {
104
+ const body = new URLSearchParams();
105
+ const requestHeaders = {
106
+ "content-type": "application/x-www-form-urlencoded",
107
+ accept: "application/json",
108
+ "user-agent": "better-auth",
109
+ ...headers
110
+ };
111
+ body.set("grant_type", "authorization_code");
112
+ body.set("code", code);
113
+ codeVerifier && body.set("code_verifier", codeVerifier);
114
+ options.clientKey && body.set("client_key", options.clientKey);
115
+ deviceId && body.set("device_id", deviceId);
116
+ body.set("redirect_uri", options.redirectURI || redirectURI);
117
+ if (resource) {
118
+ if (typeof resource === "string") {
119
+ body.append("resource", resource);
120
+ } else {
121
+ for (const _resource of resource) {
122
+ body.append("resource", _resource);
123
+ }
124
+ }
125
+ }
126
+ if (authentication === "basic") {
127
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
128
+ const encodedCredentials = base64.base64.encode(
129
+ `${primaryClientId}:${options.clientSecret ?? ""}`
130
+ );
131
+ requestHeaders["authorization"] = `Basic ${encodedCredentials}`;
132
+ } else {
133
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
134
+ body.set("client_id", primaryClientId);
135
+ if (options.clientSecret) {
136
+ body.set("client_secret", options.clientSecret);
137
+ }
138
+ }
139
+ for (const [key, value] of Object.entries(additionalParams)) {
140
+ if (!body.has(key)) body.append(key, value);
141
+ }
142
+ return {
143
+ body,
144
+ headers: requestHeaders
145
+ };
146
+ }
147
+ async function validateAuthorizationCode({
148
+ code,
149
+ codeVerifier,
150
+ redirectURI,
151
+ options,
152
+ tokenEndpoint,
153
+ authentication,
154
+ deviceId,
155
+ headers,
156
+ additionalParams = {},
157
+ resource
158
+ }) {
159
+ const { body, headers: requestHeaders } = createAuthorizationCodeRequest({
160
+ code,
161
+ codeVerifier,
162
+ redirectURI,
163
+ options,
164
+ authentication,
165
+ deviceId,
166
+ headers,
167
+ additionalParams,
168
+ resource
169
+ });
170
+ const { data, error } = await fetch.betterFetch(tokenEndpoint, {
171
+ method: "POST",
172
+ body,
173
+ headers: requestHeaders
174
+ });
175
+ if (error) {
176
+ throw error;
177
+ }
178
+ const tokens = getOAuth2Tokens(data);
179
+ return tokens;
180
+ }
181
+ async function validateToken(token, jwksEndpoint) {
182
+ const { data, error } = await fetch.betterFetch(jwksEndpoint, {
183
+ method: "GET",
184
+ headers: {
185
+ accept: "application/json",
186
+ "user-agent": "better-auth"
187
+ }
188
+ });
189
+ if (error) {
190
+ throw error;
191
+ }
192
+ const keys = data["keys"];
193
+ const header = JSON.parse(atob(token.split(".")[0]));
194
+ const key = keys.find((key2) => key2.kid === header.kid);
195
+ if (!key) {
196
+ throw new Error("Key not found");
197
+ }
198
+ const verified = await jose.jwtVerify(token, key);
199
+ return verified;
200
+ }
201
+
202
+ function createRefreshAccessTokenRequest({
203
+ refreshToken,
204
+ options,
205
+ authentication,
206
+ extraParams,
207
+ resource
208
+ }) {
209
+ const body = new URLSearchParams();
210
+ const headers = {
211
+ "content-type": "application/x-www-form-urlencoded",
212
+ accept: "application/json"
213
+ };
214
+ body.set("grant_type", "refresh_token");
215
+ body.set("refresh_token", refreshToken);
216
+ if (authentication === "basic") {
217
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
218
+ if (primaryClientId) {
219
+ headers["authorization"] = "Basic " + base64.base64.encode(`${primaryClientId}:${options.clientSecret ?? ""}`);
220
+ } else {
221
+ headers["authorization"] = "Basic " + base64.base64.encode(`:${options.clientSecret ?? ""}`);
222
+ }
223
+ } else {
224
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
225
+ body.set("client_id", primaryClientId);
226
+ if (options.clientSecret) {
227
+ body.set("client_secret", options.clientSecret);
228
+ }
229
+ }
230
+ if (resource) {
231
+ if (typeof resource === "string") {
232
+ body.append("resource", resource);
233
+ } else {
234
+ for (const _resource of resource) {
235
+ body.append("resource", _resource);
236
+ }
237
+ }
238
+ }
239
+ if (extraParams) {
240
+ for (const [key, value] of Object.entries(extraParams)) {
241
+ body.set(key, value);
242
+ }
243
+ }
244
+ return {
245
+ body,
246
+ headers
247
+ };
248
+ }
249
+ async function refreshAccessToken({
250
+ refreshToken,
251
+ options,
252
+ tokenEndpoint,
253
+ authentication,
254
+ extraParams
255
+ }) {
256
+ const { body, headers } = createRefreshAccessTokenRequest({
257
+ refreshToken,
258
+ options,
259
+ authentication,
260
+ extraParams
261
+ });
262
+ const { data, error } = await fetch.betterFetch(tokenEndpoint, {
263
+ method: "POST",
264
+ body,
265
+ headers
266
+ });
267
+ if (error) {
268
+ throw error;
269
+ }
270
+ const tokens = {
271
+ accessToken: data.access_token,
272
+ refreshToken: data.refresh_token,
273
+ tokenType: data.token_type,
274
+ scopes: data.scope?.split(" "),
275
+ idToken: data.id_token
276
+ };
277
+ if (data.expires_in) {
278
+ const now = /* @__PURE__ */ new Date();
279
+ tokens.accessTokenExpiresAt = new Date(
280
+ now.getTime() + data.expires_in * 1e3
281
+ );
282
+ }
283
+ return tokens;
284
+ }
285
+
286
+ function createClientCredentialsTokenRequest({
287
+ options,
288
+ scope,
289
+ authentication,
290
+ resource
291
+ }) {
292
+ const body = new URLSearchParams();
293
+ const headers = {
294
+ "content-type": "application/x-www-form-urlencoded",
295
+ accept: "application/json"
296
+ };
297
+ body.set("grant_type", "client_credentials");
298
+ scope && body.set("scope", scope);
299
+ if (resource) {
300
+ if (typeof resource === "string") {
301
+ body.append("resource", resource);
302
+ } else {
303
+ for (const _resource of resource) {
304
+ body.append("resource", _resource);
305
+ }
306
+ }
307
+ }
308
+ if (authentication === "basic") {
309
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
310
+ const encodedCredentials = base64.base64Url.encode(
311
+ `${primaryClientId}:${options.clientSecret}`
312
+ );
313
+ headers["authorization"] = `Basic ${encodedCredentials}`;
314
+ } else {
315
+ const primaryClientId = Array.isArray(options.clientId) ? options.clientId[0] : options.clientId;
316
+ body.set("client_id", primaryClientId);
317
+ body.set("client_secret", options.clientSecret);
318
+ }
319
+ return {
320
+ body,
321
+ headers
322
+ };
323
+ }
324
+ async function clientCredentialsToken({
325
+ options,
326
+ tokenEndpoint,
327
+ scope,
328
+ authentication,
329
+ resource
330
+ }) {
331
+ const { body, headers } = createClientCredentialsTokenRequest({
332
+ options,
333
+ scope,
334
+ authentication,
335
+ resource
336
+ });
337
+ const { data, error } = await fetch.betterFetch(tokenEndpoint, {
338
+ method: "POST",
339
+ body,
340
+ headers
341
+ });
342
+ if (error) {
343
+ throw error;
344
+ }
345
+ const tokens = {
346
+ accessToken: data.access_token,
347
+ tokenType: data.token_type,
348
+ scopes: data.scope?.split(" ")
349
+ };
350
+ if (data.expires_in) {
351
+ const now = /* @__PURE__ */ new Date();
352
+ tokens.accessTokenExpiresAt = new Date(
353
+ now.getTime() + data.expires_in * 1e3
354
+ );
355
+ }
356
+ return tokens;
357
+ }
358
+
359
+ exports.clientCredentialsToken = clientCredentialsToken;
360
+ exports.createAuthorizationCodeRequest = createAuthorizationCodeRequest;
361
+ exports.createAuthorizationURL = createAuthorizationURL;
362
+ exports.createClientCredentialsTokenRequest = createClientCredentialsTokenRequest;
363
+ exports.createRefreshAccessTokenRequest = createRefreshAccessTokenRequest;
364
+ exports.generateCodeChallenge = generateCodeChallenge;
365
+ exports.getOAuth2Tokens = getOAuth2Tokens;
366
+ exports.refreshAccessToken = refreshAccessToken;
367
+ exports.validateAuthorizationCode = validateAuthorizationCode;
368
+ exports.validateToken = validateToken;
@@ -0,0 +1,277 @@
1
+ import { a as LiteralString } from '../shared/core.DeNN5HMO.cjs';
2
+ import * as jose from 'jose';
3
+ import 'zod';
4
+
5
+ interface OAuth2Tokens {
6
+ tokenType?: string;
7
+ accessToken?: string;
8
+ refreshToken?: string;
9
+ accessTokenExpiresAt?: Date;
10
+ refreshTokenExpiresAt?: Date;
11
+ scopes?: string[];
12
+ idToken?: string;
13
+ }
14
+ type OAuth2UserInfo = {
15
+ id: string | number;
16
+ name?: string;
17
+ email?: string | null;
18
+ image?: string;
19
+ emailVerified: boolean;
20
+ };
21
+ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Partial<ProviderOptions>> {
22
+ id: LiteralString;
23
+ createAuthorizationURL: (data: {
24
+ state: string;
25
+ codeVerifier: string;
26
+ scopes?: string[];
27
+ redirectURI: string;
28
+ display?: string;
29
+ loginHint?: string;
30
+ }) => Promise<URL> | URL;
31
+ name: string;
32
+ validateAuthorizationCode: (data: {
33
+ code: string;
34
+ redirectURI: string;
35
+ codeVerifier?: string;
36
+ deviceId?: string;
37
+ }) => Promise<OAuth2Tokens>;
38
+ getUserInfo: (token: OAuth2Tokens & {
39
+ /**
40
+ * The user object from the provider
41
+ * This is only available for some providers like Apple
42
+ */
43
+ user?: {
44
+ name?: {
45
+ firstName?: string;
46
+ lastName?: string;
47
+ };
48
+ email?: string;
49
+ };
50
+ }) => Promise<{
51
+ user: OAuth2UserInfo;
52
+ data: T;
53
+ } | null>;
54
+ /**
55
+ * Custom function to refresh a token
56
+ */
57
+ refreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;
58
+ revokeToken?: (token: string) => Promise<void>;
59
+ /**
60
+ * Verify the id token
61
+ * @param token - The id token
62
+ * @param nonce - The nonce
63
+ * @returns True if the id token is valid, false otherwise
64
+ */
65
+ verifyIdToken?: (token: string, nonce?: string) => Promise<boolean>;
66
+ /**
67
+ * Disable implicit sign up for new users. When set to true for the provider,
68
+ * sign-in need to be called with with requestSignUp as true to create new users.
69
+ */
70
+ disableImplicitSignUp?: boolean;
71
+ /**
72
+ * Disable sign up for new users.
73
+ */
74
+ disableSignUp?: boolean;
75
+ /**
76
+ * Options for the provider
77
+ */
78
+ options?: O;
79
+ }
80
+ type ProviderOptions<Profile extends Record<string, any> = any> = {
81
+ /**
82
+ * The client ID of your application.
83
+ *
84
+ * This is usually a string but can be any type depending on the provider.
85
+ */
86
+ clientId?: unknown;
87
+ /**
88
+ * The client secret of your application
89
+ */
90
+ clientSecret?: string;
91
+ /**
92
+ * The scopes you want to request from the provider
93
+ */
94
+ scope?: string[];
95
+ /**
96
+ * Remove default scopes of the provider
97
+ */
98
+ disableDefaultScope?: boolean;
99
+ /**
100
+ * The redirect URL for your application. This is where the provider will
101
+ * redirect the user after the sign in process. Make sure this URL is
102
+ * whitelisted in the provider's dashboard.
103
+ */
104
+ redirectURI?: string;
105
+ /**
106
+ * The client key of your application
107
+ * Tiktok Social Provider uses this field instead of clientId
108
+ */
109
+ clientKey?: string;
110
+ /**
111
+ * Disable provider from allowing users to sign in
112
+ * with this provider with an id token sent from the
113
+ * client.
114
+ */
115
+ disableIdTokenSignIn?: boolean;
116
+ /**
117
+ * verifyIdToken function to verify the id token
118
+ */
119
+ verifyIdToken?: (token: string, nonce?: string) => Promise<boolean>;
120
+ /**
121
+ * Custom function to get user info from the provider
122
+ */
123
+ getUserInfo?: (token: OAuth2Tokens) => Promise<{
124
+ user: {
125
+ id: string;
126
+ name?: string;
127
+ email?: string | null;
128
+ image?: string;
129
+ emailVerified: boolean;
130
+ [key: string]: any;
131
+ };
132
+ data: any;
133
+ }>;
134
+ /**
135
+ * Custom function to refresh a token
136
+ */
137
+ refreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;
138
+ /**
139
+ * Custom function to map the provider profile to a
140
+ * user.
141
+ */
142
+ mapProfileToUser?: (profile: Profile) => {
143
+ id?: string;
144
+ name?: string;
145
+ email?: string | null;
146
+ image?: string;
147
+ emailVerified?: boolean;
148
+ [key: string]: any;
149
+ } | Promise<{
150
+ id?: string;
151
+ name?: string;
152
+ email?: string | null;
153
+ image?: string;
154
+ emailVerified?: boolean;
155
+ [key: string]: any;
156
+ }>;
157
+ /**
158
+ * Disable implicit sign up for new users. When set to true for the provider,
159
+ * sign-in need to be called with with requestSignUp as true to create new users.
160
+ */
161
+ disableImplicitSignUp?: boolean;
162
+ /**
163
+ * Disable sign up for new users.
164
+ */
165
+ disableSignUp?: boolean;
166
+ /**
167
+ * The prompt to use for the authorization code request
168
+ */
169
+ prompt?: "select_account" | "consent" | "login" | "none" | "select_account consent";
170
+ /**
171
+ * The response mode to use for the authorization code request
172
+ */
173
+ responseMode?: "query" | "form_post";
174
+ /**
175
+ * If enabled, the user info will be overridden with the provider user info
176
+ * This is useful if you want to use the provider user info to update the user info
177
+ *
178
+ * @default false
179
+ */
180
+ overrideUserInfoOnSignIn?: boolean;
181
+ };
182
+
183
+ declare function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens;
184
+ declare function generateCodeChallenge(codeVerifier: string): Promise<string>;
185
+
186
+ declare function createAuthorizationURL({ id, options, authorizationEndpoint, state, codeVerifier, scopes, claims, redirectURI, duration, prompt, accessType, responseType, display, loginHint, hd, responseMode, additionalParams, scopeJoiner, }: {
187
+ id: string;
188
+ options: ProviderOptions;
189
+ redirectURI: string;
190
+ authorizationEndpoint: string;
191
+ state: string;
192
+ codeVerifier?: string;
193
+ scopes: string[];
194
+ claims?: string[];
195
+ duration?: string;
196
+ prompt?: string;
197
+ accessType?: string;
198
+ responseType?: string;
199
+ display?: string;
200
+ loginHint?: string;
201
+ hd?: string;
202
+ responseMode?: string;
203
+ additionalParams?: Record<string, string>;
204
+ scopeJoiner?: string;
205
+ }): Promise<URL>;
206
+
207
+ declare function createAuthorizationCodeRequest({ code, codeVerifier, redirectURI, options, authentication, deviceId, headers, additionalParams, resource, }: {
208
+ code: string;
209
+ redirectURI: string;
210
+ options: Partial<ProviderOptions>;
211
+ codeVerifier?: string;
212
+ deviceId?: string;
213
+ authentication?: "basic" | "post";
214
+ headers?: Record<string, string>;
215
+ additionalParams?: Record<string, string>;
216
+ resource?: string | string[];
217
+ }): {
218
+ body: URLSearchParams;
219
+ headers: Record<string, any>;
220
+ };
221
+ declare function validateAuthorizationCode({ code, codeVerifier, redirectURI, options, tokenEndpoint, authentication, deviceId, headers, additionalParams, resource, }: {
222
+ code: string;
223
+ redirectURI: string;
224
+ options: Partial<ProviderOptions>;
225
+ codeVerifier?: string;
226
+ deviceId?: string;
227
+ tokenEndpoint: string;
228
+ authentication?: "basic" | "post";
229
+ headers?: Record<string, string>;
230
+ additionalParams?: Record<string, string>;
231
+ resource?: string | string[];
232
+ }): Promise<OAuth2Tokens>;
233
+ declare function validateToken(token: string, jwksEndpoint: string): Promise<jose.JWTVerifyResult<jose.JWTPayload>>;
234
+
235
+ declare function createRefreshAccessTokenRequest({ refreshToken, options, authentication, extraParams, resource, }: {
236
+ refreshToken: string;
237
+ options: Partial<ProviderOptions>;
238
+ authentication?: "basic" | "post";
239
+ extraParams?: Record<string, string>;
240
+ resource?: string | string[];
241
+ }): {
242
+ body: URLSearchParams;
243
+ headers: Record<string, any>;
244
+ };
245
+ declare function refreshAccessToken({ refreshToken, options, tokenEndpoint, authentication, extraParams, }: {
246
+ refreshToken: string;
247
+ options: Partial<ProviderOptions>;
248
+ tokenEndpoint: string;
249
+ authentication?: "basic" | "post";
250
+ extraParams?: Record<string, string>;
251
+ /** @deprecated always "refresh_token" */
252
+ grantType?: string;
253
+ }): Promise<OAuth2Tokens>;
254
+
255
+ declare function createClientCredentialsTokenRequest({ options, scope, authentication, resource, }: {
256
+ options: ProviderOptions & {
257
+ clientSecret: string;
258
+ };
259
+ scope?: string;
260
+ authentication?: "basic" | "post";
261
+ resource?: string | string[];
262
+ }): {
263
+ body: URLSearchParams;
264
+ headers: Record<string, any>;
265
+ };
266
+ declare function clientCredentialsToken({ options, tokenEndpoint, scope, authentication, resource, }: {
267
+ options: ProviderOptions & {
268
+ clientSecret: string;
269
+ };
270
+ tokenEndpoint: string;
271
+ scope: string;
272
+ authentication?: "basic" | "post";
273
+ resource?: string | string[];
274
+ }): Promise<OAuth2Tokens>;
275
+
276
+ export { clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken };
277
+ export type { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions };