@better-auth/core 1.4.12-beta.2 → 1.4.13
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 +172 -35
- package/dist/api/index.d.mts +178 -1
- package/dist/api/index.mjs +2 -1
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +31 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +37 -0
- package/dist/context/index.d.mts +5 -53
- package/dist/context/index.mjs +5 -2
- package/dist/context/request-state.d.mts +27 -0
- package/dist/context/request-state.mjs +49 -0
- package/dist/context/transaction.d.mts +16 -0
- package/dist/context/transaction.mjs +52 -0
- package/dist/db/adapter/factory.d.mts +27 -0
- package/dist/db/adapter/factory.mjs +738 -0
- package/dist/db/adapter/get-default-field-name.d.mts +18 -0
- package/dist/db/adapter/get-default-field-name.mjs +38 -0
- package/dist/db/adapter/get-default-model-name.d.mts +12 -0
- package/dist/db/adapter/get-default-model-name.mjs +32 -0
- package/dist/db/adapter/get-field-attributes.d.mts +29 -0
- package/dist/db/adapter/get-field-attributes.mjs +39 -0
- package/dist/db/adapter/get-field-name.d.mts +18 -0
- package/dist/db/adapter/get-field-name.mjs +33 -0
- package/dist/db/adapter/get-id-field.d.mts +39 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-model-name.d.mts +12 -0
- package/dist/db/adapter/get-model-name.mjs +23 -0
- package/dist/db/adapter/index.d.mts +513 -1
- package/dist/db/adapter/index.mjs +8 -970
- package/dist/db/adapter/types.d.mts +139 -0
- package/dist/db/adapter/utils.d.mts +7 -0
- package/dist/db/adapter/utils.mjs +38 -0
- package/dist/db/get-tables.d.mts +8 -0
- package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
- package/dist/db/index.d.mts +10 -2
- package/dist/db/index.mjs +7 -60
- package/dist/db/plugin.d.mts +12 -0
- package/dist/db/schema/account.d.mts +26 -0
- package/dist/db/schema/account.mjs +19 -0
- package/dist/db/schema/rate-limit.d.mts +14 -0
- package/dist/db/schema/rate-limit.mjs +11 -0
- package/dist/db/schema/session.d.mts +21 -0
- package/dist/db/schema/session.mjs +14 -0
- package/dist/db/schema/shared.d.mts +10 -0
- package/dist/db/schema/shared.mjs +11 -0
- package/dist/db/schema/user.d.mts +20 -0
- package/dist/db/schema/user.mjs +13 -0
- package/dist/db/schema/verification.d.mts +19 -0
- package/dist/db/schema/verification.mjs +12 -0
- package/dist/db/type.d.mts +143 -0
- package/dist/env/color-depth.d.mts +4 -0
- package/dist/env/color-depth.mjs +88 -0
- package/dist/env/env-impl.d.mts +32 -0
- package/dist/env/env-impl.mjs +82 -0
- package/dist/env/index.d.mts +4 -2
- package/dist/env/index.mjs +3 -1
- package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
- package/dist/env/logger.mjs +81 -0
- package/dist/error/codes.d.mts +48 -0
- package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
- package/dist/error/index.d.mts +5 -48
- package/dist/error/index.mjs +12 -3
- package/dist/index.d.mts +8 -2
- package/dist/oauth2/client-credentials-token.d.mts +36 -0
- package/dist/oauth2/client-credentials-token.mjs +54 -0
- package/dist/oauth2/create-authorization-url.d.mts +45 -0
- package/dist/oauth2/create-authorization-url.mjs +42 -0
- package/dist/oauth2/index.d.mts +8 -2
- package/dist/oauth2/index.mjs +6 -2
- package/dist/oauth2/oauth-provider.d.mts +194 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +58 -0
- package/dist/oauth2/utils.d.mts +7 -0
- package/dist/oauth2/utils.mjs +27 -0
- package/dist/oauth2/validate-authorization-code.d.mts +55 -0
- package/dist/oauth2/validate-authorization-code.mjs +71 -0
- package/dist/oauth2/verify.d.mts +49 -0
- package/dist/oauth2/verify.mjs +95 -0
- package/dist/social-providers/apple.d.mts +119 -0
- package/dist/social-providers/apple.mjs +102 -0
- package/dist/social-providers/atlassian.d.mts +72 -0
- package/dist/social-providers/atlassian.mjs +83 -0
- package/dist/social-providers/cognito.d.mts +87 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/discord.d.mts +126 -0
- package/dist/social-providers/discord.mjs +64 -0
- package/dist/social-providers/dropbox.d.mts +71 -0
- package/dist/social-providers/dropbox.mjs +75 -0
- package/dist/social-providers/facebook.d.mts +81 -0
- package/dist/social-providers/facebook.mjs +120 -0
- package/dist/social-providers/figma.d.mts +63 -0
- package/dist/social-providers/figma.mjs +84 -0
- package/dist/social-providers/github.d.mts +104 -0
- package/dist/social-providers/github.mjs +80 -0
- package/dist/social-providers/gitlab.d.mts +125 -0
- package/dist/social-providers/gitlab.mjs +82 -0
- package/dist/social-providers/google.d.mts +99 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/huggingface.d.mts +85 -0
- package/dist/social-providers/huggingface.mjs +75 -0
- package/dist/social-providers/index.d.mts +1723 -1
- package/dist/social-providers/index.mjs +33 -2570
- package/dist/social-providers/kakao.d.mts +163 -0
- package/dist/social-providers/kakao.mjs +72 -0
- package/dist/social-providers/kick.d.mts +75 -0
- package/dist/social-providers/kick.mjs +71 -0
- package/dist/social-providers/line.d.mts +107 -0
- package/dist/social-providers/line.mjs +113 -0
- package/dist/social-providers/linear.d.mts +70 -0
- package/dist/social-providers/linear.mjs +88 -0
- package/dist/social-providers/linkedin.d.mts +69 -0
- package/dist/social-providers/linkedin.mjs +76 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
- package/dist/social-providers/microsoft-entra-id.mjs +106 -0
- package/dist/social-providers/naver.d.mts +104 -0
- package/dist/social-providers/naver.mjs +67 -0
- package/dist/social-providers/notion.d.mts +66 -0
- package/dist/social-providers/notion.mjs +75 -0
- package/dist/social-providers/paybin.d.mts +73 -0
- package/dist/social-providers/paybin.mjs +85 -0
- package/dist/social-providers/paypal.d.mts +131 -0
- package/dist/social-providers/paypal.mjs +144 -0
- package/dist/social-providers/polar.d.mts +76 -0
- package/dist/social-providers/polar.mjs +73 -0
- package/dist/social-providers/reddit.d.mts +64 -0
- package/dist/social-providers/reddit.mjs +83 -0
- package/dist/social-providers/roblox.d.mts +72 -0
- package/dist/social-providers/roblox.mjs +59 -0
- package/dist/social-providers/salesforce.d.mts +81 -0
- package/dist/social-providers/salesforce.mjs +91 -0
- package/dist/social-providers/slack.d.mts +85 -0
- package/dist/social-providers/slack.mjs +68 -0
- package/dist/social-providers/spotify.d.mts +65 -0
- package/dist/social-providers/spotify.mjs +71 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +62 -0
- package/dist/social-providers/twitch.d.mts +81 -0
- package/dist/social-providers/twitch.mjs +78 -0
- package/dist/social-providers/twitter.d.mts +140 -0
- package/dist/social-providers/twitter.mjs +87 -0
- package/dist/social-providers/vercel.d.mts +64 -0
- package/dist/social-providers/vercel.mjs +61 -0
- package/dist/social-providers/vk.d.mts +72 -0
- package/dist/social-providers/vk.mjs +83 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +72 -0
- package/dist/types/context.d.mts +215 -0
- package/dist/types/cookie.d.mts +15 -0
- package/dist/types/helper.d.mts +8 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1266 -0
- package/dist/types/plugin-client.d.mts +103 -0
- package/dist/types/plugin.d.mts +121 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +17 -0
- package/dist/utils/error-codes.d.mts +9 -0
- package/dist/utils/error-codes.mjs +7 -0
- package/dist/utils/id.d.mts +4 -0
- package/dist/utils/id.mjs +9 -0
- package/dist/utils/index.d.mts +5 -26
- package/dist/utils/index.mjs +5 -2
- package/dist/utils/json.d.mts +4 -0
- package/dist/utils/json.mjs +25 -0
- package/dist/utils/string.d.mts +4 -0
- package/dist/utils/string.mjs +7 -0
- package/package.json +1 -1
- package/src/context/endpoint-context.ts +7 -15
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +1 -0
- package/src/context/request-state.ts +7 -12
- package/src/context/transaction.ts +7 -16
- package/src/db/adapter/factory.ts +13 -13
- package/src/db/adapter/get-default-model-name.ts +1 -1
- package/src/db/adapter/get-id-field.ts +2 -2
- package/src/error/index.ts +2 -3
- package/src/social-providers/gitlab.ts +1 -1
- package/src/types/context.ts +137 -131
- package/src/types/cookie.ts +6 -4
- package/src/types/index.ts +2 -1
- package/tsdown.config.ts +9 -0
- package/dist/context-BGZ8V6DD.mjs +0 -126
- package/dist/env-DbssmzoK.mjs +0 -245
- package/dist/index-zgYuzZ7O.d.mts +0 -8020
- package/dist/oauth2-COJkghlT.mjs +0 -326
- package/dist/utils-U2L7n92V.mjs +0 -59
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/kakao.d.ts
|
|
5
|
+
interface Partner {
|
|
6
|
+
/** Partner-specific ID (consent required: kakaotalk_message) */
|
|
7
|
+
uuid?: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
interface Profile {
|
|
10
|
+
/** Nickname (consent required: profile/nickname) */
|
|
11
|
+
nickname?: string | undefined;
|
|
12
|
+
/** Thumbnail image URL (consent required: profile/profile image) */
|
|
13
|
+
thumbnail_image_url?: string | undefined;
|
|
14
|
+
/** Profile image URL (consent required: profile/profile image) */
|
|
15
|
+
profile_image_url?: string | undefined;
|
|
16
|
+
/** Whether the profile image is the default */
|
|
17
|
+
is_default_image?: boolean | undefined;
|
|
18
|
+
/** Whether the nickname is the default */
|
|
19
|
+
is_default_nickname?: boolean | undefined;
|
|
20
|
+
}
|
|
21
|
+
interface KakaoAccount {
|
|
22
|
+
/** Consent required: profile info (nickname/profile image) */
|
|
23
|
+
profile_needs_agreement?: boolean | undefined;
|
|
24
|
+
/** Consent required: nickname */
|
|
25
|
+
profile_nickname_needs_agreement?: boolean | undefined;
|
|
26
|
+
/** Consent required: profile image */
|
|
27
|
+
profile_image_needs_agreement?: boolean | undefined;
|
|
28
|
+
/** Profile info */
|
|
29
|
+
profile?: Profile | undefined;
|
|
30
|
+
/** Consent required: name */
|
|
31
|
+
name_needs_agreement?: boolean | undefined;
|
|
32
|
+
/** Name */
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
/** Consent required: email */
|
|
35
|
+
email_needs_agreement?: boolean | undefined;
|
|
36
|
+
/** Email valid */
|
|
37
|
+
is_email_valid?: boolean | undefined;
|
|
38
|
+
/** Email verified */
|
|
39
|
+
is_email_verified?: boolean | undefined;
|
|
40
|
+
/** Email */
|
|
41
|
+
email?: string | undefined;
|
|
42
|
+
/** Consent required: age range */
|
|
43
|
+
age_range_needs_agreement?: boolean | undefined;
|
|
44
|
+
/** Age range */
|
|
45
|
+
age_range?: string | undefined;
|
|
46
|
+
/** Consent required: birth year */
|
|
47
|
+
birthyear_needs_agreement?: boolean | undefined;
|
|
48
|
+
/** Birth year (YYYY) */
|
|
49
|
+
birthyear?: string | undefined;
|
|
50
|
+
/** Consent required: birthday */
|
|
51
|
+
birthday_needs_agreement?: boolean | undefined;
|
|
52
|
+
/** Birthday (MMDD) */
|
|
53
|
+
birthday?: string | undefined;
|
|
54
|
+
/** Birthday type (SOLAR/LUNAR) */
|
|
55
|
+
birthday_type?: string | undefined;
|
|
56
|
+
/** Whether birthday is in a leap month */
|
|
57
|
+
is_leap_month?: boolean | undefined;
|
|
58
|
+
/** Consent required: gender */
|
|
59
|
+
gender_needs_agreement?: boolean | undefined;
|
|
60
|
+
/** Gender (male/female) */
|
|
61
|
+
gender?: string | undefined;
|
|
62
|
+
/** Consent required: phone number */
|
|
63
|
+
phone_number_needs_agreement?: boolean | undefined;
|
|
64
|
+
/** Phone number */
|
|
65
|
+
phone_number?: string | undefined;
|
|
66
|
+
/** Consent required: CI */
|
|
67
|
+
ci_needs_agreement?: boolean | undefined;
|
|
68
|
+
/** CI (unique identifier) */
|
|
69
|
+
ci?: string | undefined;
|
|
70
|
+
/** CI authentication time (UTC) */
|
|
71
|
+
ci_authenticated_at?: string | undefined;
|
|
72
|
+
}
|
|
73
|
+
interface KakaoProfile {
|
|
74
|
+
/** Kakao user ID */
|
|
75
|
+
id: number;
|
|
76
|
+
/**
|
|
77
|
+
* Whether the user has signed up (only present if auto-connection is disabled)
|
|
78
|
+
* false: preregistered, true: registered
|
|
79
|
+
*/
|
|
80
|
+
has_signed_up?: boolean | undefined;
|
|
81
|
+
/** UTC datetime when the user connected the service */
|
|
82
|
+
connected_at?: string | undefined;
|
|
83
|
+
/** UTC datetime when the user signed up via Kakao Sync */
|
|
84
|
+
synched_at?: string | undefined;
|
|
85
|
+
/** Custom user properties */
|
|
86
|
+
properties?: Record<string, any> | undefined;
|
|
87
|
+
/** Kakao account info */
|
|
88
|
+
kakao_account: KakaoAccount;
|
|
89
|
+
/** Partner info */
|
|
90
|
+
for_partner?: Partner | undefined;
|
|
91
|
+
}
|
|
92
|
+
interface KakaoOptions extends ProviderOptions<KakaoProfile> {
|
|
93
|
+
clientId: string;
|
|
94
|
+
}
|
|
95
|
+
declare const kakao: (options: KakaoOptions) => {
|
|
96
|
+
id: "kakao";
|
|
97
|
+
name: string;
|
|
98
|
+
createAuthorizationURL({
|
|
99
|
+
state,
|
|
100
|
+
scopes,
|
|
101
|
+
redirectURI
|
|
102
|
+
}: {
|
|
103
|
+
state: string;
|
|
104
|
+
codeVerifier: string;
|
|
105
|
+
scopes?: string[] | undefined;
|
|
106
|
+
redirectURI: string;
|
|
107
|
+
display?: string | undefined;
|
|
108
|
+
loginHint?: string | undefined;
|
|
109
|
+
}): Promise<URL>;
|
|
110
|
+
validateAuthorizationCode: ({
|
|
111
|
+
code,
|
|
112
|
+
redirectURI
|
|
113
|
+
}: {
|
|
114
|
+
code: string;
|
|
115
|
+
redirectURI: string;
|
|
116
|
+
codeVerifier?: string | undefined;
|
|
117
|
+
deviceId?: string | undefined;
|
|
118
|
+
}) => Promise<OAuth2Tokens>;
|
|
119
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
120
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
121
|
+
user?: {
|
|
122
|
+
name?: {
|
|
123
|
+
firstName?: string;
|
|
124
|
+
lastName?: string;
|
|
125
|
+
};
|
|
126
|
+
email?: string;
|
|
127
|
+
} | undefined;
|
|
128
|
+
}): Promise<{
|
|
129
|
+
user: {
|
|
130
|
+
id: string;
|
|
131
|
+
name?: string;
|
|
132
|
+
email?: string | null;
|
|
133
|
+
image?: string;
|
|
134
|
+
emailVerified: boolean;
|
|
135
|
+
[key: string]: any;
|
|
136
|
+
};
|
|
137
|
+
data: any;
|
|
138
|
+
} | {
|
|
139
|
+
user: {
|
|
140
|
+
id: string;
|
|
141
|
+
name: string | undefined;
|
|
142
|
+
email: string | undefined;
|
|
143
|
+
image: string | undefined;
|
|
144
|
+
emailVerified: boolean;
|
|
145
|
+
} | {
|
|
146
|
+
id: string;
|
|
147
|
+
name: string;
|
|
148
|
+
email: string | null;
|
|
149
|
+
image: string;
|
|
150
|
+
emailVerified: boolean;
|
|
151
|
+
} | {
|
|
152
|
+
id: string;
|
|
153
|
+
name: string;
|
|
154
|
+
email: string | null;
|
|
155
|
+
image: string;
|
|
156
|
+
emailVerified: boolean;
|
|
157
|
+
};
|
|
158
|
+
data: KakaoProfile;
|
|
159
|
+
} | null>;
|
|
160
|
+
options: KakaoOptions;
|
|
161
|
+
};
|
|
162
|
+
//#endregion
|
|
163
|
+
export { KakaoOptions, KakaoProfile, kakao };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
2
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
3
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
4
|
+
import "../oauth2/index.mjs";
|
|
5
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
6
|
+
|
|
7
|
+
//#region src/social-providers/kakao.ts
|
|
8
|
+
const kakao = (options) => {
|
|
9
|
+
return {
|
|
10
|
+
id: "kakao",
|
|
11
|
+
name: "Kakao",
|
|
12
|
+
createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
13
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
14
|
+
"account_email",
|
|
15
|
+
"profile_image",
|
|
16
|
+
"profile_nickname"
|
|
17
|
+
];
|
|
18
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
19
|
+
if (scopes) _scopes.push(...scopes);
|
|
20
|
+
return createAuthorizationURL({
|
|
21
|
+
id: "kakao",
|
|
22
|
+
options,
|
|
23
|
+
authorizationEndpoint: "https://kauth.kakao.com/oauth/authorize",
|
|
24
|
+
scopes: _scopes,
|
|
25
|
+
state,
|
|
26
|
+
redirectURI
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
30
|
+
return validateAuthorizationCode({
|
|
31
|
+
code,
|
|
32
|
+
redirectURI,
|
|
33
|
+
options,
|
|
34
|
+
tokenEndpoint: "https://kauth.kakao.com/oauth/token"
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
38
|
+
return refreshAccessToken({
|
|
39
|
+
refreshToken,
|
|
40
|
+
options: {
|
|
41
|
+
clientId: options.clientId,
|
|
42
|
+
clientKey: options.clientKey,
|
|
43
|
+
clientSecret: options.clientSecret
|
|
44
|
+
},
|
|
45
|
+
tokenEndpoint: "https://kauth.kakao.com/oauth/token"
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
async getUserInfo(token) {
|
|
49
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
50
|
+
const { data: profile, error } = await betterFetch("https://kapi.kakao.com/v2/user/me", { headers: { Authorization: `Bearer ${token.accessToken}` } });
|
|
51
|
+
if (error || !profile) return null;
|
|
52
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
53
|
+
const account = profile.kakao_account || {};
|
|
54
|
+
const kakaoProfile = account.profile || {};
|
|
55
|
+
return {
|
|
56
|
+
user: {
|
|
57
|
+
id: String(profile.id),
|
|
58
|
+
name: kakaoProfile.nickname || account.name || void 0,
|
|
59
|
+
email: account.email,
|
|
60
|
+
image: kakaoProfile.profile_image_url || kakaoProfile.thumbnail_image_url,
|
|
61
|
+
emailVerified: !!account.is_email_valid && !!account.is_email_verified,
|
|
62
|
+
...userMap
|
|
63
|
+
},
|
|
64
|
+
data: profile
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
options
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { kakao };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/kick.d.ts
|
|
5
|
+
interface KickProfile {
|
|
6
|
+
/**
|
|
7
|
+
* The user id of the user
|
|
8
|
+
*/
|
|
9
|
+
user_id: string;
|
|
10
|
+
/**
|
|
11
|
+
* The name of the user
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* The email of the user
|
|
16
|
+
*/
|
|
17
|
+
email: string;
|
|
18
|
+
/**
|
|
19
|
+
* The picture of the user
|
|
20
|
+
*/
|
|
21
|
+
profile_picture: string;
|
|
22
|
+
}
|
|
23
|
+
interface KickOptions extends ProviderOptions<KickProfile> {
|
|
24
|
+
clientId: string;
|
|
25
|
+
}
|
|
26
|
+
declare const kick: (options: KickOptions) => {
|
|
27
|
+
id: "kick";
|
|
28
|
+
name: string;
|
|
29
|
+
createAuthorizationURL({
|
|
30
|
+
state,
|
|
31
|
+
scopes,
|
|
32
|
+
redirectURI,
|
|
33
|
+
codeVerifier
|
|
34
|
+
}: {
|
|
35
|
+
state: string;
|
|
36
|
+
codeVerifier: string;
|
|
37
|
+
scopes?: string[] | undefined;
|
|
38
|
+
redirectURI: string;
|
|
39
|
+
display?: string | undefined;
|
|
40
|
+
loginHint?: string | undefined;
|
|
41
|
+
}): Promise<URL>;
|
|
42
|
+
validateAuthorizationCode({
|
|
43
|
+
code,
|
|
44
|
+
redirectURI,
|
|
45
|
+
codeVerifier
|
|
46
|
+
}: {
|
|
47
|
+
code: string;
|
|
48
|
+
redirectURI: string;
|
|
49
|
+
codeVerifier?: string | undefined;
|
|
50
|
+
deviceId?: string | undefined;
|
|
51
|
+
}): Promise<OAuth2Tokens>;
|
|
52
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
53
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
54
|
+
user?: {
|
|
55
|
+
name?: {
|
|
56
|
+
firstName?: string;
|
|
57
|
+
lastName?: string;
|
|
58
|
+
};
|
|
59
|
+
email?: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
user: {
|
|
63
|
+
id: string;
|
|
64
|
+
name?: string;
|
|
65
|
+
email?: string | null;
|
|
66
|
+
image?: string;
|
|
67
|
+
emailVerified: boolean;
|
|
68
|
+
[key: string]: any;
|
|
69
|
+
};
|
|
70
|
+
data: any;
|
|
71
|
+
} | null>;
|
|
72
|
+
options: KickOptions;
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { KickOptions, KickProfile, kick };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
2
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
3
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
4
|
+
import "../oauth2/index.mjs";
|
|
5
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
6
|
+
|
|
7
|
+
//#region src/social-providers/kick.ts
|
|
8
|
+
const kick = (options) => {
|
|
9
|
+
return {
|
|
10
|
+
id: "kick",
|
|
11
|
+
name: "Kick",
|
|
12
|
+
createAuthorizationURL({ state, scopes, redirectURI, codeVerifier }) {
|
|
13
|
+
const _scopes = options.disableDefaultScope ? [] : ["user:read"];
|
|
14
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
15
|
+
if (scopes) _scopes.push(...scopes);
|
|
16
|
+
return createAuthorizationURL({
|
|
17
|
+
id: "kick",
|
|
18
|
+
redirectURI,
|
|
19
|
+
options,
|
|
20
|
+
authorizationEndpoint: "https://id.kick.com/oauth/authorize",
|
|
21
|
+
scopes: _scopes,
|
|
22
|
+
codeVerifier,
|
|
23
|
+
state
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
async validateAuthorizationCode({ code, redirectURI, codeVerifier }) {
|
|
27
|
+
return validateAuthorizationCode({
|
|
28
|
+
code,
|
|
29
|
+
redirectURI,
|
|
30
|
+
options,
|
|
31
|
+
tokenEndpoint: "https://id.kick.com/oauth/token",
|
|
32
|
+
codeVerifier
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
36
|
+
return refreshAccessToken({
|
|
37
|
+
refreshToken,
|
|
38
|
+
options: {
|
|
39
|
+
clientId: options.clientId,
|
|
40
|
+
clientSecret: options.clientSecret
|
|
41
|
+
},
|
|
42
|
+
tokenEndpoint: "https://id.kick.com/oauth/token"
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
async getUserInfo(token) {
|
|
46
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
47
|
+
const { data, error } = await betterFetch("https://api.kick.com/public/v1/users", {
|
|
48
|
+
method: "GET",
|
|
49
|
+
headers: { Authorization: `Bearer ${token.accessToken}` }
|
|
50
|
+
});
|
|
51
|
+
if (error) return null;
|
|
52
|
+
const profile = data.data[0];
|
|
53
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
54
|
+
return {
|
|
55
|
+
user: {
|
|
56
|
+
id: profile.user_id,
|
|
57
|
+
name: profile.name,
|
|
58
|
+
email: profile.email,
|
|
59
|
+
image: profile.profile_picture,
|
|
60
|
+
emailVerified: false,
|
|
61
|
+
...userMap
|
|
62
|
+
},
|
|
63
|
+
data: profile
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
options
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { kick };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/line.d.ts
|
|
5
|
+
interface LineIdTokenPayload {
|
|
6
|
+
iss: string;
|
|
7
|
+
sub: string;
|
|
8
|
+
aud: string;
|
|
9
|
+
exp: number;
|
|
10
|
+
iat: number;
|
|
11
|
+
name?: string | undefined;
|
|
12
|
+
picture?: string | undefined;
|
|
13
|
+
email?: string | undefined;
|
|
14
|
+
amr?: string[] | undefined;
|
|
15
|
+
nonce?: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
interface LineUserInfo {
|
|
18
|
+
sub: string;
|
|
19
|
+
name?: string | undefined;
|
|
20
|
+
picture?: string | undefined;
|
|
21
|
+
email?: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
interface LineOptions extends ProviderOptions<LineUserInfo | LineIdTokenPayload> {
|
|
24
|
+
clientId: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* LINE Login v2.1
|
|
28
|
+
* - Authorization endpoint: https://access.line.me/oauth2/v2.1/authorize
|
|
29
|
+
* - Token endpoint: https://api.line.me/oauth2/v2.1/token
|
|
30
|
+
* - UserInfo endpoint: https://api.line.me/oauth2/v2.1/userinfo
|
|
31
|
+
* - Verify ID token: https://api.line.me/oauth2/v2.1/verify
|
|
32
|
+
*
|
|
33
|
+
* Docs: https://developers.line.biz/en/reference/line-login/#issue-access-token
|
|
34
|
+
*/
|
|
35
|
+
declare const line: (options: LineOptions) => {
|
|
36
|
+
id: "line";
|
|
37
|
+
name: string;
|
|
38
|
+
createAuthorizationURL({
|
|
39
|
+
state,
|
|
40
|
+
scopes,
|
|
41
|
+
codeVerifier,
|
|
42
|
+
redirectURI,
|
|
43
|
+
loginHint
|
|
44
|
+
}: {
|
|
45
|
+
state: string;
|
|
46
|
+
codeVerifier: string;
|
|
47
|
+
scopes?: string[] | undefined;
|
|
48
|
+
redirectURI: string;
|
|
49
|
+
display?: string | undefined;
|
|
50
|
+
loginHint?: string | undefined;
|
|
51
|
+
}): Promise<URL>;
|
|
52
|
+
validateAuthorizationCode: ({
|
|
53
|
+
code,
|
|
54
|
+
codeVerifier,
|
|
55
|
+
redirectURI
|
|
56
|
+
}: {
|
|
57
|
+
code: string;
|
|
58
|
+
redirectURI: string;
|
|
59
|
+
codeVerifier?: string | undefined;
|
|
60
|
+
deviceId?: string | undefined;
|
|
61
|
+
}) => Promise<OAuth2Tokens>;
|
|
62
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
63
|
+
verifyIdToken(token: string, nonce: string | undefined): Promise<boolean>;
|
|
64
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
65
|
+
user?: {
|
|
66
|
+
name?: {
|
|
67
|
+
firstName?: string;
|
|
68
|
+
lastName?: string;
|
|
69
|
+
};
|
|
70
|
+
email?: string;
|
|
71
|
+
} | undefined;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
user: {
|
|
74
|
+
id: string;
|
|
75
|
+
name?: string;
|
|
76
|
+
email?: string | null;
|
|
77
|
+
image?: string;
|
|
78
|
+
emailVerified: boolean;
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
};
|
|
81
|
+
data: any;
|
|
82
|
+
} | {
|
|
83
|
+
user: {
|
|
84
|
+
id: any;
|
|
85
|
+
name: any;
|
|
86
|
+
email: any;
|
|
87
|
+
image: any;
|
|
88
|
+
emailVerified: false;
|
|
89
|
+
} | {
|
|
90
|
+
id: any;
|
|
91
|
+
name: any;
|
|
92
|
+
email: any;
|
|
93
|
+
image: any;
|
|
94
|
+
emailVerified: boolean;
|
|
95
|
+
} | {
|
|
96
|
+
id: any;
|
|
97
|
+
name: any;
|
|
98
|
+
email: any;
|
|
99
|
+
image: any;
|
|
100
|
+
emailVerified: boolean;
|
|
101
|
+
};
|
|
102
|
+
data: any;
|
|
103
|
+
} | null>;
|
|
104
|
+
options: LineOptions;
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { LineIdTokenPayload, LineOptions, LineUserInfo, line };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
2
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
3
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
4
|
+
import "../oauth2/index.mjs";
|
|
5
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
6
|
+
import { decodeJwt } from "jose";
|
|
7
|
+
|
|
8
|
+
//#region src/social-providers/line.ts
|
|
9
|
+
/**
|
|
10
|
+
* LINE Login v2.1
|
|
11
|
+
* - Authorization endpoint: https://access.line.me/oauth2/v2.1/authorize
|
|
12
|
+
* - Token endpoint: https://api.line.me/oauth2/v2.1/token
|
|
13
|
+
* - UserInfo endpoint: https://api.line.me/oauth2/v2.1/userinfo
|
|
14
|
+
* - Verify ID token: https://api.line.me/oauth2/v2.1/verify
|
|
15
|
+
*
|
|
16
|
+
* Docs: https://developers.line.biz/en/reference/line-login/#issue-access-token
|
|
17
|
+
*/
|
|
18
|
+
const line = (options) => {
|
|
19
|
+
const authorizationEndpoint = "https://access.line.me/oauth2/v2.1/authorize";
|
|
20
|
+
const tokenEndpoint = "https://api.line.me/oauth2/v2.1/token";
|
|
21
|
+
const userInfoEndpoint = "https://api.line.me/oauth2/v2.1/userinfo";
|
|
22
|
+
const verifyIdTokenEndpoint = "https://api.line.me/oauth2/v2.1/verify";
|
|
23
|
+
return {
|
|
24
|
+
id: "line",
|
|
25
|
+
name: "LINE",
|
|
26
|
+
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, loginHint }) {
|
|
27
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
28
|
+
"openid",
|
|
29
|
+
"profile",
|
|
30
|
+
"email"
|
|
31
|
+
];
|
|
32
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
33
|
+
if (scopes) _scopes.push(...scopes);
|
|
34
|
+
return await createAuthorizationURL({
|
|
35
|
+
id: "line",
|
|
36
|
+
options,
|
|
37
|
+
authorizationEndpoint,
|
|
38
|
+
scopes: _scopes,
|
|
39
|
+
state,
|
|
40
|
+
codeVerifier,
|
|
41
|
+
redirectURI,
|
|
42
|
+
loginHint
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
46
|
+
return validateAuthorizationCode({
|
|
47
|
+
code,
|
|
48
|
+
codeVerifier,
|
|
49
|
+
redirectURI,
|
|
50
|
+
options,
|
|
51
|
+
tokenEndpoint
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
55
|
+
return refreshAccessToken({
|
|
56
|
+
refreshToken,
|
|
57
|
+
options: {
|
|
58
|
+
clientId: options.clientId,
|
|
59
|
+
clientSecret: options.clientSecret
|
|
60
|
+
},
|
|
61
|
+
tokenEndpoint
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
async verifyIdToken(token, nonce) {
|
|
65
|
+
if (options.disableIdTokenSignIn) return false;
|
|
66
|
+
if (options.verifyIdToken) return options.verifyIdToken(token, nonce);
|
|
67
|
+
const body = new URLSearchParams();
|
|
68
|
+
body.set("id_token", token);
|
|
69
|
+
body.set("client_id", options.clientId);
|
|
70
|
+
if (nonce) body.set("nonce", nonce);
|
|
71
|
+
const { data, error } = await betterFetch(verifyIdTokenEndpoint, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
74
|
+
body
|
|
75
|
+
});
|
|
76
|
+
if (error || !data) return false;
|
|
77
|
+
if (data.aud !== options.clientId) return false;
|
|
78
|
+
if (data.nonce && data.nonce !== nonce) return false;
|
|
79
|
+
return true;
|
|
80
|
+
},
|
|
81
|
+
async getUserInfo(token) {
|
|
82
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
83
|
+
let profile = null;
|
|
84
|
+
if (token.idToken) try {
|
|
85
|
+
profile = decodeJwt(token.idToken);
|
|
86
|
+
} catch {}
|
|
87
|
+
if (!profile) {
|
|
88
|
+
const { data } = await betterFetch(userInfoEndpoint, { headers: { authorization: `Bearer ${token.accessToken}` } });
|
|
89
|
+
profile = data || null;
|
|
90
|
+
}
|
|
91
|
+
if (!profile) return null;
|
|
92
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
93
|
+
const id = profile.sub || profile.userId;
|
|
94
|
+
const name = profile.name || profile.displayName;
|
|
95
|
+
const image = profile.picture || profile.pictureUrl || void 0;
|
|
96
|
+
return {
|
|
97
|
+
user: {
|
|
98
|
+
id,
|
|
99
|
+
name,
|
|
100
|
+
email: profile.email,
|
|
101
|
+
image,
|
|
102
|
+
emailVerified: false,
|
|
103
|
+
...userMap
|
|
104
|
+
},
|
|
105
|
+
data: profile
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
options
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { line };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/linear.d.ts
|
|
5
|
+
interface LinearUser {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
avatarUrl?: string | undefined;
|
|
10
|
+
active: boolean;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
updatedAt: string;
|
|
13
|
+
}
|
|
14
|
+
interface LinearProfile {
|
|
15
|
+
data: {
|
|
16
|
+
viewer: LinearUser;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface LinearOptions extends ProviderOptions<LinearUser> {
|
|
20
|
+
clientId: string;
|
|
21
|
+
}
|
|
22
|
+
declare const linear: (options: LinearOptions) => {
|
|
23
|
+
id: "linear";
|
|
24
|
+
name: string;
|
|
25
|
+
createAuthorizationURL({
|
|
26
|
+
state,
|
|
27
|
+
scopes,
|
|
28
|
+
loginHint,
|
|
29
|
+
redirectURI
|
|
30
|
+
}: {
|
|
31
|
+
state: string;
|
|
32
|
+
codeVerifier: string;
|
|
33
|
+
scopes?: string[] | undefined;
|
|
34
|
+
redirectURI: string;
|
|
35
|
+
display?: string | undefined;
|
|
36
|
+
loginHint?: string | undefined;
|
|
37
|
+
}): Promise<URL>;
|
|
38
|
+
validateAuthorizationCode: ({
|
|
39
|
+
code,
|
|
40
|
+
redirectURI
|
|
41
|
+
}: {
|
|
42
|
+
code: string;
|
|
43
|
+
redirectURI: string;
|
|
44
|
+
codeVerifier?: string | undefined;
|
|
45
|
+
deviceId?: string | undefined;
|
|
46
|
+
}) => Promise<OAuth2Tokens>;
|
|
47
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
48
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
49
|
+
user?: {
|
|
50
|
+
name?: {
|
|
51
|
+
firstName?: string;
|
|
52
|
+
lastName?: string;
|
|
53
|
+
};
|
|
54
|
+
email?: string;
|
|
55
|
+
} | undefined;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
user: {
|
|
58
|
+
id: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
email?: string | null;
|
|
61
|
+
image?: string;
|
|
62
|
+
emailVerified: boolean;
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
};
|
|
65
|
+
data: any;
|
|
66
|
+
} | null>;
|
|
67
|
+
options: LinearOptions;
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
export { LinearOptions, LinearProfile, LinearUser, linear };
|