@better-auth/core 1.3.27 → 1.3.29
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 +54 -4
- package/build.config.ts +6 -0
- package/dist/db/adapter/index.d.cts +13 -23
- package/dist/db/adapter/index.d.mts +13 -23
- package/dist/db/adapter/index.d.ts +13 -23
- package/dist/db/index.cjs +16 -0
- package/dist/db/index.d.cts +6 -83
- package/dist/db/index.d.mts +6 -83
- package/dist/db/index.d.ts +6 -83
- package/dist/db/index.mjs +16 -1
- package/dist/env/index.cjs +312 -0
- package/dist/env/index.d.cts +36 -0
- package/dist/env/index.d.mts +36 -0
- package/dist/env/index.d.ts +36 -0
- package/dist/env/index.mjs +297 -0
- package/dist/error/index.cjs +44 -0
- package/dist/error/index.d.cts +33 -0
- package/dist/error/index.d.mts +33 -0
- package/dist/error/index.d.ts +33 -0
- package/dist/error/index.mjs +41 -0
- package/dist/index.d.cts +156 -101
- package/dist/index.d.mts +156 -101
- package/dist/index.d.ts +156 -101
- package/dist/middleware/index.cjs +25 -0
- package/dist/middleware/index.d.cts +13 -0
- package/dist/middleware/index.d.mts +13 -0
- package/dist/middleware/index.d.ts +13 -0
- package/dist/middleware/index.mjs +21 -0
- package/dist/oauth2/index.cjs +368 -0
- package/dist/oauth2/index.d.cts +100 -0
- package/dist/oauth2/index.d.mts +100 -0
- package/dist/oauth2/index.d.ts +100 -0
- package/dist/oauth2/index.mjs +357 -0
- package/dist/shared/core.Bl6TpxyD.d.mts +181 -0
- package/dist/shared/core.Bqe5IGAi.d.ts +13 -0
- package/dist/shared/core.Bshk2o_x.d.ts +1721 -0
- package/dist/shared/core.BwoNUcJQ.d.cts +53 -0
- package/dist/shared/core.BwoNUcJQ.d.mts +53 -0
- package/dist/shared/core.BwoNUcJQ.d.ts +53 -0
- package/dist/shared/core.C6_2xGyf.d.mts +1721 -0
- package/dist/shared/{core.CnvFgghY.d.cts → core.CajxAutx.d.cts} +27 -1
- package/dist/shared/{core.CnvFgghY.d.mts → core.CajxAutx.d.mts} +27 -1
- package/dist/shared/{core.CnvFgghY.d.ts → core.CajxAutx.d.ts} +27 -1
- package/dist/shared/core.CfqdiZTu.d.cts +1721 -0
- package/dist/shared/core.DkdZ1o38.d.ts +181 -0
- package/dist/shared/core.Dl-70uns.d.cts +84 -0
- package/dist/shared/core.Dl-70uns.d.mts +84 -0
- package/dist/shared/core.Dl-70uns.d.ts +84 -0
- package/dist/shared/core.DyEdx0m7.d.cts +181 -0
- package/dist/shared/core.E9DfzGLz.d.mts +13 -0
- package/dist/shared/core.HqYn20Fi.d.cts +13 -0
- package/dist/social-providers/index.cjs +2793 -0
- package/dist/social-providers/index.d.cts +3903 -0
- package/dist/social-providers/index.d.mts +3903 -0
- package/dist/social-providers/index.d.ts +3903 -0
- package/dist/social-providers/index.mjs +2743 -0
- package/dist/utils/index.cjs +7 -0
- package/dist/utils/index.d.cts +10 -0
- package/dist/utils/index.d.mts +10 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.mjs +5 -0
- package/package.json +98 -2
- package/src/db/adapter/index.ts +424 -0
- package/src/db/index.ts +2 -0
- package/src/db/schema/rate-limit.ts +21 -0
- package/src/db/type.ts +28 -0
- package/src/env/color-depth.ts +172 -0
- package/src/env/env-impl.ts +124 -0
- package/src/env/index.ts +23 -0
- package/src/env/logger.test.ts +33 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +31 -0
- package/src/error/index.ts +11 -0
- package/src/index.ts +0 -2
- package/src/middleware/index.ts +33 -0
- package/src/oauth2/client-credentials-token.ts +102 -0
- package/src/oauth2/create-authorization-url.ts +85 -0
- package/src/oauth2/index.ts +22 -0
- package/src/oauth2/oauth-provider.ts +194 -0
- package/src/oauth2/refresh-access-token.ts +124 -0
- package/src/oauth2/utils.ts +36 -0
- package/src/oauth2/validate-authorization-code.ts +156 -0
- package/src/social-providers/apple.ts +213 -0
- package/src/social-providers/atlassian.ts +130 -0
- package/src/social-providers/cognito.ts +269 -0
- package/src/social-providers/discord.ts +172 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +204 -0
- package/src/social-providers/figma.ts +115 -0
- package/src/social-providers/github.ts +154 -0
- package/src/social-providers/gitlab.ts +152 -0
- package/src/social-providers/google.ts +171 -0
- package/src/social-providers/huggingface.ts +116 -0
- package/src/social-providers/index.ts +118 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +95 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +120 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +243 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +106 -0
- package/src/social-providers/paypal.ts +261 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +110 -0
- package/src/social-providers/salesforce.ts +157 -0
- package/src/social-providers/slack.ts +114 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +211 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +194 -0
- package/src/social-providers/vk.ts +128 -0
- package/src/social-providers/zoom.ts +218 -0
- package/src/types/context.ts +334 -0
- package/src/types/cookie.ts +7 -0
- package/src/types/index.ts +19 -1
- package/src/types/init-options.ts +1048 -2
- package/src/types/plugin-client.ts +69 -0
- package/src/types/plugin.ts +134 -0
- package/src/utils/error-codes.ts +51 -0
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
validateAuthorizationCode,
|
|
6
|
+
refreshAccessToken,
|
|
7
|
+
} from "@better-auth/core/oauth2";
|
|
8
|
+
|
|
9
|
+
interface Partner {
|
|
10
|
+
/** Partner-specific ID (consent required: kakaotalk_message) */
|
|
11
|
+
uuid?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Profile {
|
|
15
|
+
/** Nickname (consent required: profile/nickname) */
|
|
16
|
+
nickname?: string;
|
|
17
|
+
/** Thumbnail image URL (consent required: profile/profile image) */
|
|
18
|
+
thumbnail_image_url?: string;
|
|
19
|
+
/** Profile image URL (consent required: profile/profile image) */
|
|
20
|
+
profile_image_url?: string;
|
|
21
|
+
/** Whether the profile image is the default */
|
|
22
|
+
is_default_image?: boolean;
|
|
23
|
+
/** Whether the nickname is the default */
|
|
24
|
+
is_default_nickname?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface KakaoAccount {
|
|
28
|
+
/** Consent required: profile info (nickname/profile image) */
|
|
29
|
+
profile_needs_agreement?: boolean;
|
|
30
|
+
/** Consent required: nickname */
|
|
31
|
+
profile_nickname_needs_agreement?: boolean;
|
|
32
|
+
/** Consent required: profile image */
|
|
33
|
+
profile_image_needs_agreement?: boolean;
|
|
34
|
+
/** Profile info */
|
|
35
|
+
profile?: Profile;
|
|
36
|
+
/** Consent required: name */
|
|
37
|
+
name_needs_agreement?: boolean;
|
|
38
|
+
/** Name */
|
|
39
|
+
name?: string;
|
|
40
|
+
/** Consent required: email */
|
|
41
|
+
email_needs_agreement?: boolean;
|
|
42
|
+
/** Email valid */
|
|
43
|
+
is_email_valid?: boolean;
|
|
44
|
+
/** Email verified */
|
|
45
|
+
is_email_verified?: boolean;
|
|
46
|
+
/** Email */
|
|
47
|
+
email?: string;
|
|
48
|
+
/** Consent required: age range */
|
|
49
|
+
age_range_needs_agreement?: boolean;
|
|
50
|
+
/** Age range */
|
|
51
|
+
age_range?: string;
|
|
52
|
+
/** Consent required: birth year */
|
|
53
|
+
birthyear_needs_agreement?: boolean;
|
|
54
|
+
/** Birth year (YYYY) */
|
|
55
|
+
birthyear?: string;
|
|
56
|
+
/** Consent required: birthday */
|
|
57
|
+
birthday_needs_agreement?: boolean;
|
|
58
|
+
/** Birthday (MMDD) */
|
|
59
|
+
birthday?: string;
|
|
60
|
+
/** Birthday type (SOLAR/LUNAR) */
|
|
61
|
+
birthday_type?: string;
|
|
62
|
+
/** Whether birthday is in a leap month */
|
|
63
|
+
is_leap_month?: boolean;
|
|
64
|
+
/** Consent required: gender */
|
|
65
|
+
gender_needs_agreement?: boolean;
|
|
66
|
+
/** Gender (male/female) */
|
|
67
|
+
gender?: string;
|
|
68
|
+
/** Consent required: phone number */
|
|
69
|
+
phone_number_needs_agreement?: boolean;
|
|
70
|
+
/** Phone number */
|
|
71
|
+
phone_number?: string;
|
|
72
|
+
/** Consent required: CI */
|
|
73
|
+
ci_needs_agreement?: boolean;
|
|
74
|
+
/** CI (unique identifier) */
|
|
75
|
+
ci?: string;
|
|
76
|
+
/** CI authentication time (UTC) */
|
|
77
|
+
ci_authenticated_at?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface KakaoProfile {
|
|
81
|
+
/** Kakao user ID */
|
|
82
|
+
id: number;
|
|
83
|
+
/**
|
|
84
|
+
* Whether the user has signed up (only present if auto-connection is disabled)
|
|
85
|
+
* false: preregistered, true: registered
|
|
86
|
+
*/
|
|
87
|
+
has_signed_up?: boolean;
|
|
88
|
+
/** UTC datetime when the user connected the service */
|
|
89
|
+
connected_at?: string;
|
|
90
|
+
/** UTC datetime when the user signed up via Kakao Sync */
|
|
91
|
+
synched_at?: string;
|
|
92
|
+
/** Custom user properties */
|
|
93
|
+
properties?: Record<string, any>;
|
|
94
|
+
/** Kakao account info */
|
|
95
|
+
kakao_account: KakaoAccount;
|
|
96
|
+
/** Partner info */
|
|
97
|
+
for_partner?: Partner;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface KakaoOptions extends ProviderOptions<KakaoProfile> {
|
|
101
|
+
clientId: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const kakao = (options: KakaoOptions) => {
|
|
105
|
+
return {
|
|
106
|
+
id: "kakao",
|
|
107
|
+
name: "Kakao",
|
|
108
|
+
createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
109
|
+
const _scopes = options.disableDefaultScope
|
|
110
|
+
? []
|
|
111
|
+
: ["account_email", "profile_image", "profile_nickname"];
|
|
112
|
+
options.scope && _scopes.push(...options.scope);
|
|
113
|
+
scopes && _scopes.push(...scopes);
|
|
114
|
+
return createAuthorizationURL({
|
|
115
|
+
id: "kakao",
|
|
116
|
+
options,
|
|
117
|
+
authorizationEndpoint: "https://kauth.kakao.com/oauth/authorize",
|
|
118
|
+
scopes: _scopes,
|
|
119
|
+
state,
|
|
120
|
+
redirectURI,
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
124
|
+
return validateAuthorizationCode({
|
|
125
|
+
code,
|
|
126
|
+
redirectURI,
|
|
127
|
+
options,
|
|
128
|
+
tokenEndpoint: "https://kauth.kakao.com/oauth/token",
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
refreshAccessToken: options.refreshAccessToken
|
|
132
|
+
? options.refreshAccessToken
|
|
133
|
+
: async (refreshToken) => {
|
|
134
|
+
return refreshAccessToken({
|
|
135
|
+
refreshToken,
|
|
136
|
+
options: {
|
|
137
|
+
clientId: options.clientId,
|
|
138
|
+
clientKey: options.clientKey,
|
|
139
|
+
clientSecret: options.clientSecret,
|
|
140
|
+
},
|
|
141
|
+
tokenEndpoint: "https://kauth.kakao.com/oauth/token",
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
async getUserInfo(token) {
|
|
145
|
+
if (options.getUserInfo) {
|
|
146
|
+
return options.getUserInfo(token);
|
|
147
|
+
}
|
|
148
|
+
const { data: profile, error } = await betterFetch<KakaoProfile>(
|
|
149
|
+
"https://kapi.kakao.com/v2/user/me",
|
|
150
|
+
{
|
|
151
|
+
headers: {
|
|
152
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
if (error || !profile) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
160
|
+
const account = profile.kakao_account || {};
|
|
161
|
+
const kakaoProfile = account.profile || {};
|
|
162
|
+
const user = {
|
|
163
|
+
id: String(profile.id),
|
|
164
|
+
name: kakaoProfile.nickname || account.name || undefined,
|
|
165
|
+
email: account.email,
|
|
166
|
+
image:
|
|
167
|
+
kakaoProfile.profile_image_url || kakaoProfile.thumbnail_image_url,
|
|
168
|
+
emailVerified: !!account.is_email_valid && !!account.is_email_verified,
|
|
169
|
+
...userMap,
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
user,
|
|
173
|
+
data: profile,
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
options,
|
|
177
|
+
} satisfies OAuthProvider<KakaoProfile>;
|
|
178
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import {
|
|
3
|
+
createAuthorizationURL,
|
|
4
|
+
validateAuthorizationCode,
|
|
5
|
+
} from "@better-auth/core/oauth2";
|
|
6
|
+
import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
|
|
7
|
+
|
|
8
|
+
export interface KickProfile {
|
|
9
|
+
/**
|
|
10
|
+
* The user id of the user
|
|
11
|
+
*/
|
|
12
|
+
user_id: string;
|
|
13
|
+
/**
|
|
14
|
+
* The name of the user
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* The email of the user
|
|
19
|
+
*/
|
|
20
|
+
email: string;
|
|
21
|
+
/**
|
|
22
|
+
* The picture of the user
|
|
23
|
+
*/
|
|
24
|
+
profile_picture: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface KickOptions extends ProviderOptions<KickProfile> {
|
|
28
|
+
clientId: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const kick = (options: KickOptions) => {
|
|
32
|
+
return {
|
|
33
|
+
id: "kick",
|
|
34
|
+
name: "Kick",
|
|
35
|
+
createAuthorizationURL({ state, scopes, redirectURI, codeVerifier }) {
|
|
36
|
+
const _scopes = options.disableDefaultScope ? [] : ["user:read"];
|
|
37
|
+
options.scope && _scopes.push(...options.scope);
|
|
38
|
+
scopes && _scopes.push(...scopes);
|
|
39
|
+
|
|
40
|
+
return createAuthorizationURL({
|
|
41
|
+
id: "kick",
|
|
42
|
+
redirectURI,
|
|
43
|
+
options,
|
|
44
|
+
authorizationEndpoint: "https://id.kick.com/oauth/authorize",
|
|
45
|
+
scopes: _scopes,
|
|
46
|
+
codeVerifier,
|
|
47
|
+
state,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
async validateAuthorizationCode({ code, redirectURI, codeVerifier }) {
|
|
51
|
+
return validateAuthorizationCode({
|
|
52
|
+
code,
|
|
53
|
+
redirectURI,
|
|
54
|
+
options,
|
|
55
|
+
tokenEndpoint: "https://id.kick.com/oauth/token",
|
|
56
|
+
codeVerifier,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async getUserInfo(token) {
|
|
60
|
+
if (options.getUserInfo) {
|
|
61
|
+
return options.getUserInfo(token);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { data, error } = await betterFetch<{
|
|
65
|
+
data: KickProfile[];
|
|
66
|
+
}>("https://api.kick.com/public/v1/users", {
|
|
67
|
+
method: "GET",
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (error) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const profile = data.data[0]!;
|
|
78
|
+
|
|
79
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
user: {
|
|
83
|
+
id: profile.user_id,
|
|
84
|
+
name: profile.name,
|
|
85
|
+
email: profile.email,
|
|
86
|
+
image: profile.profile_picture,
|
|
87
|
+
emailVerified: true,
|
|
88
|
+
...userMap,
|
|
89
|
+
},
|
|
90
|
+
data: profile,
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
options,
|
|
94
|
+
} satisfies OAuthProvider<KickProfile>;
|
|
95
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import { decodeJwt } from "jose";
|
|
3
|
+
import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
|
|
4
|
+
import {
|
|
5
|
+
createAuthorizationURL,
|
|
6
|
+
refreshAccessToken,
|
|
7
|
+
validateAuthorizationCode,
|
|
8
|
+
} from "@better-auth/core/oauth2";
|
|
9
|
+
|
|
10
|
+
export interface LineIdTokenPayload {
|
|
11
|
+
iss: string;
|
|
12
|
+
sub: string;
|
|
13
|
+
aud: string;
|
|
14
|
+
exp: number;
|
|
15
|
+
iat: number;
|
|
16
|
+
name?: string;
|
|
17
|
+
picture?: string;
|
|
18
|
+
email?: string;
|
|
19
|
+
amr?: string[];
|
|
20
|
+
nonce?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LineUserInfo {
|
|
24
|
+
sub: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
picture?: string;
|
|
27
|
+
email?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface LineOptions
|
|
31
|
+
extends ProviderOptions<LineUserInfo | LineIdTokenPayload> {
|
|
32
|
+
clientId: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* LINE Login v2.1
|
|
37
|
+
* - Authorization endpoint: https://access.line.me/oauth2/v2.1/authorize
|
|
38
|
+
* - Token endpoint: https://api.line.me/oauth2/v2.1/token
|
|
39
|
+
* - UserInfo endpoint: https://api.line.me/oauth2/v2.1/userinfo
|
|
40
|
+
* - Verify ID token: https://api.line.me/oauth2/v2.1/verify
|
|
41
|
+
*
|
|
42
|
+
* Docs: https://developers.line.biz/en/reference/line-login/#issue-access-token
|
|
43
|
+
*/
|
|
44
|
+
export const line = (options: LineOptions) => {
|
|
45
|
+
const authorizationEndpoint = "https://access.line.me/oauth2/v2.1/authorize";
|
|
46
|
+
const tokenEndpoint = "https://api.line.me/oauth2/v2.1/token";
|
|
47
|
+
const userInfoEndpoint = "https://api.line.me/oauth2/v2.1/userinfo";
|
|
48
|
+
const verifyIdTokenEndpoint = "https://api.line.me/oauth2/v2.1/verify";
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
id: "line",
|
|
52
|
+
name: "LINE",
|
|
53
|
+
async createAuthorizationURL({
|
|
54
|
+
state,
|
|
55
|
+
scopes,
|
|
56
|
+
codeVerifier,
|
|
57
|
+
redirectURI,
|
|
58
|
+
loginHint,
|
|
59
|
+
}) {
|
|
60
|
+
const _scopes = options.disableDefaultScope
|
|
61
|
+
? []
|
|
62
|
+
: ["openid", "profile", "email"];
|
|
63
|
+
options.scope && _scopes.push(...options.scope);
|
|
64
|
+
scopes && _scopes.push(...scopes);
|
|
65
|
+
return await createAuthorizationURL({
|
|
66
|
+
id: "line",
|
|
67
|
+
options,
|
|
68
|
+
authorizationEndpoint,
|
|
69
|
+
scopes: _scopes,
|
|
70
|
+
state,
|
|
71
|
+
codeVerifier,
|
|
72
|
+
redirectURI,
|
|
73
|
+
loginHint,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
77
|
+
return validateAuthorizationCode({
|
|
78
|
+
code,
|
|
79
|
+
codeVerifier,
|
|
80
|
+
redirectURI,
|
|
81
|
+
options,
|
|
82
|
+
tokenEndpoint,
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
refreshAccessToken: options.refreshAccessToken
|
|
86
|
+
? options.refreshAccessToken
|
|
87
|
+
: async (refreshToken) => {
|
|
88
|
+
return refreshAccessToken({
|
|
89
|
+
refreshToken,
|
|
90
|
+
options: {
|
|
91
|
+
clientId: options.clientId,
|
|
92
|
+
clientSecret: options.clientSecret,
|
|
93
|
+
},
|
|
94
|
+
tokenEndpoint,
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
async verifyIdToken(token, nonce) {
|
|
98
|
+
if (options.disableIdTokenSignIn) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (options.verifyIdToken) {
|
|
102
|
+
return options.verifyIdToken(token, nonce);
|
|
103
|
+
}
|
|
104
|
+
const body = new URLSearchParams();
|
|
105
|
+
body.set("id_token", token);
|
|
106
|
+
body.set("client_id", options.clientId);
|
|
107
|
+
if (nonce) body.set("nonce", nonce);
|
|
108
|
+
const { data, error } = await betterFetch<LineIdTokenPayload>(
|
|
109
|
+
verifyIdTokenEndpoint,
|
|
110
|
+
{
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: {
|
|
113
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
114
|
+
},
|
|
115
|
+
body,
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
if (error || !data) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
// aud must match clientId; nonce (if provided) must also match
|
|
122
|
+
if (data.aud !== options.clientId) return false;
|
|
123
|
+
if (nonce && data.nonce && data.nonce !== nonce) return false;
|
|
124
|
+
return true;
|
|
125
|
+
},
|
|
126
|
+
async getUserInfo(token) {
|
|
127
|
+
if (options.getUserInfo) {
|
|
128
|
+
return options.getUserInfo(token);
|
|
129
|
+
}
|
|
130
|
+
let profile: LineUserInfo | LineIdTokenPayload | null = null;
|
|
131
|
+
// Prefer ID token if available
|
|
132
|
+
if (token.idToken) {
|
|
133
|
+
try {
|
|
134
|
+
profile = decodeJwt(token.idToken) as LineIdTokenPayload;
|
|
135
|
+
} catch {}
|
|
136
|
+
}
|
|
137
|
+
// Fallback to UserInfo endpoint
|
|
138
|
+
if (!profile) {
|
|
139
|
+
const { data } = await betterFetch<LineUserInfo>(userInfoEndpoint, {
|
|
140
|
+
headers: {
|
|
141
|
+
authorization: `Bearer ${token.accessToken}`,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
profile = data || null;
|
|
145
|
+
}
|
|
146
|
+
if (!profile) return null;
|
|
147
|
+
const userMap = await options.mapProfileToUser?.(profile as any);
|
|
148
|
+
// ID preference order
|
|
149
|
+
const id = (profile as any).sub || (profile as any).userId;
|
|
150
|
+
const name = (profile as any).name || (profile as any).displayName;
|
|
151
|
+
const image =
|
|
152
|
+
(profile as any).picture || (profile as any).pictureUrl || undefined;
|
|
153
|
+
const email = (profile as any).email;
|
|
154
|
+
return {
|
|
155
|
+
user: {
|
|
156
|
+
id,
|
|
157
|
+
name,
|
|
158
|
+
email,
|
|
159
|
+
image,
|
|
160
|
+
// LINE does not expose email verification status in ID token/userinfo
|
|
161
|
+
emailVerified: false,
|
|
162
|
+
...userMap,
|
|
163
|
+
},
|
|
164
|
+
data: profile as any,
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
options,
|
|
168
|
+
} satisfies OAuthProvider<LineUserInfo | LineIdTokenPayload, LineOptions>;
|
|
169
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "@better-auth/core/oauth2";
|
|
8
|
+
|
|
9
|
+
interface LinearUser {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
email: string;
|
|
13
|
+
avatarUrl?: string;
|
|
14
|
+
active: boolean;
|
|
15
|
+
createdAt: string;
|
|
16
|
+
updatedAt: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface LinearProfile {
|
|
20
|
+
data: {
|
|
21
|
+
viewer: LinearUser;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LinearOptions extends ProviderOptions<LinearUser> {
|
|
26
|
+
clientId: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const linear = (options: LinearOptions) => {
|
|
30
|
+
const tokenEndpoint = "https://api.linear.app/oauth/token";
|
|
31
|
+
return {
|
|
32
|
+
id: "linear",
|
|
33
|
+
name: "Linear",
|
|
34
|
+
createAuthorizationURL({ state, scopes, loginHint, redirectURI }) {
|
|
35
|
+
const _scopes = options.disableDefaultScope ? [] : ["read"];
|
|
36
|
+
options.scope && _scopes.push(...options.scope);
|
|
37
|
+
scopes && _scopes.push(...scopes);
|
|
38
|
+
return createAuthorizationURL({
|
|
39
|
+
id: "linear",
|
|
40
|
+
options,
|
|
41
|
+
authorizationEndpoint: "https://linear.app/oauth/authorize",
|
|
42
|
+
scopes: _scopes,
|
|
43
|
+
state,
|
|
44
|
+
redirectURI,
|
|
45
|
+
loginHint,
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
49
|
+
return validateAuthorizationCode({
|
|
50
|
+
code,
|
|
51
|
+
redirectURI,
|
|
52
|
+
options,
|
|
53
|
+
tokenEndpoint,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
refreshAccessToken: options.refreshAccessToken
|
|
57
|
+
? options.refreshAccessToken
|
|
58
|
+
: async (refreshToken) => {
|
|
59
|
+
return refreshAccessToken({
|
|
60
|
+
refreshToken,
|
|
61
|
+
options: {
|
|
62
|
+
clientId: options.clientId,
|
|
63
|
+
clientKey: options.clientKey,
|
|
64
|
+
clientSecret: options.clientSecret,
|
|
65
|
+
},
|
|
66
|
+
tokenEndpoint,
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
async getUserInfo(token) {
|
|
70
|
+
if (options.getUserInfo) {
|
|
71
|
+
return options.getUserInfo(token);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const { data: profile, error } = await betterFetch<LinearProfile>(
|
|
75
|
+
"https://api.linear.app/graphql",
|
|
76
|
+
{
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
query: `
|
|
84
|
+
query {
|
|
85
|
+
viewer {
|
|
86
|
+
id
|
|
87
|
+
name
|
|
88
|
+
email
|
|
89
|
+
avatarUrl
|
|
90
|
+
active
|
|
91
|
+
createdAt
|
|
92
|
+
updatedAt
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
`,
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
if (error || !profile?.data?.viewer) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const userData = profile.data.viewer;
|
|
104
|
+
const userMap = await options.mapProfileToUser?.(userData);
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
user: {
|
|
108
|
+
id: profile.data.viewer.id,
|
|
109
|
+
name: profile.data.viewer.name,
|
|
110
|
+
email: profile.data.viewer.email,
|
|
111
|
+
image: profile.data.viewer.avatarUrl,
|
|
112
|
+
emailVerified: true,
|
|
113
|
+
...userMap,
|
|
114
|
+
},
|
|
115
|
+
data: userData,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
options,
|
|
119
|
+
} satisfies OAuthProvider<LinearUser>;
|
|
120
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
validateAuthorizationCode,
|
|
6
|
+
refreshAccessToken,
|
|
7
|
+
} from "@better-auth/core/oauth2";
|
|
8
|
+
|
|
9
|
+
export interface LinkedInProfile {
|
|
10
|
+
sub: string;
|
|
11
|
+
name: string;
|
|
12
|
+
given_name: string;
|
|
13
|
+
family_name: string;
|
|
14
|
+
picture: string;
|
|
15
|
+
locale: {
|
|
16
|
+
country: string;
|
|
17
|
+
language: string;
|
|
18
|
+
};
|
|
19
|
+
email: string;
|
|
20
|
+
email_verified: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LinkedInOptions extends ProviderOptions<LinkedInProfile> {
|
|
24
|
+
clientId: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const linkedin = (options: LinkedInOptions) => {
|
|
28
|
+
const authorizationEndpoint =
|
|
29
|
+
"https://www.linkedin.com/oauth/v2/authorization";
|
|
30
|
+
const tokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
id: "linkedin",
|
|
34
|
+
name: "Linkedin",
|
|
35
|
+
createAuthorizationURL: async ({
|
|
36
|
+
state,
|
|
37
|
+
scopes,
|
|
38
|
+
redirectURI,
|
|
39
|
+
loginHint,
|
|
40
|
+
}) => {
|
|
41
|
+
const _scopes = options.disableDefaultScope
|
|
42
|
+
? []
|
|
43
|
+
: ["profile", "email", "openid"];
|
|
44
|
+
options.scope && _scopes.push(...options.scope);
|
|
45
|
+
scopes && _scopes.push(...scopes);
|
|
46
|
+
return await createAuthorizationURL({
|
|
47
|
+
id: "linkedin",
|
|
48
|
+
options,
|
|
49
|
+
authorizationEndpoint,
|
|
50
|
+
scopes: _scopes,
|
|
51
|
+
state,
|
|
52
|
+
loginHint,
|
|
53
|
+
redirectURI,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
57
|
+
return await validateAuthorizationCode({
|
|
58
|
+
code,
|
|
59
|
+
redirectURI,
|
|
60
|
+
options,
|
|
61
|
+
tokenEndpoint,
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
refreshAccessToken: options.refreshAccessToken
|
|
65
|
+
? options.refreshAccessToken
|
|
66
|
+
: async (refreshToken) => {
|
|
67
|
+
return refreshAccessToken({
|
|
68
|
+
refreshToken,
|
|
69
|
+
options: {
|
|
70
|
+
clientId: options.clientId,
|
|
71
|
+
clientKey: options.clientKey,
|
|
72
|
+
clientSecret: options.clientSecret,
|
|
73
|
+
},
|
|
74
|
+
tokenEndpoint,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
async getUserInfo(token) {
|
|
78
|
+
if (options.getUserInfo) {
|
|
79
|
+
return options.getUserInfo(token);
|
|
80
|
+
}
|
|
81
|
+
const { data: profile, error } = await betterFetch<LinkedInProfile>(
|
|
82
|
+
"https://api.linkedin.com/v2/userinfo",
|
|
83
|
+
{
|
|
84
|
+
method: "GET",
|
|
85
|
+
headers: {
|
|
86
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
if (error) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
96
|
+
return {
|
|
97
|
+
user: {
|
|
98
|
+
id: profile.sub,
|
|
99
|
+
name: profile.name,
|
|
100
|
+
email: profile.email,
|
|
101
|
+
emailVerified: profile.email_verified || false,
|
|
102
|
+
image: profile.picture,
|
|
103
|
+
...userMap,
|
|
104
|
+
},
|
|
105
|
+
data: profile,
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
options,
|
|
109
|
+
} satisfies OAuthProvider<LinkedInProfile>;
|
|
110
|
+
};
|