@hammadj/better-auth-core 1.5.0-beta.9
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 +266 -0
- package/.turbo/turbo-test.log +2 -0
- package/LICENSE.md +20 -0
- package/dist/api/index.d.mts +181 -0
- package/dist/api/index.mjs +34 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/async_hooks/index.d.mts +7 -0
- package/dist/async_hooks/index.mjs +22 -0
- package/dist/async_hooks/index.mjs.map +1 -0
- package/dist/async_hooks/pure.index.d.mts +7 -0
- package/dist/async_hooks/pure.index.mjs +35 -0
- package/dist/async_hooks/pure.index.mjs.map +1 -0
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +32 -0
- package/dist/context/endpoint-context.mjs.map +1 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +38 -0
- package/dist/context/global.mjs.map +1 -0
- package/dist/context/index.d.mts +5 -0
- package/dist/context/index.mjs +6 -0
- package/dist/context/request-state.d.mts +26 -0
- package/dist/context/request-state.mjs +50 -0
- package/dist/context/request-state.mjs.map +1 -0
- package/dist/context/transaction.d.mts +25 -0
- package/dist/context/transaction.mjs +96 -0
- package/dist/context/transaction.mjs.map +1 -0
- package/dist/db/adapter/factory.d.mts +28 -0
- package/dist/db/adapter/factory.mjs +716 -0
- package/dist/db/adapter/factory.mjs.map +1 -0
- package/dist/db/adapter/get-default-field-name.d.mts +19 -0
- package/dist/db/adapter/get-default-field-name.mjs +39 -0
- package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-default-model-name.d.mts +13 -0
- package/dist/db/adapter/get-default-model-name.mjs +33 -0
- package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
- package/dist/db/adapter/get-field-attributes.d.mts +30 -0
- package/dist/db/adapter/get-field-attributes.mjs +40 -0
- package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
- package/dist/db/adapter/get-field-name.d.mts +19 -0
- package/dist/db/adapter/get-field-name.mjs +34 -0
- package/dist/db/adapter/get-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-id-field.d.mts +40 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-id-field.mjs.map +1 -0
- package/dist/db/adapter/get-model-name.d.mts +13 -0
- package/dist/db/adapter/get-model-name.mjs +24 -0
- package/dist/db/adapter/get-model-name.mjs.map +1 -0
- package/dist/db/adapter/index.d.mts +515 -0
- package/dist/db/adapter/index.mjs +10 -0
- package/dist/db/adapter/types.d.mts +140 -0
- package/dist/db/adapter/utils.d.mts +8 -0
- package/dist/db/adapter/utils.mjs +39 -0
- package/dist/db/adapter/utils.mjs.map +1 -0
- package/dist/db/get-tables.d.mts +9 -0
- package/dist/db/get-tables.mjs +267 -0
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +9 -0
- package/dist/db/plugin.d.mts +13 -0
- package/dist/db/schema/account.d.mts +27 -0
- package/dist/db/schema/account.mjs +20 -0
- package/dist/db/schema/account.mjs.map +1 -0
- package/dist/db/schema/rate-limit.d.mts +15 -0
- package/dist/db/schema/rate-limit.mjs +12 -0
- package/dist/db/schema/rate-limit.mjs.map +1 -0
- package/dist/db/schema/session.d.mts +22 -0
- package/dist/db/schema/session.mjs +15 -0
- package/dist/db/schema/session.mjs.map +1 -0
- package/dist/db/schema/shared.d.mts +11 -0
- package/dist/db/schema/shared.mjs +12 -0
- package/dist/db/schema/shared.mjs.map +1 -0
- package/dist/db/schema/user.d.mts +21 -0
- package/dist/db/schema/user.mjs +14 -0
- package/dist/db/schema/user.mjs.map +1 -0
- package/dist/db/schema/verification.d.mts +20 -0
- package/dist/db/schema/verification.mjs +13 -0
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +147 -0
- package/dist/env/color-depth.d.mts +5 -0
- package/dist/env/color-depth.mjs +89 -0
- package/dist/env/color-depth.mjs.map +1 -0
- package/dist/env/env-impl.d.mts +33 -0
- package/dist/env/env-impl.mjs +83 -0
- package/dist/env/env-impl.mjs.map +1 -0
- package/dist/env/index.d.mts +4 -0
- package/dist/env/index.mjs +5 -0
- package/dist/env/logger.d.mts +49 -0
- package/dist/env/logger.mjs +82 -0
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +199 -0
- package/dist/error/codes.mjs +57 -0
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +20 -0
- package/dist/error/index.mjs +30 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +1 -0
- package/dist/oauth2/client-credentials-token.d.mts +37 -0
- package/dist/oauth2/client-credentials-token.mjs +55 -0
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +46 -0
- package/dist/oauth2/create-authorization-url.mjs +43 -0
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +8 -0
- package/dist/oauth2/index.mjs +8 -0
- package/dist/oauth2/oauth-provider.d.mts +195 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +59 -0
- package/dist/oauth2/refresh-access-token.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +8 -0
- package/dist/oauth2/utils.mjs +28 -0
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +56 -0
- package/dist/oauth2/validate-authorization-code.mjs +72 -0
- package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
- package/dist/oauth2/verify.d.mts +43 -0
- package/dist/oauth2/verify.mjs +96 -0
- package/dist/oauth2/verify.mjs.map +1 -0
- package/dist/social-providers/apple.d.mts +120 -0
- package/dist/social-providers/apple.mjs +105 -0
- package/dist/social-providers/apple.mjs.map +1 -0
- package/dist/social-providers/atlassian.d.mts +73 -0
- package/dist/social-providers/atlassian.mjs +84 -0
- package/dist/social-providers/atlassian.mjs.map +1 -0
- package/dist/social-providers/cognito.d.mts +88 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/cognito.mjs.map +1 -0
- package/dist/social-providers/discord.d.mts +127 -0
- package/dist/social-providers/discord.mjs +65 -0
- package/dist/social-providers/discord.mjs.map +1 -0
- package/dist/social-providers/dropbox.d.mts +72 -0
- package/dist/social-providers/dropbox.mjs +76 -0
- package/dist/social-providers/dropbox.mjs.map +1 -0
- package/dist/social-providers/facebook.d.mts +82 -0
- package/dist/social-providers/facebook.mjs +121 -0
- package/dist/social-providers/facebook.mjs.map +1 -0
- package/dist/social-providers/figma.d.mts +64 -0
- package/dist/social-providers/figma.mjs +87 -0
- package/dist/social-providers/figma.mjs.map +1 -0
- package/dist/social-providers/github.d.mts +105 -0
- package/dist/social-providers/github.mjs +97 -0
- package/dist/social-providers/github.mjs.map +1 -0
- package/dist/social-providers/gitlab.d.mts +126 -0
- package/dist/social-providers/gitlab.mjs +83 -0
- package/dist/social-providers/gitlab.mjs.map +1 -0
- package/dist/social-providers/google.d.mts +100 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/google.mjs.map +1 -0
- package/dist/social-providers/huggingface.d.mts +86 -0
- package/dist/social-providers/huggingface.mjs +76 -0
- package/dist/social-providers/huggingface.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +1725 -0
- package/dist/social-providers/index.mjs +77 -0
- package/dist/social-providers/index.mjs.map +1 -0
- package/dist/social-providers/kakao.d.mts +164 -0
- package/dist/social-providers/kakao.mjs +73 -0
- package/dist/social-providers/kakao.mjs.map +1 -0
- package/dist/social-providers/kick.d.mts +76 -0
- package/dist/social-providers/kick.mjs +72 -0
- package/dist/social-providers/kick.mjs.map +1 -0
- package/dist/social-providers/line.d.mts +108 -0
- package/dist/social-providers/line.mjs +114 -0
- package/dist/social-providers/line.mjs.map +1 -0
- package/dist/social-providers/linear.d.mts +71 -0
- package/dist/social-providers/linear.mjs +89 -0
- package/dist/social-providers/linear.mjs.map +1 -0
- package/dist/social-providers/linkedin.d.mts +70 -0
- package/dist/social-providers/linkedin.mjs +77 -0
- package/dist/social-providers/linkedin.mjs.map +1 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +175 -0
- package/dist/social-providers/microsoft-entra-id.mjs +107 -0
- package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/social-providers/naver.d.mts +95 -0
- package/dist/social-providers/naver.mjs +68 -0
- package/dist/social-providers/naver.mjs.map +1 -0
- package/dist/social-providers/notion.d.mts +67 -0
- package/dist/social-providers/notion.mjs +76 -0
- package/dist/social-providers/notion.mjs.map +1 -0
- package/dist/social-providers/paybin.d.mts +74 -0
- package/dist/social-providers/paybin.mjs +86 -0
- package/dist/social-providers/paybin.mjs.map +1 -0
- package/dist/social-providers/paypal.d.mts +132 -0
- package/dist/social-providers/paypal.mjs +145 -0
- package/dist/social-providers/paypal.mjs.map +1 -0
- package/dist/social-providers/polar.d.mts +77 -0
- package/dist/social-providers/polar.mjs +74 -0
- package/dist/social-providers/polar.mjs.map +1 -0
- package/dist/social-providers/reddit.d.mts +65 -0
- package/dist/social-providers/reddit.mjs +84 -0
- package/dist/social-providers/reddit.mjs.map +1 -0
- package/dist/social-providers/roblox.d.mts +73 -0
- package/dist/social-providers/roblox.mjs +60 -0
- package/dist/social-providers/roblox.mjs.map +1 -0
- package/dist/social-providers/salesforce.d.mts +82 -0
- package/dist/social-providers/salesforce.mjs +92 -0
- package/dist/social-providers/salesforce.mjs.map +1 -0
- package/dist/social-providers/slack.d.mts +86 -0
- package/dist/social-providers/slack.mjs +69 -0
- package/dist/social-providers/slack.mjs.map +1 -0
- package/dist/social-providers/spotify.d.mts +66 -0
- package/dist/social-providers/spotify.mjs +72 -0
- package/dist/social-providers/spotify.mjs.map +1 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +63 -0
- package/dist/social-providers/tiktok.mjs.map +1 -0
- package/dist/social-providers/twitch.d.mts +82 -0
- package/dist/social-providers/twitch.mjs +79 -0
- package/dist/social-providers/twitch.mjs.map +1 -0
- package/dist/social-providers/twitter.d.mts +129 -0
- package/dist/social-providers/twitter.mjs +88 -0
- package/dist/social-providers/twitter.mjs.map +1 -0
- package/dist/social-providers/vercel.d.mts +65 -0
- package/dist/social-providers/vercel.mjs +62 -0
- package/dist/social-providers/vercel.mjs.map +1 -0
- package/dist/social-providers/vk.d.mts +73 -0
- package/dist/social-providers/vk.mjs +84 -0
- package/dist/social-providers/vk.mjs.map +1 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +73 -0
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +267 -0
- package/dist/types/cookie.d.mts +16 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1314 -0
- package/dist/types/plugin-client.d.mts +112 -0
- package/dist/types/plugin.d.mts +125 -0
- package/dist/utils/db.d.mts +12 -0
- package/dist/utils/db.mjs +17 -0
- package/dist/utils/db.mjs.map +1 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +18 -0
- package/dist/utils/deprecate.mjs.map +1 -0
- package/dist/utils/error-codes.d.mts +13 -0
- package/dist/utils/error-codes.mjs +12 -0
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/id.d.mts +5 -0
- package/dist/utils/id.mjs +10 -0
- package/dist/utils/id.mjs.map +1 -0
- package/dist/utils/ip.d.mts +55 -0
- package/dist/utils/ip.mjs +119 -0
- package/dist/utils/ip.mjs.map +1 -0
- package/dist/utils/json.d.mts +5 -0
- package/dist/utils/json.mjs +26 -0
- package/dist/utils/json.mjs.map +1 -0
- package/dist/utils/string.d.mts +5 -0
- package/dist/utils/string.mjs +8 -0
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/url.d.mts +21 -0
- package/dist/utils/url.mjs +33 -0
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +147 -0
- package/src/api/index.ts +106 -0
- package/src/async_hooks/index.ts +40 -0
- package/src/async_hooks/pure.index.ts +46 -0
- package/src/context/endpoint-context.ts +50 -0
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +23 -0
- package/src/context/request-state.test.ts +94 -0
- package/src/context/request-state.ts +91 -0
- package/src/context/transaction.ts +136 -0
- package/src/db/adapter/factory.ts +1362 -0
- package/src/db/adapter/get-default-field-name.ts +59 -0
- package/src/db/adapter/get-default-model-name.ts +51 -0
- package/src/db/adapter/get-field-attributes.ts +62 -0
- package/src/db/adapter/get-field-name.ts +43 -0
- package/src/db/adapter/get-id-field.ts +141 -0
- package/src/db/adapter/get-model-name.ts +36 -0
- package/src/db/adapter/index.ts +554 -0
- package/src/db/adapter/types.ts +171 -0
- package/src/db/adapter/utils.ts +61 -0
- package/src/db/get-tables.ts +296 -0
- package/src/db/index.ts +18 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -0
- package/src/db/schema/rate-limit.ts +21 -0
- package/src/db/schema/session.ts +17 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +16 -0
- package/src/db/schema/verification.ts +15 -0
- package/src/db/test/get-tables.test.ts +116 -0
- package/src/db/type.ts +180 -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 +34 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +58 -0
- package/src/error/index.ts +35 -0
- package/src/index.ts +1 -0
- package/src/oauth2/client-credentials-token.ts +102 -0
- package/src/oauth2/create-authorization-url.ts +87 -0
- package/src/oauth2/index.ts +26 -0
- package/src/oauth2/oauth-provider.ts +222 -0
- package/src/oauth2/refresh-access-token.ts +124 -0
- package/src/oauth2/utils.ts +38 -0
- package/src/oauth2/validate-authorization-code.ts +149 -0
- package/src/oauth2/validate-token.test.ts +174 -0
- package/src/oauth2/verify.ts +221 -0
- package/src/social-providers/apple.ts +223 -0
- package/src/social-providers/atlassian.ts +132 -0
- package/src/social-providers/cognito.ts +279 -0
- package/src/social-providers/discord.ts +169 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +206 -0
- package/src/social-providers/figma.ts +117 -0
- package/src/social-providers/github.ts +184 -0
- package/src/social-providers/gitlab.ts +155 -0
- package/src/social-providers/google.ts +199 -0
- package/src/social-providers/huggingface.ts +118 -0
- package/src/social-providers/index.ts +127 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +109 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +121 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +259 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +122 -0
- package/src/social-providers/paypal.ts +263 -0
- package/src/social-providers/polar.ts +110 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +111 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +111 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +209 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +198 -0
- package/src/social-providers/vercel.ts +87 -0
- package/src/social-providers/vk.ts +124 -0
- package/src/social-providers/zoom.ts +238 -0
- package/src/types/context.ts +396 -0
- package/src/types/cookie.ts +10 -0
- package/src/types/helper.ts +26 -0
- package/src/types/index.ts +32 -0
- package/src/types/init-options.ts +1529 -0
- package/src/types/plugin-client.ts +127 -0
- package/src/types/plugin.ts +157 -0
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.test.ts +72 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +65 -0
- package/src/utils/id.ts +5 -0
- package/src/utils/ip.test.ts +255 -0
- package/src/utils/ip.ts +211 -0
- package/src/utils/json.ts +25 -0
- package/src/utils/string.ts +3 -0
- package/src/utils/url.ts +43 -0
- package/tsconfig.json +7 -0
- package/tsdown.config.ts +35 -0
- package/vitest.config.ts +3 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { apple } from "./apple";
|
|
3
|
+
import { atlassian } from "./atlassian";
|
|
4
|
+
import { cognito } from "./cognito";
|
|
5
|
+
import { discord } from "./discord";
|
|
6
|
+
import { dropbox } from "./dropbox";
|
|
7
|
+
import { facebook } from "./facebook";
|
|
8
|
+
import { figma } from "./figma";
|
|
9
|
+
import { github } from "./github";
|
|
10
|
+
import { gitlab } from "./gitlab";
|
|
11
|
+
import { google } from "./google";
|
|
12
|
+
import { huggingface } from "./huggingface";
|
|
13
|
+
import { kakao } from "./kakao";
|
|
14
|
+
import { kick } from "./kick";
|
|
15
|
+
import { line } from "./line";
|
|
16
|
+
import { linear } from "./linear";
|
|
17
|
+
import { linkedin } from "./linkedin";
|
|
18
|
+
import { microsoft } from "./microsoft-entra-id";
|
|
19
|
+
import { naver } from "./naver";
|
|
20
|
+
import { notion } from "./notion";
|
|
21
|
+
import { paybin } from "./paybin";
|
|
22
|
+
import { paypal } from "./paypal";
|
|
23
|
+
import { polar } from "./polar";
|
|
24
|
+
import { reddit } from "./reddit";
|
|
25
|
+
import { roblox } from "./roblox";
|
|
26
|
+
import { salesforce } from "./salesforce";
|
|
27
|
+
import { slack } from "./slack";
|
|
28
|
+
import { spotify } from "./spotify";
|
|
29
|
+
import { tiktok } from "./tiktok";
|
|
30
|
+
import { twitch } from "./twitch";
|
|
31
|
+
import { twitter } from "./twitter";
|
|
32
|
+
import { vercel } from "./vercel";
|
|
33
|
+
import { vk } from "./vk";
|
|
34
|
+
import { zoom } from "./zoom";
|
|
35
|
+
|
|
36
|
+
export const socialProviders = {
|
|
37
|
+
apple,
|
|
38
|
+
atlassian,
|
|
39
|
+
cognito,
|
|
40
|
+
discord,
|
|
41
|
+
facebook,
|
|
42
|
+
figma,
|
|
43
|
+
github,
|
|
44
|
+
microsoft,
|
|
45
|
+
google,
|
|
46
|
+
huggingface,
|
|
47
|
+
slack,
|
|
48
|
+
spotify,
|
|
49
|
+
twitch,
|
|
50
|
+
twitter,
|
|
51
|
+
dropbox,
|
|
52
|
+
kick,
|
|
53
|
+
linear,
|
|
54
|
+
linkedin,
|
|
55
|
+
gitlab,
|
|
56
|
+
tiktok,
|
|
57
|
+
reddit,
|
|
58
|
+
roblox,
|
|
59
|
+
salesforce,
|
|
60
|
+
vk,
|
|
61
|
+
zoom,
|
|
62
|
+
notion,
|
|
63
|
+
kakao,
|
|
64
|
+
naver,
|
|
65
|
+
line,
|
|
66
|
+
paybin,
|
|
67
|
+
paypal,
|
|
68
|
+
polar,
|
|
69
|
+
vercel,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const socialProviderList = Object.keys(socialProviders) as [
|
|
73
|
+
"github",
|
|
74
|
+
...(keyof typeof socialProviders)[],
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
export const SocialProviderListEnum = z
|
|
78
|
+
.enum(socialProviderList)
|
|
79
|
+
.or(z.string()) as z.ZodType<SocialProviderList[number] | (string & {})>;
|
|
80
|
+
|
|
81
|
+
export type SocialProvider = z.infer<typeof SocialProviderListEnum>;
|
|
82
|
+
|
|
83
|
+
export type SocialProviders = {
|
|
84
|
+
[K in SocialProviderList[number]]?: Parameters<
|
|
85
|
+
(typeof socialProviders)[K]
|
|
86
|
+
>[0] & {
|
|
87
|
+
enabled?: boolean | undefined;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export * from "./apple";
|
|
92
|
+
export * from "./atlassian";
|
|
93
|
+
export * from "./cognito";
|
|
94
|
+
export * from "./discord";
|
|
95
|
+
export * from "./dropbox";
|
|
96
|
+
export * from "./facebook";
|
|
97
|
+
export * from "./figma";
|
|
98
|
+
export * from "./github";
|
|
99
|
+
export * from "./gitlab";
|
|
100
|
+
export * from "./google";
|
|
101
|
+
export * from "./huggingface";
|
|
102
|
+
export * from "./kakao";
|
|
103
|
+
export * from "./kick";
|
|
104
|
+
export * from "./kick";
|
|
105
|
+
export * from "./line";
|
|
106
|
+
export * from "./linear";
|
|
107
|
+
export * from "./linkedin";
|
|
108
|
+
export * from "./linkedin";
|
|
109
|
+
export * from "./microsoft-entra-id";
|
|
110
|
+
export * from "./naver";
|
|
111
|
+
export * from "./notion";
|
|
112
|
+
export * from "./paybin";
|
|
113
|
+
export * from "./paypal";
|
|
114
|
+
export * from "./polar";
|
|
115
|
+
export * from "./reddit";
|
|
116
|
+
export * from "./roblox";
|
|
117
|
+
export * from "./salesforce";
|
|
118
|
+
export * from "./slack";
|
|
119
|
+
export * from "./spotify";
|
|
120
|
+
export * from "./tiktok";
|
|
121
|
+
export * from "./twitch";
|
|
122
|
+
export * from "./twitter";
|
|
123
|
+
export * from "./vercel";
|
|
124
|
+
export * from "./vk";
|
|
125
|
+
export * from "./zoom";
|
|
126
|
+
|
|
127
|
+
export type SocialProviderList = typeof socialProviderList;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "../oauth2";
|
|
8
|
+
|
|
9
|
+
interface Partner {
|
|
10
|
+
/** Partner-specific ID (consent required: kakaotalk_message) */
|
|
11
|
+
uuid?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Profile {
|
|
15
|
+
/** Nickname (consent required: profile/nickname) */
|
|
16
|
+
nickname?: string | undefined;
|
|
17
|
+
/** Thumbnail image URL (consent required: profile/profile image) */
|
|
18
|
+
thumbnail_image_url?: string | undefined;
|
|
19
|
+
/** Profile image URL (consent required: profile/profile image) */
|
|
20
|
+
profile_image_url?: string | undefined;
|
|
21
|
+
/** Whether the profile image is the default */
|
|
22
|
+
is_default_image?: boolean | undefined;
|
|
23
|
+
/** Whether the nickname is the default */
|
|
24
|
+
is_default_nickname?: boolean | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface KakaoAccount {
|
|
28
|
+
/** Consent required: profile info (nickname/profile image) */
|
|
29
|
+
profile_needs_agreement?: boolean | undefined;
|
|
30
|
+
/** Consent required: nickname */
|
|
31
|
+
profile_nickname_needs_agreement?: boolean | undefined;
|
|
32
|
+
/** Consent required: profile image */
|
|
33
|
+
profile_image_needs_agreement?: boolean | undefined;
|
|
34
|
+
/** Profile info */
|
|
35
|
+
profile?: Profile | undefined;
|
|
36
|
+
/** Consent required: name */
|
|
37
|
+
name_needs_agreement?: boolean | undefined;
|
|
38
|
+
/** Name */
|
|
39
|
+
name?: string | undefined;
|
|
40
|
+
/** Consent required: email */
|
|
41
|
+
email_needs_agreement?: boolean | undefined;
|
|
42
|
+
/** Email valid */
|
|
43
|
+
is_email_valid?: boolean | undefined;
|
|
44
|
+
/** Email verified */
|
|
45
|
+
is_email_verified?: boolean | undefined;
|
|
46
|
+
/** Email */
|
|
47
|
+
email?: string | undefined;
|
|
48
|
+
/** Consent required: age range */
|
|
49
|
+
age_range_needs_agreement?: boolean | undefined;
|
|
50
|
+
/** Age range */
|
|
51
|
+
age_range?: string | undefined;
|
|
52
|
+
/** Consent required: birth year */
|
|
53
|
+
birthyear_needs_agreement?: boolean | undefined;
|
|
54
|
+
/** Birth year (YYYY) */
|
|
55
|
+
birthyear?: string | undefined;
|
|
56
|
+
/** Consent required: birthday */
|
|
57
|
+
birthday_needs_agreement?: boolean | undefined;
|
|
58
|
+
/** Birthday (MMDD) */
|
|
59
|
+
birthday?: string | undefined;
|
|
60
|
+
/** Birthday type (SOLAR/LUNAR) */
|
|
61
|
+
birthday_type?: string | undefined;
|
|
62
|
+
/** Whether birthday is in a leap month */
|
|
63
|
+
is_leap_month?: boolean | undefined;
|
|
64
|
+
/** Consent required: gender */
|
|
65
|
+
gender_needs_agreement?: boolean | undefined;
|
|
66
|
+
/** Gender (male/female) */
|
|
67
|
+
gender?: string | undefined;
|
|
68
|
+
/** Consent required: phone number */
|
|
69
|
+
phone_number_needs_agreement?: boolean | undefined;
|
|
70
|
+
/** Phone number */
|
|
71
|
+
phone_number?: string | undefined;
|
|
72
|
+
/** Consent required: CI */
|
|
73
|
+
ci_needs_agreement?: boolean | undefined;
|
|
74
|
+
/** CI (unique identifier) */
|
|
75
|
+
ci?: string | undefined;
|
|
76
|
+
/** CI authentication time (UTC) */
|
|
77
|
+
ci_authenticated_at?: string | undefined;
|
|
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 | undefined;
|
|
88
|
+
/** UTC datetime when the user connected the service */
|
|
89
|
+
connected_at?: string | undefined;
|
|
90
|
+
/** UTC datetime when the user signed up via Kakao Sync */
|
|
91
|
+
synched_at?: string | undefined;
|
|
92
|
+
/** Custom user properties */
|
|
93
|
+
properties?: Record<string, any> | undefined;
|
|
94
|
+
/** Kakao account info */
|
|
95
|
+
kakao_account: KakaoAccount;
|
|
96
|
+
/** Partner info */
|
|
97
|
+
for_partner?: Partner | undefined;
|
|
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
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
113
|
+
if (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,109 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "../oauth2";
|
|
8
|
+
|
|
9
|
+
export interface KickProfile {
|
|
10
|
+
/**
|
|
11
|
+
* The user id of the user
|
|
12
|
+
*/
|
|
13
|
+
user_id: string;
|
|
14
|
+
/**
|
|
15
|
+
* The name of the user
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* The email of the user
|
|
20
|
+
*/
|
|
21
|
+
email: string;
|
|
22
|
+
/**
|
|
23
|
+
* The picture of the user
|
|
24
|
+
*/
|
|
25
|
+
profile_picture: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface KickOptions extends ProviderOptions<KickProfile> {
|
|
29
|
+
clientId: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const kick = (options: KickOptions) => {
|
|
33
|
+
return {
|
|
34
|
+
id: "kick",
|
|
35
|
+
name: "Kick",
|
|
36
|
+
createAuthorizationURL({ state, scopes, redirectURI, codeVerifier }) {
|
|
37
|
+
const _scopes = options.disableDefaultScope ? [] : ["user:read"];
|
|
38
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
39
|
+
if (scopes) _scopes.push(...scopes);
|
|
40
|
+
|
|
41
|
+
return createAuthorizationURL({
|
|
42
|
+
id: "kick",
|
|
43
|
+
redirectURI,
|
|
44
|
+
options,
|
|
45
|
+
authorizationEndpoint: "https://id.kick.com/oauth/authorize",
|
|
46
|
+
scopes: _scopes,
|
|
47
|
+
codeVerifier,
|
|
48
|
+
state,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
async validateAuthorizationCode({ code, redirectURI, codeVerifier }) {
|
|
52
|
+
return validateAuthorizationCode({
|
|
53
|
+
code,
|
|
54
|
+
redirectURI,
|
|
55
|
+
options,
|
|
56
|
+
tokenEndpoint: "https://id.kick.com/oauth/token",
|
|
57
|
+
codeVerifier,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
refreshAccessToken: options.refreshAccessToken
|
|
61
|
+
? options.refreshAccessToken
|
|
62
|
+
: async (refreshToken) => {
|
|
63
|
+
return refreshAccessToken({
|
|
64
|
+
refreshToken,
|
|
65
|
+
options: {
|
|
66
|
+
clientId: options.clientId,
|
|
67
|
+
clientSecret: options.clientSecret,
|
|
68
|
+
},
|
|
69
|
+
tokenEndpoint: "https://id.kick.com/oauth/token",
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async getUserInfo(token) {
|
|
73
|
+
if (options.getUserInfo) {
|
|
74
|
+
return options.getUserInfo(token);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const { data, error } = await betterFetch<{
|
|
78
|
+
data: KickProfile[];
|
|
79
|
+
}>("https://api.kick.com/public/v1/users", {
|
|
80
|
+
method: "GET",
|
|
81
|
+
headers: {
|
|
82
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (error) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const profile = data.data[0]!;
|
|
91
|
+
|
|
92
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
93
|
+
// Kick does not provide email_verified claim.
|
|
94
|
+
// We default to false for security consistency.
|
|
95
|
+
return {
|
|
96
|
+
user: {
|
|
97
|
+
id: profile.user_id,
|
|
98
|
+
name: profile.name,
|
|
99
|
+
email: profile.email,
|
|
100
|
+
image: profile.profile_picture,
|
|
101
|
+
emailVerified: false,
|
|
102
|
+
...userMap,
|
|
103
|
+
},
|
|
104
|
+
data: profile,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
options,
|
|
108
|
+
} satisfies OAuthProvider<KickProfile>;
|
|
109
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import { decodeJwt } from "jose";
|
|
3
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
4
|
+
import {
|
|
5
|
+
createAuthorizationURL,
|
|
6
|
+
refreshAccessToken,
|
|
7
|
+
validateAuthorizationCode,
|
|
8
|
+
} from "../oauth2";
|
|
9
|
+
|
|
10
|
+
export interface LineIdTokenPayload {
|
|
11
|
+
iss: string;
|
|
12
|
+
sub: string;
|
|
13
|
+
aud: string;
|
|
14
|
+
exp: number;
|
|
15
|
+
iat: number;
|
|
16
|
+
name?: string | undefined;
|
|
17
|
+
picture?: string | undefined;
|
|
18
|
+
email?: string | undefined;
|
|
19
|
+
amr?: string[] | undefined;
|
|
20
|
+
nonce?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface LineUserInfo {
|
|
24
|
+
sub: string;
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
picture?: string | undefined;
|
|
27
|
+
email?: string | undefined;
|
|
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
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
64
|
+
if (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 nonce
|
|
122
|
+
if (data.aud !== options.clientId) return false;
|
|
123
|
+
if (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,121 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "../oauth2";
|
|
8
|
+
|
|
9
|
+
export interface LinearUser {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
email: string;
|
|
13
|
+
avatarUrl?: string | undefined;
|
|
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
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
37
|
+
if (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
|
+
// Linear does not provide email_verified claim.
|
|
106
|
+
// We default to false for security consistency.
|
|
107
|
+
return {
|
|
108
|
+
user: {
|
|
109
|
+
id: profile.data.viewer.id,
|
|
110
|
+
name: profile.data.viewer.name,
|
|
111
|
+
email: profile.data.viewer.email,
|
|
112
|
+
image: profile.data.viewer.avatarUrl,
|
|
113
|
+
emailVerified: false,
|
|
114
|
+
...userMap,
|
|
115
|
+
},
|
|
116
|
+
data: userData,
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
options,
|
|
120
|
+
} satisfies OAuthProvider<LinearUser>;
|
|
121
|
+
};
|