@better-auth/core 1.4.0-beta.9 → 1.4.0
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/.turbo/turbo-build.log +41 -76
- package/dist/api/index.d.mts +3 -0
- package/dist/api/index.mjs +26 -0
- package/dist/async_hooks/index.d.mts +2 -10
- package/dist/async_hooks/index.mjs +2 -24
- package/dist/async_hooks-BfRfbd1J.mjs +18 -0
- package/dist/context/index.d.mts +54 -0
- package/dist/context/index.mjs +4 -0
- package/dist/context-DgQ9XGBl.mjs +114 -0
- package/dist/db/adapter/index.d.mts +3 -14
- package/dist/db/adapter/index.mjs +1 -1
- package/dist/db/index.d.mts +3 -39
- package/dist/db/index.mjs +46 -55
- package/dist/env/index.d.mts +2 -36
- package/dist/env/index.mjs +2 -299
- package/dist/env-DwlNAN_D.mjs +245 -0
- package/dist/error/index.d.mts +31 -29
- package/dist/error/index.mjs +3 -40
- package/dist/error-BhAKg8LX.mjs +45 -0
- package/dist/index-CdubV7uy.d.mts +82 -0
- package/dist/index-CkAWdKH8.d.mts +7352 -0
- package/dist/index-DgwIISs7.d.mts +7 -0
- package/dist/index.d.mts +3 -180
- package/dist/index.mjs +1 -1
- package/dist/oauth2/index.d.mts +3 -99
- package/dist/oauth2/index.mjs +2 -356
- package/dist/oauth2-DmgZmPEg.mjs +236 -0
- package/dist/social-providers/index.d.mts +3 -3903
- package/dist/social-providers/index.mjs +2434 -2654
- package/dist/utils/index.d.mts +5 -6
- package/dist/utils/index.mjs +2 -4
- package/dist/utils-C5EN75oV.mjs +7 -0
- package/package.json +70 -111
- package/src/api/index.ts +53 -0
- package/src/async_hooks/index.ts +1 -9
- package/src/context/endpoint-context.ts +49 -0
- package/src/context/index.ts +21 -0
- package/src/context/request-state.test.ts +94 -0
- package/src/context/request-state.ts +90 -0
- package/src/context/transaction.ts +73 -0
- package/src/db/adapter/index.ts +215 -129
- package/src/db/index.ts +12 -13
- package/src/db/plugin.ts +3 -3
- package/src/db/type.ts +54 -42
- package/src/env/color-depth.ts +5 -4
- package/src/env/env-impl.ts +2 -1
- package/src/env/index.ts +9 -9
- package/src/env/logger.test.ts +3 -2
- package/src/env/logger.ts +11 -9
- package/src/error/codes.ts +1 -1
- package/src/error/index.ts +1 -1
- package/src/oauth2/client-credentials-token.ts +9 -9
- package/src/oauth2/create-authorization-url.ts +12 -12
- package/src/oauth2/index.ts +10 -11
- package/src/oauth2/oauth-provider.ts +96 -74
- package/src/oauth2/refresh-access-token.ts +12 -12
- package/src/oauth2/utils.ts +2 -0
- package/src/oauth2/validate-authorization-code.ts +13 -15
- package/src/social-providers/apple.ts +8 -8
- package/src/social-providers/atlassian.ts +21 -19
- package/src/social-providers/cognito.ts +15 -15
- package/src/social-providers/discord.ts +8 -11
- package/src/social-providers/dropbox.ts +5 -5
- package/src/social-providers/facebook.ts +12 -10
- package/src/social-providers/figma.ts +6 -6
- package/src/social-providers/github.ts +4 -4
- package/src/social-providers/gitlab.ts +13 -10
- package/src/social-providers/google.ts +13 -13
- package/src/social-providers/huggingface.ts +27 -25
- package/src/social-providers/index.ts +30 -24
- package/src/social-providers/kakao.ts +41 -41
- package/src/social-providers/kick.ts +7 -9
- package/src/social-providers/line.ts +12 -12
- package/src/social-providers/linear.ts +9 -8
- package/src/social-providers/linkedin.ts +5 -5
- package/src/social-providers/microsoft-entra-id.ts +31 -15
- package/src/social-providers/naver.ts +5 -5
- package/src/social-providers/notion.ts +11 -9
- package/src/social-providers/paybin.ts +122 -0
- package/src/social-providers/paypal.ts +31 -29
- package/src/social-providers/polar.ts +110 -0
- package/src/social-providers/reddit.ts +6 -6
- package/src/social-providers/roblox.ts +15 -14
- package/src/social-providers/salesforce.ts +20 -18
- package/src/social-providers/slack.ts +4 -7
- package/src/social-providers/spotify.ts +5 -5
- package/src/social-providers/tiktok.ts +32 -33
- package/src/social-providers/twitch.ts +8 -8
- package/src/social-providers/twitter.ts +49 -45
- package/src/social-providers/vk.ts +14 -17
- package/src/social-providers/zoom.ts +29 -14
- package/src/types/context.ts +67 -67
- package/src/types/cookie.ts +1 -0
- package/src/types/index.ts +13 -11
- package/src/types/init-options.ts +1134 -911
- package/src/types/plugin-client.ts +61 -13
- package/src/types/plugin.ts +81 -57
- package/tsconfig.json +2 -5
- package/{build.config.ts → tsdown.config.ts} +8 -11
- package/vitest.config.ts +3 -0
- package/dist/async_hooks/index.cjs +0 -27
- package/dist/async_hooks/index.d.cts +0 -10
- package/dist/async_hooks/index.d.ts +0 -10
- package/dist/db/adapter/index.cjs +0 -2
- package/dist/db/adapter/index.d.cts +0 -14
- package/dist/db/adapter/index.d.ts +0 -14
- package/dist/db/index.cjs +0 -91
- package/dist/db/index.d.cts +0 -39
- package/dist/db/index.d.ts +0 -39
- package/dist/env/index.cjs +0 -315
- package/dist/env/index.d.cts +0 -36
- package/dist/env/index.d.ts +0 -36
- package/dist/error/index.cjs +0 -44
- package/dist/error/index.d.cts +0 -33
- package/dist/error/index.d.ts +0 -33
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +0 -180
- package/dist/index.d.ts +0 -180
- package/dist/middleware/index.cjs +0 -25
- package/dist/middleware/index.d.cts +0 -14
- package/dist/middleware/index.d.mts +0 -14
- package/dist/middleware/index.d.ts +0 -14
- package/dist/middleware/index.mjs +0 -21
- package/dist/oauth2/index.cjs +0 -368
- package/dist/oauth2/index.d.cts +0 -99
- package/dist/oauth2/index.d.ts +0 -99
- package/dist/shared/core.2rWMW9q9.d.ts +0 -13
- package/dist/shared/core.40VTWh-p.d.cts +0 -217
- package/dist/shared/core.BfcVdsSf.d.cts +0 -181
- package/dist/shared/core.Bisb2Bdk.d.mts +0 -181
- package/dist/shared/core.BwoNUcJQ.d.cts +0 -53
- package/dist/shared/core.BwoNUcJQ.d.mts +0 -53
- package/dist/shared/core.BwoNUcJQ.d.ts +0 -53
- package/dist/shared/core.CErFRCOZ.d.mts +0 -1684
- package/dist/shared/core.CGN6D-Mh.d.ts +0 -181
- package/dist/shared/core.CPuIItYE.d.ts +0 -217
- package/dist/shared/core.CftpHMDz.d.cts +0 -13
- package/dist/shared/core.Db7zJyxf.d.ts +0 -1684
- package/dist/shared/core.DqaxObkf.d.cts +0 -1684
- package/dist/shared/core.MjcDoj7R.d.cts +0 -5
- package/dist/shared/core.MjcDoj7R.d.mts +0 -5
- package/dist/shared/core.MjcDoj7R.d.ts +0 -5
- package/dist/shared/core.g2ZbxAEV.d.mts +0 -217
- package/dist/shared/core.g9ACQ8v2.d.mts +0 -13
- package/dist/social-providers/index.cjs +0 -2793
- package/dist/social-providers/index.d.cts +0 -3903
- package/dist/social-providers/index.d.ts +0 -3903
- package/dist/utils/index.cjs +0 -7
- package/dist/utils/index.d.cts +0 -10
- package/dist/utils/index.d.ts +0 -10
- package/src/middleware/index.ts +0 -33
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import type { LiteralString } from "../types";
|
|
2
2
|
|
|
3
3
|
export interface OAuth2Tokens {
|
|
4
|
-
tokenType?: string;
|
|
5
|
-
accessToken?: string;
|
|
6
|
-
refreshToken?: string;
|
|
7
|
-
accessTokenExpiresAt?: Date;
|
|
8
|
-
refreshTokenExpiresAt?: Date;
|
|
9
|
-
scopes?: string[];
|
|
10
|
-
idToken?: string;
|
|
4
|
+
tokenType?: string | undefined;
|
|
5
|
+
accessToken?: string | undefined;
|
|
6
|
+
refreshToken?: string | undefined;
|
|
7
|
+
accessTokenExpiresAt?: Date | undefined;
|
|
8
|
+
refreshTokenExpiresAt?: Date | undefined;
|
|
9
|
+
scopes?: string[] | undefined;
|
|
10
|
+
idToken?: string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Raw token response from the provider.
|
|
13
|
+
* Preserves provider-specific fields that are not part of the standard OAuth2 token response.
|
|
14
|
+
*/
|
|
15
|
+
raw?: Record<string, unknown> | undefined;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export type OAuth2UserInfo = {
|
|
14
19
|
id: string | number;
|
|
15
|
-
name?: string;
|
|
16
|
-
email?: string | null;
|
|
17
|
-
image?: string;
|
|
20
|
+
name?: string | undefined;
|
|
21
|
+
email?: (string | null) | undefined;
|
|
22
|
+
image?: string | undefined;
|
|
18
23
|
emailVerified: boolean;
|
|
19
24
|
};
|
|
20
25
|
|
|
@@ -26,17 +31,17 @@ export interface OAuthProvider<
|
|
|
26
31
|
createAuthorizationURL: (data: {
|
|
27
32
|
state: string;
|
|
28
33
|
codeVerifier: string;
|
|
29
|
-
scopes?: string[];
|
|
34
|
+
scopes?: string[] | undefined;
|
|
30
35
|
redirectURI: string;
|
|
31
|
-
display?: string;
|
|
32
|
-
loginHint?: string;
|
|
36
|
+
display?: string | undefined;
|
|
37
|
+
loginHint?: string | undefined;
|
|
33
38
|
}) => Promise<URL> | URL;
|
|
34
39
|
name: string;
|
|
35
40
|
validateAuthorizationCode: (data: {
|
|
36
41
|
code: string;
|
|
37
42
|
redirectURI: string;
|
|
38
|
-
codeVerifier?: string;
|
|
39
|
-
deviceId?: string;
|
|
43
|
+
codeVerifier?: string | undefined;
|
|
44
|
+
deviceId?: string | undefined;
|
|
40
45
|
}) => Promise<OAuth2Tokens>;
|
|
41
46
|
getUserInfo: (
|
|
42
47
|
token: OAuth2Tokens & {
|
|
@@ -44,13 +49,15 @@ export interface OAuthProvider<
|
|
|
44
49
|
* The user object from the provider
|
|
45
50
|
* This is only available for some providers like Apple
|
|
46
51
|
*/
|
|
47
|
-
user?:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
user?:
|
|
53
|
+
| {
|
|
54
|
+
name?: {
|
|
55
|
+
firstName?: string;
|
|
56
|
+
lastName?: string;
|
|
57
|
+
};
|
|
58
|
+
email?: string;
|
|
59
|
+
}
|
|
60
|
+
| undefined;
|
|
54
61
|
},
|
|
55
62
|
) => Promise<{
|
|
56
63
|
user: OAuth2UserInfo;
|
|
@@ -59,28 +66,32 @@ export interface OAuthProvider<
|
|
|
59
66
|
/**
|
|
60
67
|
* Custom function to refresh a token
|
|
61
68
|
*/
|
|
62
|
-
refreshAccessToken?:
|
|
63
|
-
|
|
69
|
+
refreshAccessToken?:
|
|
70
|
+
| ((refreshToken: string) => Promise<OAuth2Tokens>)
|
|
71
|
+
| undefined;
|
|
72
|
+
revokeToken?: ((token: string) => Promise<void>) | undefined;
|
|
64
73
|
/**
|
|
65
74
|
* Verify the id token
|
|
66
75
|
* @param token - The id token
|
|
67
76
|
* @param nonce - The nonce
|
|
68
77
|
* @returns True if the id token is valid, false otherwise
|
|
69
78
|
*/
|
|
70
|
-
verifyIdToken?:
|
|
79
|
+
verifyIdToken?:
|
|
80
|
+
| ((token: string, nonce?: string) => Promise<boolean>)
|
|
81
|
+
| undefined;
|
|
71
82
|
/**
|
|
72
83
|
* Disable implicit sign up for new users. When set to true for the provider,
|
|
73
84
|
* sign-in need to be called with with requestSignUp as true to create new users.
|
|
74
85
|
*/
|
|
75
|
-
disableImplicitSignUp?: boolean;
|
|
86
|
+
disableImplicitSignUp?: boolean | undefined;
|
|
76
87
|
/**
|
|
77
88
|
* Disable sign up for new users.
|
|
78
89
|
*/
|
|
79
|
-
disableSignUp?: boolean;
|
|
90
|
+
disableSignUp?: boolean | undefined;
|
|
80
91
|
/**
|
|
81
92
|
* Options for the provider
|
|
82
93
|
*/
|
|
83
|
-
options?: O;
|
|
94
|
+
options?: O | undefined;
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
export type ProviderOptions<Profile extends Record<string, any> = any> = {
|
|
@@ -89,106 +100,117 @@ export type ProviderOptions<Profile extends Record<string, any> = any> = {
|
|
|
89
100
|
*
|
|
90
101
|
* This is usually a string but can be any type depending on the provider.
|
|
91
102
|
*/
|
|
92
|
-
clientId?: unknown;
|
|
103
|
+
clientId?: unknown | undefined;
|
|
93
104
|
/**
|
|
94
105
|
* The client secret of your application
|
|
95
106
|
*/
|
|
96
|
-
clientSecret?: string;
|
|
107
|
+
clientSecret?: string | undefined;
|
|
97
108
|
/**
|
|
98
109
|
* The scopes you want to request from the provider
|
|
99
110
|
*/
|
|
100
|
-
scope?: string[];
|
|
111
|
+
scope?: string[] | undefined;
|
|
101
112
|
/**
|
|
102
113
|
* Remove default scopes of the provider
|
|
103
114
|
*/
|
|
104
|
-
disableDefaultScope?: boolean;
|
|
115
|
+
disableDefaultScope?: boolean | undefined;
|
|
105
116
|
/**
|
|
106
117
|
* The redirect URL for your application. This is where the provider will
|
|
107
118
|
* redirect the user after the sign in process. Make sure this URL is
|
|
108
119
|
* whitelisted in the provider's dashboard.
|
|
109
120
|
*/
|
|
110
|
-
redirectURI?: string;
|
|
121
|
+
redirectURI?: string | undefined;
|
|
111
122
|
/**
|
|
112
123
|
* The client key of your application
|
|
113
124
|
* Tiktok Social Provider uses this field instead of clientId
|
|
114
125
|
*/
|
|
115
|
-
clientKey?: string;
|
|
126
|
+
clientKey?: string | undefined;
|
|
116
127
|
/**
|
|
117
128
|
* Disable provider from allowing users to sign in
|
|
118
129
|
* with this provider with an id token sent from the
|
|
119
130
|
* client.
|
|
120
131
|
*/
|
|
121
|
-
disableIdTokenSignIn?: boolean;
|
|
132
|
+
disableIdTokenSignIn?: boolean | undefined;
|
|
122
133
|
/**
|
|
123
134
|
* verifyIdToken function to verify the id token
|
|
124
135
|
*/
|
|
125
|
-
verifyIdToken?:
|
|
136
|
+
verifyIdToken?:
|
|
137
|
+
| ((token: string, nonce?: string) => Promise<boolean>)
|
|
138
|
+
| undefined;
|
|
126
139
|
/**
|
|
127
140
|
* Custom function to get user info from the provider
|
|
128
141
|
*/
|
|
129
|
-
getUserInfo?:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
142
|
+
getUserInfo?:
|
|
143
|
+
| ((token: OAuth2Tokens) => Promise<{
|
|
144
|
+
user: {
|
|
145
|
+
id: string;
|
|
146
|
+
name?: string;
|
|
147
|
+
email?: string | null;
|
|
148
|
+
image?: string;
|
|
149
|
+
emailVerified: boolean;
|
|
150
|
+
[key: string]: any;
|
|
151
|
+
};
|
|
152
|
+
data: any;
|
|
153
|
+
}>)
|
|
154
|
+
| undefined;
|
|
140
155
|
/**
|
|
141
156
|
* Custom function to refresh a token
|
|
142
157
|
*/
|
|
143
|
-
refreshAccessToken?:
|
|
158
|
+
refreshAccessToken?:
|
|
159
|
+
| ((refreshToken: string) => Promise<OAuth2Tokens>)
|
|
160
|
+
| undefined;
|
|
144
161
|
/**
|
|
145
162
|
* Custom function to map the provider profile to a
|
|
146
163
|
* user.
|
|
147
164
|
*/
|
|
148
|
-
mapProfileToUser?:
|
|
149
|
-
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
mapProfileToUser?:
|
|
166
|
+
| ((profile: Profile) =>
|
|
167
|
+
| {
|
|
168
|
+
id?: string;
|
|
169
|
+
name?: string;
|
|
170
|
+
email?: string | null;
|
|
171
|
+
image?: string;
|
|
172
|
+
emailVerified?: boolean;
|
|
173
|
+
[key: string]: any;
|
|
174
|
+
}
|
|
175
|
+
| Promise<{
|
|
176
|
+
id?: string;
|
|
177
|
+
name?: string;
|
|
178
|
+
email?: string | null;
|
|
179
|
+
image?: string;
|
|
180
|
+
emailVerified?: boolean;
|
|
181
|
+
[key: string]: any;
|
|
182
|
+
}>)
|
|
183
|
+
| undefined;
|
|
165
184
|
/**
|
|
166
185
|
* Disable implicit sign up for new users. When set to true for the provider,
|
|
167
186
|
* sign-in need to be called with with requestSignUp as true to create new users.
|
|
168
187
|
*/
|
|
169
|
-
disableImplicitSignUp?: boolean;
|
|
188
|
+
disableImplicitSignUp?: boolean | undefined;
|
|
170
189
|
/**
|
|
171
190
|
* Disable sign up for new users.
|
|
172
191
|
*/
|
|
173
|
-
disableSignUp?: boolean;
|
|
192
|
+
disableSignUp?: boolean | undefined;
|
|
174
193
|
/**
|
|
175
194
|
* The prompt to use for the authorization code request
|
|
176
195
|
*/
|
|
177
196
|
prompt?:
|
|
178
|
-
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
197
|
+
| (
|
|
198
|
+
| "select_account"
|
|
199
|
+
| "consent"
|
|
200
|
+
| "login"
|
|
201
|
+
| "none"
|
|
202
|
+
| "select_account consent"
|
|
203
|
+
)
|
|
204
|
+
| undefined;
|
|
183
205
|
/**
|
|
184
206
|
* The response mode to use for the authorization code request
|
|
185
207
|
*/
|
|
186
|
-
responseMode?: "query" | "form_post";
|
|
208
|
+
responseMode?: ("query" | "form_post") | undefined;
|
|
187
209
|
/**
|
|
188
210
|
* If enabled, the user info will be overridden with the provider user info
|
|
189
211
|
* This is useful if you want to use the provider user info to update the user info
|
|
190
212
|
*
|
|
191
213
|
* @default false
|
|
192
214
|
*/
|
|
193
|
-
overrideUserInfoOnSignIn?: boolean;
|
|
215
|
+
overrideUserInfoOnSignIn?: boolean | undefined;
|
|
194
216
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { base64 } from "@better-auth/utils/base64";
|
|
1
2
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
3
|
import type { OAuth2Tokens, ProviderOptions } from "./oauth-provider";
|
|
3
|
-
import { base64 } from "@better-auth/utils/base64";
|
|
4
4
|
|
|
5
5
|
export function createRefreshAccessTokenRequest({
|
|
6
6
|
refreshToken,
|
|
@@ -11,9 +11,9 @@ export function createRefreshAccessTokenRequest({
|
|
|
11
11
|
}: {
|
|
12
12
|
refreshToken: string;
|
|
13
13
|
options: Partial<ProviderOptions>;
|
|
14
|
-
authentication?: "basic" | "post";
|
|
15
|
-
extraParams?: Record<string, string
|
|
16
|
-
resource?: string | string[];
|
|
14
|
+
authentication?: ("basic" | "post") | undefined;
|
|
15
|
+
extraParams?: Record<string, string> | undefined;
|
|
16
|
+
resource?: (string | string[]) | undefined;
|
|
17
17
|
}) {
|
|
18
18
|
const body = new URLSearchParams();
|
|
19
19
|
const headers: Record<string, any> = {
|
|
@@ -78,10 +78,10 @@ export async function refreshAccessToken({
|
|
|
78
78
|
refreshToken: string;
|
|
79
79
|
options: Partial<ProviderOptions>;
|
|
80
80
|
tokenEndpoint: string;
|
|
81
|
-
authentication?: "basic" | "post";
|
|
82
|
-
extraParams?: Record<string, string
|
|
81
|
+
authentication?: ("basic" | "post") | undefined;
|
|
82
|
+
extraParams?: Record<string, string> | undefined;
|
|
83
83
|
/** @deprecated always "refresh_token" */
|
|
84
|
-
grantType?: string;
|
|
84
|
+
grantType?: string | undefined;
|
|
85
85
|
}): Promise<OAuth2Tokens> {
|
|
86
86
|
const { body, headers } = createRefreshAccessTokenRequest({
|
|
87
87
|
refreshToken,
|
|
@@ -92,11 +92,11 @@ export async function refreshAccessToken({
|
|
|
92
92
|
|
|
93
93
|
const { data, error } = await betterFetch<{
|
|
94
94
|
access_token: string;
|
|
95
|
-
refresh_token?: string;
|
|
96
|
-
expires_in?: number;
|
|
97
|
-
token_type?: string;
|
|
98
|
-
scope?: string;
|
|
99
|
-
id_token?: string;
|
|
95
|
+
refresh_token?: string | undefined;
|
|
96
|
+
expires_in?: number | undefined;
|
|
97
|
+
token_type?: string | undefined;
|
|
98
|
+
scope?: string | undefined;
|
|
99
|
+
id_token?: string | undefined;
|
|
100
100
|
}>(tokenEndpoint, {
|
|
101
101
|
method: "POST",
|
|
102
102
|
body,
|
package/src/oauth2/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { base64 } from "@better-auth/utils/base64";
|
|
1
2
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
3
|
import { jwtVerify } from "jose";
|
|
3
4
|
import type { ProviderOptions } from "./index";
|
|
4
5
|
import { getOAuth2Tokens } from "./index";
|
|
5
|
-
import { base64 } from "@better-auth/utils/base64";
|
|
6
6
|
|
|
7
7
|
export function createAuthorizationCodeRequest({
|
|
8
8
|
code,
|
|
@@ -18,18 +18,17 @@ export function createAuthorizationCodeRequest({
|
|
|
18
18
|
code: string;
|
|
19
19
|
redirectURI: string;
|
|
20
20
|
options: Partial<ProviderOptions>;
|
|
21
|
-
codeVerifier?: string;
|
|
22
|
-
deviceId?: string;
|
|
23
|
-
authentication?: "basic" | "post";
|
|
24
|
-
headers?: Record<string, string
|
|
25
|
-
additionalParams?: Record<string, string
|
|
26
|
-
resource?: string | string[];
|
|
21
|
+
codeVerifier?: string | undefined;
|
|
22
|
+
deviceId?: string | undefined;
|
|
23
|
+
authentication?: ("basic" | "post") | undefined;
|
|
24
|
+
headers?: Record<string, string> | undefined;
|
|
25
|
+
additionalParams?: Record<string, string> | undefined;
|
|
26
|
+
resource?: (string | string[]) | undefined;
|
|
27
27
|
}) {
|
|
28
28
|
const body = new URLSearchParams();
|
|
29
29
|
const requestHeaders: Record<string, any> = {
|
|
30
30
|
"content-type": "application/x-www-form-urlencoded",
|
|
31
31
|
accept: "application/json",
|
|
32
|
-
"user-agent": "better-auth",
|
|
33
32
|
...headers,
|
|
34
33
|
};
|
|
35
34
|
body.set("grant_type", "authorization_code");
|
|
@@ -92,13 +91,13 @@ export async function validateAuthorizationCode({
|
|
|
92
91
|
code: string;
|
|
93
92
|
redirectURI: string;
|
|
94
93
|
options: Partial<ProviderOptions>;
|
|
95
|
-
codeVerifier?: string;
|
|
96
|
-
deviceId?: string;
|
|
94
|
+
codeVerifier?: string | undefined;
|
|
95
|
+
deviceId?: string | undefined;
|
|
97
96
|
tokenEndpoint: string;
|
|
98
|
-
authentication?: "basic" | "post";
|
|
99
|
-
headers?: Record<string, string
|
|
100
|
-
additionalParams?: Record<string, string
|
|
101
|
-
resource?: string | string[];
|
|
97
|
+
authentication?: ("basic" | "post") | undefined;
|
|
98
|
+
headers?: Record<string, string> | undefined;
|
|
99
|
+
additionalParams?: Record<string, string> | undefined;
|
|
100
|
+
resource?: (string | string[]) | undefined;
|
|
102
101
|
}) {
|
|
103
102
|
const { body, headers: requestHeaders } = createAuthorizationCodeRequest({
|
|
104
103
|
code,
|
|
@@ -139,7 +138,6 @@ export async function validateToken(token: string, jwksEndpoint: string) {
|
|
|
139
138
|
method: "GET",
|
|
140
139
|
headers: {
|
|
141
140
|
accept: "application/json",
|
|
142
|
-
"user-agent": "better-auth",
|
|
143
141
|
},
|
|
144
142
|
});
|
|
145
143
|
if (error) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
2
|
import { APIError } from "better-call";
|
|
3
3
|
import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
4
|
-
import type { OAuthProvider, ProviderOptions } from "
|
|
4
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
5
5
|
import {
|
|
6
|
-
refreshAccessToken,
|
|
7
6
|
createAuthorizationURL,
|
|
7
|
+
refreshAccessToken,
|
|
8
8
|
validateAuthorizationCode,
|
|
9
|
-
} from "
|
|
9
|
+
} from "../oauth2";
|
|
10
10
|
export interface AppleProfile {
|
|
11
11
|
/**
|
|
12
12
|
* The subject registered claim identifies the principal that’s the subject
|
|
@@ -52,7 +52,7 @@ export interface AppleProfile {
|
|
|
52
52
|
* The URL to the user's profile picture.
|
|
53
53
|
*/
|
|
54
54
|
picture: string;
|
|
55
|
-
user?: AppleNonConformUser;
|
|
55
|
+
user?: AppleNonConformUser | undefined;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -70,8 +70,8 @@ export interface AppleNonConformUser {
|
|
|
70
70
|
|
|
71
71
|
export interface AppleOptions extends ProviderOptions<AppleProfile> {
|
|
72
72
|
clientId: string;
|
|
73
|
-
appBundleIdentifier?: string;
|
|
74
|
-
audience?: string | string[];
|
|
73
|
+
appBundleIdentifier?: string | undefined;
|
|
74
|
+
audience?: (string | string[]) | undefined;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export const apple = (options: AppleOptions) => {
|
|
@@ -81,8 +81,8 @@ export const apple = (options: AppleOptions) => {
|
|
|
81
81
|
name: "Apple",
|
|
82
82
|
async createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
83
83
|
const _scope = options.disableDefaultScope ? [] : ["email", "name"];
|
|
84
|
-
options.scope
|
|
85
|
-
scopes
|
|
84
|
+
if (options.scope) _scope.push(...options.scope);
|
|
85
|
+
if (scopes) _scope.push(...scopes);
|
|
86
86
|
const url = await createAuthorizationURL({
|
|
87
87
|
id: "apple",
|
|
88
88
|
options,
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import { logger } from "../env";
|
|
2
3
|
import { BetterAuthError } from "../error";
|
|
3
|
-
import type { OAuthProvider, ProviderOptions } from "
|
|
4
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
4
5
|
import {
|
|
5
6
|
createAuthorizationURL,
|
|
7
|
+
refreshAccessToken,
|
|
6
8
|
validateAuthorizationCode,
|
|
7
|
-
} from "
|
|
8
|
-
import { logger } from "@better-auth/core/env";
|
|
9
|
-
import { refreshAccessToken } from "@better-auth/core/oauth2";
|
|
9
|
+
} from "../oauth2";
|
|
10
10
|
|
|
11
11
|
export interface AtlassianProfile {
|
|
12
|
-
account_type?: string;
|
|
12
|
+
account_type?: string | undefined;
|
|
13
13
|
account_id: string;
|
|
14
|
-
email?: string;
|
|
14
|
+
email?: string | undefined;
|
|
15
15
|
name: string;
|
|
16
|
-
picture?: string;
|
|
17
|
-
nickname?: string;
|
|
18
|
-
locale?: string;
|
|
19
|
-
extended_profile?:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
picture?: string | undefined;
|
|
17
|
+
nickname?: string | undefined;
|
|
18
|
+
locale?: string | undefined;
|
|
19
|
+
extended_profile?:
|
|
20
|
+
| {
|
|
21
|
+
job_title?: string;
|
|
22
|
+
organization?: string;
|
|
23
|
+
department?: string;
|
|
24
|
+
location?: string;
|
|
25
|
+
}
|
|
26
|
+
| undefined;
|
|
25
27
|
}
|
|
26
28
|
export interface AtlassianOptions extends ProviderOptions<AtlassianProfile> {
|
|
27
29
|
clientId: string;
|
|
@@ -44,8 +46,8 @@ export const atlassian = (options: AtlassianOptions) => {
|
|
|
44
46
|
const _scopes = options.disableDefaultScope
|
|
45
47
|
? []
|
|
46
48
|
: ["read:jira-user", "offline_access"];
|
|
47
|
-
options.scope
|
|
48
|
-
scopes
|
|
49
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
50
|
+
if (scopes) _scopes.push(...scopes);
|
|
49
51
|
|
|
50
52
|
return createAuthorizationURL({
|
|
51
53
|
id: "atlassian",
|
|
@@ -98,8 +100,8 @@ export const atlassian = (options: AtlassianOptions) => {
|
|
|
98
100
|
const { data: profile } = await betterFetch<{
|
|
99
101
|
account_id: string;
|
|
100
102
|
name: string;
|
|
101
|
-
email?: string;
|
|
102
|
-
picture?: string;
|
|
103
|
+
email?: string | undefined;
|
|
104
|
+
picture?: string | undefined;
|
|
103
105
|
}>("https://api.atlassian.com/me", {
|
|
104
106
|
headers: { Authorization: `Bearer ${token.accessToken}` },
|
|
105
107
|
});
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import { APIError } from "better-call";
|
|
2
3
|
import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
4
|
+
import { logger } from "../env";
|
|
3
5
|
import { BetterAuthError } from "../error";
|
|
4
|
-
import type { OAuthProvider, ProviderOptions } from "
|
|
6
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
5
7
|
import {
|
|
6
8
|
createAuthorizationURL,
|
|
9
|
+
refreshAccessToken,
|
|
7
10
|
validateAuthorizationCode,
|
|
8
|
-
} from "
|
|
9
|
-
import { logger } from "@better-auth/core/env";
|
|
10
|
-
import { refreshAccessToken } from "@better-auth/core/oauth2";
|
|
11
|
-
import { APIError } from "better-call";
|
|
11
|
+
} from "../oauth2";
|
|
12
12
|
|
|
13
13
|
export interface CognitoProfile {
|
|
14
14
|
sub: string;
|
|
15
15
|
email: string;
|
|
16
16
|
email_verified: boolean;
|
|
17
17
|
name: string;
|
|
18
|
-
given_name?: string;
|
|
19
|
-
family_name?: string;
|
|
20
|
-
picture?: string;
|
|
21
|
-
username?: string;
|
|
22
|
-
locale?: string;
|
|
23
|
-
phone_number?: string;
|
|
24
|
-
phone_number_verified?: boolean;
|
|
18
|
+
given_name?: string | undefined;
|
|
19
|
+
family_name?: string | undefined;
|
|
20
|
+
picture?: string | undefined;
|
|
21
|
+
username?: string | undefined;
|
|
22
|
+
locale?: string | undefined;
|
|
23
|
+
phone_number?: string | undefined;
|
|
24
|
+
phone_number_verified?: boolean | undefined;
|
|
25
25
|
aud: string;
|
|
26
26
|
iss: string;
|
|
27
27
|
exp: number;
|
|
@@ -41,7 +41,7 @@ export interface CognitoOptions extends ProviderOptions<CognitoProfile> {
|
|
|
41
41
|
*/
|
|
42
42
|
region: string;
|
|
43
43
|
userPoolId: string;
|
|
44
|
-
requireClientSecret?: boolean;
|
|
44
|
+
requireClientSecret?: boolean | undefined;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export const cognito = (options: CognitoOptions) => {
|
|
@@ -77,8 +77,8 @@ export const cognito = (options: CognitoOptions) => {
|
|
|
77
77
|
const _scopes = options.disableDefaultScope
|
|
78
78
|
? []
|
|
79
79
|
: ["openid", "profile", "email"];
|
|
80
|
-
options.scope
|
|
81
|
-
scopes
|
|
80
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
81
|
+
if (scopes) _scopes.push(...scopes);
|
|
82
82
|
|
|
83
83
|
const url = await createAuthorizationURL({
|
|
84
84
|
id: "cognito",
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
import type { OAuthProvider, ProviderOptions } from "
|
|
3
|
-
import {
|
|
4
|
-
refreshAccessToken,
|
|
5
|
-
validateAuthorizationCode,
|
|
6
|
-
} from "@better-auth/core/oauth2";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import { refreshAccessToken, validateAuthorizationCode } from "../oauth2";
|
|
7
4
|
export interface DiscordProfile extends Record<string, any> {
|
|
8
5
|
/** the user's id (i.e. the numerical snowflake) */
|
|
9
6
|
id: string;
|
|
@@ -19,12 +16,12 @@ export interface DiscordProfile extends Record<string, any> {
|
|
|
19
16
|
*/
|
|
20
17
|
avatar: string | null;
|
|
21
18
|
/** whether the user belongs to an OAuth2 application */
|
|
22
|
-
bot?: boolean;
|
|
19
|
+
bot?: boolean | undefined;
|
|
23
20
|
/**
|
|
24
21
|
* whether the user is an Official Discord System user (part of the urgent
|
|
25
22
|
* message system)
|
|
26
23
|
*/
|
|
27
|
-
system?: boolean;
|
|
24
|
+
system?: boolean | undefined;
|
|
28
25
|
/** whether the user has two factor enabled on their account */
|
|
29
26
|
mfa_enabled: boolean;
|
|
30
27
|
/**
|
|
@@ -78,8 +75,8 @@ export interface DiscordProfile extends Record<string, any> {
|
|
|
78
75
|
|
|
79
76
|
export interface DiscordOptions extends ProviderOptions<DiscordProfile> {
|
|
80
77
|
clientId: string;
|
|
81
|
-
prompt?: "none" | "consent";
|
|
82
|
-
permissions?: number;
|
|
78
|
+
prompt?: ("none" | "consent") | undefined;
|
|
79
|
+
permissions?: number | undefined;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
export const discord = (options: DiscordOptions) => {
|
|
@@ -88,8 +85,8 @@ export const discord = (options: DiscordOptions) => {
|
|
|
88
85
|
name: "Discord",
|
|
89
86
|
createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
90
87
|
const _scopes = options.disableDefaultScope ? [] : ["identify", "email"];
|
|
91
|
-
scopes
|
|
92
|
-
options.scope
|
|
88
|
+
if (scopes) _scopes.push(...scopes);
|
|
89
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
93
90
|
const hasBotScope = _scopes.includes("bot");
|
|
94
91
|
const permissionsParam =
|
|
95
92
|
hasBotScope && options.permissions !== undefined
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
import type { OAuthProvider, ProviderOptions } from "
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
3
|
import {
|
|
4
4
|
createAuthorizationURL,
|
|
5
5
|
refreshAccessToken,
|
|
6
6
|
validateAuthorizationCode,
|
|
7
|
-
} from "
|
|
7
|
+
} from "../oauth2";
|
|
8
8
|
|
|
9
9
|
export interface DropboxProfile {
|
|
10
10
|
account_id: string;
|
|
@@ -22,7 +22,7 @@ export interface DropboxProfile {
|
|
|
22
22
|
|
|
23
23
|
export interface DropboxOptions extends ProviderOptions<DropboxProfile> {
|
|
24
24
|
clientId: string;
|
|
25
|
-
accessType?: "offline" | "online" | "legacy";
|
|
25
|
+
accessType?: ("offline" | "online" | "legacy") | undefined;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export const dropbox = (options: DropboxOptions) => {
|
|
@@ -38,8 +38,8 @@ export const dropbox = (options: DropboxOptions) => {
|
|
|
38
38
|
redirectURI,
|
|
39
39
|
}) => {
|
|
40
40
|
const _scopes = options.disableDefaultScope ? [] : ["account_info.read"];
|
|
41
|
-
options.scope
|
|
42
|
-
scopes
|
|
41
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
42
|
+
if (scopes) _scopes.push(...scopes);
|
|
43
43
|
const additionalParams: Record<string, string> = {};
|
|
44
44
|
if (options.accessType) {
|
|
45
45
|
additionalParams.token_access_type = options.accessType;
|