@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,73 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/roblox.d.ts
|
|
5
|
+
interface RobloxProfile extends Record<string, any> {
|
|
6
|
+
/** the user's id */
|
|
7
|
+
sub: string;
|
|
8
|
+
/** the user's username */
|
|
9
|
+
preferred_username: string;
|
|
10
|
+
/** the user's display name, will return the same value as the preferred_username if not set */
|
|
11
|
+
nickname: string;
|
|
12
|
+
/** the user's display name, again, will return the same value as the preferred_username if not set */
|
|
13
|
+
name: string;
|
|
14
|
+
/** the account creation date as a unix timestamp in seconds */
|
|
15
|
+
created_at: number;
|
|
16
|
+
/** the user's profile URL */
|
|
17
|
+
profile: string;
|
|
18
|
+
/** the user's avatar URL */
|
|
19
|
+
picture: string;
|
|
20
|
+
}
|
|
21
|
+
interface RobloxOptions extends ProviderOptions<RobloxProfile> {
|
|
22
|
+
clientId: string;
|
|
23
|
+
prompt?: ("none" | "consent" | "login" | "select_account" | "select_account consent") | undefined;
|
|
24
|
+
}
|
|
25
|
+
declare const roblox: (options: RobloxOptions) => {
|
|
26
|
+
id: "roblox";
|
|
27
|
+
name: string;
|
|
28
|
+
createAuthorizationURL({
|
|
29
|
+
state,
|
|
30
|
+
scopes,
|
|
31
|
+
redirectURI
|
|
32
|
+
}: {
|
|
33
|
+
state: string;
|
|
34
|
+
codeVerifier: string;
|
|
35
|
+
scopes?: string[] | undefined;
|
|
36
|
+
redirectURI: string;
|
|
37
|
+
display?: string | undefined;
|
|
38
|
+
loginHint?: string | undefined;
|
|
39
|
+
}): URL;
|
|
40
|
+
validateAuthorizationCode: ({
|
|
41
|
+
code,
|
|
42
|
+
redirectURI
|
|
43
|
+
}: {
|
|
44
|
+
code: string;
|
|
45
|
+
redirectURI: string;
|
|
46
|
+
codeVerifier?: string | undefined;
|
|
47
|
+
deviceId?: string | undefined;
|
|
48
|
+
}) => Promise<OAuth2Tokens>;
|
|
49
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
50
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
51
|
+
user?: {
|
|
52
|
+
name?: {
|
|
53
|
+
firstName?: string;
|
|
54
|
+
lastName?: string;
|
|
55
|
+
};
|
|
56
|
+
email?: string;
|
|
57
|
+
} | undefined;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
user: {
|
|
60
|
+
id: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
email?: string | null;
|
|
63
|
+
image?: string;
|
|
64
|
+
emailVerified: boolean;
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
};
|
|
67
|
+
data: any;
|
|
68
|
+
} | null>;
|
|
69
|
+
options: RobloxOptions;
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { RobloxOptions, RobloxProfile, roblox };
|
|
73
|
+
//# sourceMappingURL=roblox.d.mts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
2
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
3
|
+
import "../oauth2/index.mjs";
|
|
4
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
5
|
+
|
|
6
|
+
//#region src/social-providers/roblox.ts
|
|
7
|
+
const roblox = (options) => {
|
|
8
|
+
return {
|
|
9
|
+
id: "roblox",
|
|
10
|
+
name: "Roblox",
|
|
11
|
+
createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
12
|
+
const _scopes = options.disableDefaultScope ? [] : ["openid", "profile"];
|
|
13
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
14
|
+
if (scopes) _scopes.push(...scopes);
|
|
15
|
+
return new URL(`https://apis.roblox.com/oauth/v1/authorize?scope=${_scopes.join("+")}&response_type=code&client_id=${options.clientId}&redirect_uri=${encodeURIComponent(options.redirectURI || redirectURI)}&state=${state}&prompt=${options.prompt || "select_account consent"}`);
|
|
16
|
+
},
|
|
17
|
+
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
18
|
+
return validateAuthorizationCode({
|
|
19
|
+
code,
|
|
20
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
21
|
+
options,
|
|
22
|
+
tokenEndpoint: "https://apis.roblox.com/oauth/v1/token",
|
|
23
|
+
authentication: "post"
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
27
|
+
return refreshAccessToken({
|
|
28
|
+
refreshToken,
|
|
29
|
+
options: {
|
|
30
|
+
clientId: options.clientId,
|
|
31
|
+
clientKey: options.clientKey,
|
|
32
|
+
clientSecret: options.clientSecret
|
|
33
|
+
},
|
|
34
|
+
tokenEndpoint: "https://apis.roblox.com/oauth/v1/token"
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
async getUserInfo(token) {
|
|
38
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
39
|
+
const { data: profile, error } = await betterFetch("https://apis.roblox.com/oauth/v1/userinfo", { headers: { authorization: `Bearer ${token.accessToken}` } });
|
|
40
|
+
if (error) return null;
|
|
41
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
42
|
+
return {
|
|
43
|
+
user: {
|
|
44
|
+
id: profile.sub,
|
|
45
|
+
name: profile.nickname || profile.preferred_username || "",
|
|
46
|
+
image: profile.picture,
|
|
47
|
+
email: profile.preferred_username || null,
|
|
48
|
+
emailVerified: false,
|
|
49
|
+
...userMap
|
|
50
|
+
},
|
|
51
|
+
data: { ...profile }
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
options
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { roblox };
|
|
60
|
+
//# sourceMappingURL=roblox.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roblox.mjs","names":[],"sources":["../../src/social-providers/roblox.ts"],"sourcesContent":["import { betterFetch } from \"@better-fetch/fetch\";\nimport type { OAuthProvider, ProviderOptions } from \"../oauth2\";\nimport { refreshAccessToken, validateAuthorizationCode } from \"../oauth2\";\n\nexport interface RobloxProfile extends Record<string, any> {\n\t/** the user's id */\n\tsub: string;\n\t/** the user's username */\n\tpreferred_username: string;\n\t/** the user's display name, will return the same value as the preferred_username if not set */\n\tnickname: string;\n\t/** the user's display name, again, will return the same value as the preferred_username if not set */\n\tname: string;\n\t/** the account creation date as a unix timestamp in seconds */\n\tcreated_at: number;\n\t/** the user's profile URL */\n\tprofile: string;\n\t/** the user's avatar URL */\n\tpicture: string;\n}\n\nexport interface RobloxOptions extends ProviderOptions<RobloxProfile> {\n\tclientId: string;\n\tprompt?:\n\t\t| (\n\t\t\t\t| \"none\"\n\t\t\t\t| \"consent\"\n\t\t\t\t| \"login\"\n\t\t\t\t| \"select_account\"\n\t\t\t\t| \"select_account consent\"\n\t\t )\n\t\t| undefined;\n}\n\nexport const roblox = (options: RobloxOptions) => {\n\treturn {\n\t\tid: \"roblox\",\n\t\tname: \"Roblox\",\n\t\tcreateAuthorizationURL({ state, scopes, redirectURI }) {\n\t\t\tconst _scopes = options.disableDefaultScope ? [] : [\"openid\", \"profile\"];\n\t\t\tif (options.scope) _scopes.push(...options.scope);\n\t\t\tif (scopes) _scopes.push(...scopes);\n\t\t\treturn new URL(\n\t\t\t\t`https://apis.roblox.com/oauth/v1/authorize?scope=${_scopes.join(\n\t\t\t\t\t\"+\",\n\t\t\t\t)}&response_type=code&client_id=${\n\t\t\t\t\toptions.clientId\n\t\t\t\t}&redirect_uri=${encodeURIComponent(\n\t\t\t\t\toptions.redirectURI || redirectURI,\n\t\t\t\t)}&state=${state}&prompt=${options.prompt || \"select_account consent\"}`,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async ({ code, redirectURI }) => {\n\t\t\treturn validateAuthorizationCode({\n\t\t\t\tcode,\n\t\t\t\tredirectURI: options.redirectURI || redirectURI,\n\t\t\t\toptions,\n\t\t\t\ttokenEndpoint: \"https://apis.roblox.com/oauth/v1/token\",\n\t\t\t\tauthentication: \"post\",\n\t\t\t});\n\t\t},\n\t\trefreshAccessToken: options.refreshAccessToken\n\t\t\t? options.refreshAccessToken\n\t\t\t: async (refreshToken) => {\n\t\t\t\t\treturn refreshAccessToken({\n\t\t\t\t\t\trefreshToken,\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tclientId: options.clientId,\n\t\t\t\t\t\t\tclientKey: options.clientKey,\n\t\t\t\t\t\t\tclientSecret: options.clientSecret,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttokenEndpoint: \"https://apis.roblox.com/oauth/v1/token\",\n\t\t\t\t\t});\n\t\t\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (options.getUserInfo) {\n\t\t\t\treturn options.getUserInfo(token);\n\t\t\t}\n\t\t\tconst { data: profile, error } = await betterFetch<RobloxProfile>(\n\t\t\t\t\"https://apis.roblox.com/oauth/v1/userinfo\",\n\t\t\t\t{\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tauthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst userMap = await options.mapProfileToUser?.(profile);\n\t\t\t// Roblox does not provide email or email_verified claim.\n\t\t\t// We default to false for security consistency.\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.sub,\n\t\t\t\t\tname: profile.nickname || profile.preferred_username || \"\",\n\t\t\t\t\timage: profile.picture,\n\t\t\t\t\temail: profile.preferred_username || null, // Roblox does not provide email\n\t\t\t\t\temailVerified: false,\n\t\t\t\t\t...userMap,\n\t\t\t\t},\n\t\t\t\tdata: {\n\t\t\t\t\t...profile,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\toptions,\n\t} satisfies OAuthProvider<RobloxProfile>;\n};\n"],"mappings":";;;;;;AAkCA,MAAa,UAAU,YAA2B;AACjD,QAAO;EACN,IAAI;EACJ,MAAM;EACN,uBAAuB,EAAE,OAAO,QAAQ,eAAe;GACtD,MAAM,UAAU,QAAQ,sBAAsB,EAAE,GAAG,CAAC,UAAU,UAAU;AACxE,OAAI,QAAQ,MAAO,SAAQ,KAAK,GAAG,QAAQ,MAAM;AACjD,OAAI,OAAQ,SAAQ,KAAK,GAAG,OAAO;AACnC,UAAO,IAAI,IACV,oDAAoD,QAAQ,KAC3D,IACA,CAAC,gCACD,QAAQ,SACR,gBAAgB,mBAChB,QAAQ,eAAe,YACvB,CAAC,SAAS,MAAM,UAAU,QAAQ,UAAU,2BAC7C;;EAEF,2BAA2B,OAAO,EAAE,MAAM,kBAAkB;AAC3D,UAAO,0BAA0B;IAChC;IACA,aAAa,QAAQ,eAAe;IACpC;IACA,eAAe;IACf,gBAAgB;IAChB,CAAC;;EAEH,oBAAoB,QAAQ,qBACzB,QAAQ,qBACR,OAAO,iBAAiB;AACxB,UAAO,mBAAmB;IACzB;IACA,SAAS;KACR,UAAU,QAAQ;KAClB,WAAW,QAAQ;KACnB,cAAc,QAAQ;KACtB;IACD,eAAe;IACf,CAAC;;EAEL,MAAM,YAAY,OAAO;AACxB,OAAI,QAAQ,YACX,QAAO,QAAQ,YAAY,MAAM;GAElC,MAAM,EAAE,MAAM,SAAS,UAAU,MAAM,YACtC,6CACA,EACC,SAAS,EACR,eAAe,UAAU,MAAM,eAC/B,EACD,CACD;AAED,OAAI,MACH,QAAO;GAGR,MAAM,UAAU,MAAM,QAAQ,mBAAmB,QAAQ;AAGzD,UAAO;IACN,MAAM;KACL,IAAI,QAAQ;KACZ,MAAM,QAAQ,YAAY,QAAQ,sBAAsB;KACxD,OAAO,QAAQ;KACf,OAAO,QAAQ,sBAAsB;KACrC,eAAe;KACf,GAAG;KACH;IACD,MAAM,EACL,GAAG,SACH;IACD;;EAEF;EACA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/salesforce.d.ts
|
|
5
|
+
interface SalesforceProfile {
|
|
6
|
+
sub: string;
|
|
7
|
+
user_id: string;
|
|
8
|
+
organization_id: string;
|
|
9
|
+
preferred_username?: string | undefined;
|
|
10
|
+
email: string;
|
|
11
|
+
email_verified?: boolean | undefined;
|
|
12
|
+
name: string;
|
|
13
|
+
given_name?: string | undefined;
|
|
14
|
+
family_name?: string | undefined;
|
|
15
|
+
zoneinfo?: string | undefined;
|
|
16
|
+
photos?: {
|
|
17
|
+
picture?: string;
|
|
18
|
+
thumbnail?: string;
|
|
19
|
+
} | undefined;
|
|
20
|
+
}
|
|
21
|
+
interface SalesforceOptions extends ProviderOptions<SalesforceProfile> {
|
|
22
|
+
clientId: string;
|
|
23
|
+
environment?: ("sandbox" | "production") | undefined;
|
|
24
|
+
loginUrl?: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Override the redirect URI if auto-detection fails.
|
|
27
|
+
* Should match the Callback URL configured in your Salesforce Connected App.
|
|
28
|
+
* @example "http://localhost:3000/api/auth/callback/salesforce"
|
|
29
|
+
*/
|
|
30
|
+
redirectURI?: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
declare const salesforce: (options: SalesforceOptions) => {
|
|
33
|
+
id: "salesforce";
|
|
34
|
+
name: string;
|
|
35
|
+
createAuthorizationURL({
|
|
36
|
+
state,
|
|
37
|
+
scopes,
|
|
38
|
+
codeVerifier,
|
|
39
|
+
redirectURI
|
|
40
|
+
}: {
|
|
41
|
+
state: string;
|
|
42
|
+
codeVerifier: string;
|
|
43
|
+
scopes?: string[] | undefined;
|
|
44
|
+
redirectURI: string;
|
|
45
|
+
display?: string | undefined;
|
|
46
|
+
loginHint?: string | undefined;
|
|
47
|
+
}): Promise<URL>;
|
|
48
|
+
validateAuthorizationCode: ({
|
|
49
|
+
code,
|
|
50
|
+
codeVerifier,
|
|
51
|
+
redirectURI
|
|
52
|
+
}: {
|
|
53
|
+
code: string;
|
|
54
|
+
redirectURI: string;
|
|
55
|
+
codeVerifier?: string | undefined;
|
|
56
|
+
deviceId?: string | undefined;
|
|
57
|
+
}) => Promise<OAuth2Tokens>;
|
|
58
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
59
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
60
|
+
user?: {
|
|
61
|
+
name?: {
|
|
62
|
+
firstName?: string;
|
|
63
|
+
lastName?: string;
|
|
64
|
+
};
|
|
65
|
+
email?: string;
|
|
66
|
+
} | undefined;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
user: {
|
|
69
|
+
id: string;
|
|
70
|
+
name?: string;
|
|
71
|
+
email?: string | null;
|
|
72
|
+
image?: string;
|
|
73
|
+
emailVerified: boolean;
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
};
|
|
76
|
+
data: any;
|
|
77
|
+
} | null>;
|
|
78
|
+
options: SalesforceOptions;
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { SalesforceOptions, SalesforceProfile, salesforce };
|
|
82
|
+
//# sourceMappingURL=salesforce.d.mts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { logger } from "../env/logger.mjs";
|
|
2
|
+
import "../env/index.mjs";
|
|
3
|
+
import { BetterAuthError } from "../error/index.mjs";
|
|
4
|
+
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
5
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
6
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
7
|
+
import "../oauth2/index.mjs";
|
|
8
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
9
|
+
|
|
10
|
+
//#region src/social-providers/salesforce.ts
|
|
11
|
+
const salesforce = (options) => {
|
|
12
|
+
const isSandbox = (options.environment ?? "production") === "sandbox";
|
|
13
|
+
const authorizationEndpoint = options.loginUrl ? `https://${options.loginUrl}/services/oauth2/authorize` : isSandbox ? "https://test.salesforce.com/services/oauth2/authorize" : "https://login.salesforce.com/services/oauth2/authorize";
|
|
14
|
+
const tokenEndpoint = options.loginUrl ? `https://${options.loginUrl}/services/oauth2/token` : isSandbox ? "https://test.salesforce.com/services/oauth2/token" : "https://login.salesforce.com/services/oauth2/token";
|
|
15
|
+
const userInfoEndpoint = options.loginUrl ? `https://${options.loginUrl}/services/oauth2/userinfo` : isSandbox ? "https://test.salesforce.com/services/oauth2/userinfo" : "https://login.salesforce.com/services/oauth2/userinfo";
|
|
16
|
+
return {
|
|
17
|
+
id: "salesforce",
|
|
18
|
+
name: "Salesforce",
|
|
19
|
+
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
20
|
+
if (!options.clientId || !options.clientSecret) {
|
|
21
|
+
logger.error("Client Id and Client Secret are required for Salesforce. Make sure to provide them in the options.");
|
|
22
|
+
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
23
|
+
}
|
|
24
|
+
if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Salesforce");
|
|
25
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
26
|
+
"openid",
|
|
27
|
+
"email",
|
|
28
|
+
"profile"
|
|
29
|
+
];
|
|
30
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
31
|
+
if (scopes) _scopes.push(...scopes);
|
|
32
|
+
return createAuthorizationURL({
|
|
33
|
+
id: "salesforce",
|
|
34
|
+
options,
|
|
35
|
+
authorizationEndpoint,
|
|
36
|
+
scopes: _scopes,
|
|
37
|
+
state,
|
|
38
|
+
codeVerifier,
|
|
39
|
+
redirectURI: options.redirectURI || redirectURI
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
43
|
+
return validateAuthorizationCode({
|
|
44
|
+
code,
|
|
45
|
+
codeVerifier,
|
|
46
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
47
|
+
options,
|
|
48
|
+
tokenEndpoint
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
52
|
+
return refreshAccessToken({
|
|
53
|
+
refreshToken,
|
|
54
|
+
options: {
|
|
55
|
+
clientId: options.clientId,
|
|
56
|
+
clientSecret: options.clientSecret
|
|
57
|
+
},
|
|
58
|
+
tokenEndpoint
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
async getUserInfo(token) {
|
|
62
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
63
|
+
try {
|
|
64
|
+
const { data: user } = await betterFetch(userInfoEndpoint, { headers: { Authorization: `Bearer ${token.accessToken}` } });
|
|
65
|
+
if (!user) {
|
|
66
|
+
logger.error("Failed to fetch user info from Salesforce");
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const userMap = await options.mapProfileToUser?.(user);
|
|
70
|
+
return {
|
|
71
|
+
user: {
|
|
72
|
+
id: user.user_id,
|
|
73
|
+
name: user.name,
|
|
74
|
+
email: user.email,
|
|
75
|
+
image: user.photos?.picture || user.photos?.thumbnail,
|
|
76
|
+
emailVerified: user.email_verified ?? false,
|
|
77
|
+
...userMap
|
|
78
|
+
},
|
|
79
|
+
data: user
|
|
80
|
+
};
|
|
81
|
+
} catch (error) {
|
|
82
|
+
logger.error("Failed to fetch user info from Salesforce:", error);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
options
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
export { salesforce };
|
|
92
|
+
//# sourceMappingURL=salesforce.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"salesforce.mjs","names":[],"sources":["../../src/social-providers/salesforce.ts"],"sourcesContent":["import { betterFetch } from \"@better-fetch/fetch\";\nimport { logger } from \"../env\";\nimport { BetterAuthError } from \"../error\";\nimport type { OAuthProvider, ProviderOptions } from \"../oauth2\";\nimport {\n\tcreateAuthorizationURL,\n\trefreshAccessToken,\n\tvalidateAuthorizationCode,\n} from \"../oauth2\";\n\nexport interface SalesforceProfile {\n\tsub: string;\n\tuser_id: string;\n\torganization_id: string;\n\tpreferred_username?: string | undefined;\n\temail: string;\n\temail_verified?: boolean | undefined;\n\tname: string;\n\tgiven_name?: string | undefined;\n\tfamily_name?: string | undefined;\n\tzoneinfo?: string | undefined;\n\tphotos?:\n\t\t| {\n\t\t\t\tpicture?: string;\n\t\t\t\tthumbnail?: string;\n\t\t }\n\t\t| undefined;\n}\n\nexport interface SalesforceOptions extends ProviderOptions<SalesforceProfile> {\n\tclientId: string;\n\tenvironment?: (\"sandbox\" | \"production\") | undefined;\n\tloginUrl?: string | undefined;\n\t/**\n\t * Override the redirect URI if auto-detection fails.\n\t * Should match the Callback URL configured in your Salesforce Connected App.\n\t * @example \"http://localhost:3000/api/auth/callback/salesforce\"\n\t */\n\tredirectURI?: string | undefined;\n}\n\nexport const salesforce = (options: SalesforceOptions) => {\n\tconst environment = options.environment ?? \"production\";\n\tconst isSandbox = environment === \"sandbox\";\n\tconst authorizationEndpoint = options.loginUrl\n\t\t? `https://${options.loginUrl}/services/oauth2/authorize`\n\t\t: isSandbox\n\t\t\t? \"https://test.salesforce.com/services/oauth2/authorize\"\n\t\t\t: \"https://login.salesforce.com/services/oauth2/authorize\";\n\n\tconst tokenEndpoint = options.loginUrl\n\t\t? `https://${options.loginUrl}/services/oauth2/token`\n\t\t: isSandbox\n\t\t\t? \"https://test.salesforce.com/services/oauth2/token\"\n\t\t\t: \"https://login.salesforce.com/services/oauth2/token\";\n\n\tconst userInfoEndpoint = options.loginUrl\n\t\t? `https://${options.loginUrl}/services/oauth2/userinfo`\n\t\t: isSandbox\n\t\t\t? \"https://test.salesforce.com/services/oauth2/userinfo\"\n\t\t\t: \"https://login.salesforce.com/services/oauth2/userinfo\";\n\n\treturn {\n\t\tid: \"salesforce\",\n\t\tname: \"Salesforce\",\n\n\t\tasync createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {\n\t\t\tif (!options.clientId || !options.clientSecret) {\n\t\t\t\tlogger.error(\n\t\t\t\t\t\"Client Id and Client Secret are required for Salesforce. Make sure to provide them in the options.\",\n\t\t\t\t);\n\t\t\t\tthrow new BetterAuthError(\"CLIENT_ID_AND_SECRET_REQUIRED\");\n\t\t\t}\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Salesforce\");\n\t\t\t}\n\n\t\t\tconst _scopes = options.disableDefaultScope\n\t\t\t\t? []\n\t\t\t\t: [\"openid\", \"email\", \"profile\"];\n\t\t\tif (options.scope) _scopes.push(...options.scope);\n\t\t\tif (scopes) _scopes.push(...scopes);\n\n\t\t\treturn createAuthorizationURL({\n\t\t\t\tid: \"salesforce\",\n\t\t\t\toptions,\n\t\t\t\tauthorizationEndpoint,\n\t\t\t\tscopes: _scopes,\n\t\t\t\tstate,\n\t\t\t\tcodeVerifier,\n\t\t\t\tredirectURI: options.redirectURI || redirectURI,\n\t\t\t});\n\t\t},\n\n\t\tvalidateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {\n\t\t\treturn validateAuthorizationCode({\n\t\t\t\tcode,\n\t\t\t\tcodeVerifier,\n\t\t\t\tredirectURI: options.redirectURI || redirectURI,\n\t\t\t\toptions,\n\t\t\t\ttokenEndpoint,\n\t\t\t});\n\t\t},\n\n\t\trefreshAccessToken: options.refreshAccessToken\n\t\t\t? options.refreshAccessToken\n\t\t\t: async (refreshToken) => {\n\t\t\t\t\treturn refreshAccessToken({\n\t\t\t\t\t\trefreshToken,\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tclientId: options.clientId,\n\t\t\t\t\t\t\tclientSecret: options.clientSecret,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttokenEndpoint,\n\t\t\t\t\t});\n\t\t\t\t},\n\n\t\tasync getUserInfo(token) {\n\t\t\tif (options.getUserInfo) {\n\t\t\t\treturn options.getUserInfo(token);\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst { data: user } = await betterFetch<SalesforceProfile>(\n\t\t\t\t\tuserInfoEndpoint,\n\t\t\t\t\t{\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (!user) {\n\t\t\t\t\tlogger.error(\"Failed to fetch user info from Salesforce\");\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst userMap = await options.mapProfileToUser?.(user);\n\n\t\t\t\treturn {\n\t\t\t\t\tuser: {\n\t\t\t\t\t\tid: user.user_id,\n\t\t\t\t\t\tname: user.name,\n\t\t\t\t\t\temail: user.email,\n\t\t\t\t\t\timage: user.photos?.picture || user.photos?.thumbnail,\n\t\t\t\t\t\temailVerified: user.email_verified ?? false,\n\t\t\t\t\t\t...userMap,\n\t\t\t\t\t},\n\t\t\t\t\tdata: user,\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error(\"Failed to fetch user info from Salesforce:\", error);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t},\n\n\t\toptions,\n\t} satisfies OAuthProvider<SalesforceProfile>;\n};\n"],"mappings":";;;;;;;;;;AAyCA,MAAa,cAAc,YAA+B;CAEzD,MAAM,aADc,QAAQ,eAAe,kBACT;CAClC,MAAM,wBAAwB,QAAQ,WACnC,WAAW,QAAQ,SAAS,8BAC5B,YACC,0DACA;CAEJ,MAAM,gBAAgB,QAAQ,WAC3B,WAAW,QAAQ,SAAS,0BAC5B,YACC,sDACA;CAEJ,MAAM,mBAAmB,QAAQ,WAC9B,WAAW,QAAQ,SAAS,6BAC5B,YACC,yDACA;AAEJ,QAAO;EACN,IAAI;EACJ,MAAM;EAEN,MAAM,uBAAuB,EAAE,OAAO,QAAQ,cAAc,eAAe;AAC1E,OAAI,CAAC,QAAQ,YAAY,CAAC,QAAQ,cAAc;AAC/C,WAAO,MACN,qGACA;AACD,UAAM,IAAI,gBAAgB,gCAAgC;;AAE3D,OAAI,CAAC,aACJ,OAAM,IAAI,gBAAgB,0CAA0C;GAGrE,MAAM,UAAU,QAAQ,sBACrB,EAAE,GACF;IAAC;IAAU;IAAS;IAAU;AACjC,OAAI,QAAQ,MAAO,SAAQ,KAAK,GAAG,QAAQ,MAAM;AACjD,OAAI,OAAQ,SAAQ,KAAK,GAAG,OAAO;AAEnC,UAAO,uBAAuB;IAC7B,IAAI;IACJ;IACA;IACA,QAAQ;IACR;IACA;IACA,aAAa,QAAQ,eAAe;IACpC,CAAC;;EAGH,2BAA2B,OAAO,EAAE,MAAM,cAAc,kBAAkB;AACzE,UAAO,0BAA0B;IAChC;IACA;IACA,aAAa,QAAQ,eAAe;IACpC;IACA;IACA,CAAC;;EAGH,oBAAoB,QAAQ,qBACzB,QAAQ,qBACR,OAAO,iBAAiB;AACxB,UAAO,mBAAmB;IACzB;IACA,SAAS;KACR,UAAU,QAAQ;KAClB,cAAc,QAAQ;KACtB;IACD;IACA,CAAC;;EAGL,MAAM,YAAY,OAAO;AACxB,OAAI,QAAQ,YACX,QAAO,QAAQ,YAAY,MAAM;AAGlC,OAAI;IACH,MAAM,EAAE,MAAM,SAAS,MAAM,YAC5B,kBACA,EACC,SAAS,EACR,eAAe,UAAU,MAAM,eAC/B,EACD,CACD;AAED,QAAI,CAAC,MAAM;AACV,YAAO,MAAM,4CAA4C;AACzD,YAAO;;IAGR,MAAM,UAAU,MAAM,QAAQ,mBAAmB,KAAK;AAEtD,WAAO;KACN,MAAM;MACL,IAAI,KAAK;MACT,MAAM,KAAK;MACX,OAAO,KAAK;MACZ,OAAO,KAAK,QAAQ,WAAW,KAAK,QAAQ;MAC5C,eAAe,KAAK,kBAAkB;MACtC,GAAG;MACH;KACD,MAAM;KACN;YACO,OAAO;AACf,WAAO,MAAM,8CAA8C,MAAM;AACjE,WAAO;;;EAIT;EACA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/slack.d.ts
|
|
5
|
+
interface SlackProfile extends Record<string, any> {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
sub: string;
|
|
8
|
+
"https://slack.com/user_id": string;
|
|
9
|
+
"https://slack.com/team_id": string;
|
|
10
|
+
email: string;
|
|
11
|
+
email_verified: boolean;
|
|
12
|
+
date_email_verified: number;
|
|
13
|
+
name: string;
|
|
14
|
+
picture: string;
|
|
15
|
+
given_name: string;
|
|
16
|
+
family_name: string;
|
|
17
|
+
locale: string;
|
|
18
|
+
"https://slack.com/team_name": string;
|
|
19
|
+
"https://slack.com/team_domain": string;
|
|
20
|
+
"https://slack.com/user_image_24": string;
|
|
21
|
+
"https://slack.com/user_image_32": string;
|
|
22
|
+
"https://slack.com/user_image_48": string;
|
|
23
|
+
"https://slack.com/user_image_72": string;
|
|
24
|
+
"https://slack.com/user_image_192": string;
|
|
25
|
+
"https://slack.com/user_image_512": string;
|
|
26
|
+
"https://slack.com/team_image_34": string;
|
|
27
|
+
"https://slack.com/team_image_44": string;
|
|
28
|
+
"https://slack.com/team_image_68": string;
|
|
29
|
+
"https://slack.com/team_image_88": string;
|
|
30
|
+
"https://slack.com/team_image_102": string;
|
|
31
|
+
"https://slack.com/team_image_132": string;
|
|
32
|
+
"https://slack.com/team_image_230": string;
|
|
33
|
+
"https://slack.com/team_image_default": boolean;
|
|
34
|
+
}
|
|
35
|
+
interface SlackOptions extends ProviderOptions<SlackProfile> {
|
|
36
|
+
clientId: string;
|
|
37
|
+
}
|
|
38
|
+
declare const slack: (options: SlackOptions) => {
|
|
39
|
+
id: "slack";
|
|
40
|
+
name: string;
|
|
41
|
+
createAuthorizationURL({
|
|
42
|
+
state,
|
|
43
|
+
scopes,
|
|
44
|
+
redirectURI
|
|
45
|
+
}: {
|
|
46
|
+
state: string;
|
|
47
|
+
codeVerifier: string;
|
|
48
|
+
scopes?: string[] | undefined;
|
|
49
|
+
redirectURI: string;
|
|
50
|
+
display?: string | undefined;
|
|
51
|
+
loginHint?: string | undefined;
|
|
52
|
+
}): URL;
|
|
53
|
+
validateAuthorizationCode: ({
|
|
54
|
+
code,
|
|
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
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
64
|
+
user?: {
|
|
65
|
+
name?: {
|
|
66
|
+
firstName?: string;
|
|
67
|
+
lastName?: string;
|
|
68
|
+
};
|
|
69
|
+
email?: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
user: {
|
|
73
|
+
id: string;
|
|
74
|
+
name?: string;
|
|
75
|
+
email?: string | null;
|
|
76
|
+
image?: string;
|
|
77
|
+
emailVerified: boolean;
|
|
78
|
+
[key: string]: any;
|
|
79
|
+
};
|
|
80
|
+
data: any;
|
|
81
|
+
} | null>;
|
|
82
|
+
options: SlackOptions;
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { SlackOptions, SlackProfile, slack };
|
|
86
|
+
//# sourceMappingURL=slack.d.mts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
2
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
3
|
+
import "../oauth2/index.mjs";
|
|
4
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
5
|
+
|
|
6
|
+
//#region src/social-providers/slack.ts
|
|
7
|
+
const slack = (options) => {
|
|
8
|
+
return {
|
|
9
|
+
id: "slack",
|
|
10
|
+
name: "Slack",
|
|
11
|
+
createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
12
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
13
|
+
"openid",
|
|
14
|
+
"profile",
|
|
15
|
+
"email"
|
|
16
|
+
];
|
|
17
|
+
if (scopes) _scopes.push(...scopes);
|
|
18
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
19
|
+
const url = new URL("https://slack.com/openid/connect/authorize");
|
|
20
|
+
url.searchParams.set("scope", _scopes.join(" "));
|
|
21
|
+
url.searchParams.set("response_type", "code");
|
|
22
|
+
url.searchParams.set("client_id", options.clientId);
|
|
23
|
+
url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
|
|
24
|
+
url.searchParams.set("state", state);
|
|
25
|
+
return url;
|
|
26
|
+
},
|
|
27
|
+
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
28
|
+
return validateAuthorizationCode({
|
|
29
|
+
code,
|
|
30
|
+
redirectURI,
|
|
31
|
+
options,
|
|
32
|
+
tokenEndpoint: "https://slack.com/api/openid.connect.token"
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
36
|
+
return refreshAccessToken({
|
|
37
|
+
refreshToken,
|
|
38
|
+
options: {
|
|
39
|
+
clientId: options.clientId,
|
|
40
|
+
clientKey: options.clientKey,
|
|
41
|
+
clientSecret: options.clientSecret
|
|
42
|
+
},
|
|
43
|
+
tokenEndpoint: "https://slack.com/api/openid.connect.token"
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
async getUserInfo(token) {
|
|
47
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
48
|
+
const { data: profile, error } = await betterFetch("https://slack.com/api/openid.connect.userInfo", { headers: { authorization: `Bearer ${token.accessToken}` } });
|
|
49
|
+
if (error) return null;
|
|
50
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
51
|
+
return {
|
|
52
|
+
user: {
|
|
53
|
+
id: profile["https://slack.com/user_id"],
|
|
54
|
+
name: profile.name || "",
|
|
55
|
+
email: profile.email,
|
|
56
|
+
emailVerified: profile.email_verified,
|
|
57
|
+
image: profile.picture || profile["https://slack.com/user_image_512"],
|
|
58
|
+
...userMap
|
|
59
|
+
},
|
|
60
|
+
data: profile
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
options
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { slack };
|
|
69
|
+
//# sourceMappingURL=slack.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slack.mjs","names":[],"sources":["../../src/social-providers/slack.ts"],"sourcesContent":["import { betterFetch } from \"@better-fetch/fetch\";\nimport type { OAuthProvider, ProviderOptions } from \"../oauth2\";\nimport { refreshAccessToken, validateAuthorizationCode } from \"../oauth2\";\n\nexport interface SlackProfile extends Record<string, any> {\n\tok: boolean;\n\tsub: string;\n\t\"https://slack.com/user_id\": string;\n\t\"https://slack.com/team_id\": string;\n\temail: string;\n\temail_verified: boolean;\n\tdate_email_verified: number;\n\tname: string;\n\tpicture: string;\n\tgiven_name: string;\n\tfamily_name: string;\n\tlocale: string;\n\t\"https://slack.com/team_name\": string;\n\t\"https://slack.com/team_domain\": string;\n\t\"https://slack.com/user_image_24\": string;\n\t\"https://slack.com/user_image_32\": string;\n\t\"https://slack.com/user_image_48\": string;\n\t\"https://slack.com/user_image_72\": string;\n\t\"https://slack.com/user_image_192\": string;\n\t\"https://slack.com/user_image_512\": string;\n\t\"https://slack.com/team_image_34\": string;\n\t\"https://slack.com/team_image_44\": string;\n\t\"https://slack.com/team_image_68\": string;\n\t\"https://slack.com/team_image_88\": string;\n\t\"https://slack.com/team_image_102\": string;\n\t\"https://slack.com/team_image_132\": string;\n\t\"https://slack.com/team_image_230\": string;\n\t\"https://slack.com/team_image_default\": boolean;\n}\n\nexport interface SlackOptions extends ProviderOptions<SlackProfile> {\n\tclientId: string;\n}\n\nexport const slack = (options: SlackOptions) => {\n\treturn {\n\t\tid: \"slack\",\n\t\tname: \"Slack\",\n\t\tcreateAuthorizationURL({ state, scopes, redirectURI }) {\n\t\t\tconst _scopes = options.disableDefaultScope\n\t\t\t\t? []\n\t\t\t\t: [\"openid\", \"profile\", \"email\"];\n\t\t\tif (scopes) _scopes.push(...scopes);\n\t\t\tif (options.scope) _scopes.push(...options.scope);\n\t\t\tconst url = new URL(\"https://slack.com/openid/connect/authorize\");\n\t\t\turl.searchParams.set(\"scope\", _scopes.join(\" \"));\n\t\t\turl.searchParams.set(\"response_type\", \"code\");\n\t\t\turl.searchParams.set(\"client_id\", options.clientId);\n\t\t\turl.searchParams.set(\"redirect_uri\", options.redirectURI || redirectURI);\n\t\t\turl.searchParams.set(\"state\", state);\n\t\t\treturn url;\n\t\t},\n\t\tvalidateAuthorizationCode: async ({ code, redirectURI }) => {\n\t\t\treturn validateAuthorizationCode({\n\t\t\t\tcode,\n\t\t\t\tredirectURI,\n\t\t\t\toptions,\n\t\t\t\ttokenEndpoint: \"https://slack.com/api/openid.connect.token\",\n\t\t\t});\n\t\t},\n\t\trefreshAccessToken: options.refreshAccessToken\n\t\t\t? options.refreshAccessToken\n\t\t\t: async (refreshToken) => {\n\t\t\t\t\treturn refreshAccessToken({\n\t\t\t\t\t\trefreshToken,\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tclientId: options.clientId,\n\t\t\t\t\t\t\tclientKey: options.clientKey,\n\t\t\t\t\t\t\tclientSecret: options.clientSecret,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttokenEndpoint: \"https://slack.com/api/openid.connect.token\",\n\t\t\t\t\t});\n\t\t\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (options.getUserInfo) {\n\t\t\t\treturn options.getUserInfo(token);\n\t\t\t}\n\t\t\tconst { data: profile, error } = await betterFetch<SlackProfile>(\n\t\t\t\t\"https://slack.com/api/openid.connect.userInfo\",\n\t\t\t\t{\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tauthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst userMap = await options.mapProfileToUser?.(profile);\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile[\"https://slack.com/user_id\"],\n\t\t\t\t\tname: profile.name || \"\",\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.email_verified,\n\t\t\t\t\timage: profile.picture || profile[\"https://slack.com/user_image_512\"],\n\t\t\t\t\t...userMap,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t\toptions,\n\t} satisfies OAuthProvider<SlackProfile>;\n};\n"],"mappings":";;;;;;AAuCA,MAAa,SAAS,YAA0B;AAC/C,QAAO;EACN,IAAI;EACJ,MAAM;EACN,uBAAuB,EAAE,OAAO,QAAQ,eAAe;GACtD,MAAM,UAAU,QAAQ,sBACrB,EAAE,GACF;IAAC;IAAU;IAAW;IAAQ;AACjC,OAAI,OAAQ,SAAQ,KAAK,GAAG,OAAO;AACnC,OAAI,QAAQ,MAAO,SAAQ,KAAK,GAAG,QAAQ,MAAM;GACjD,MAAM,MAAM,IAAI,IAAI,6CAA6C;AACjE,OAAI,aAAa,IAAI,SAAS,QAAQ,KAAK,IAAI,CAAC;AAChD,OAAI,aAAa,IAAI,iBAAiB,OAAO;AAC7C,OAAI,aAAa,IAAI,aAAa,QAAQ,SAAS;AACnD,OAAI,aAAa,IAAI,gBAAgB,QAAQ,eAAe,YAAY;AACxE,OAAI,aAAa,IAAI,SAAS,MAAM;AACpC,UAAO;;EAER,2BAA2B,OAAO,EAAE,MAAM,kBAAkB;AAC3D,UAAO,0BAA0B;IAChC;IACA;IACA;IACA,eAAe;IACf,CAAC;;EAEH,oBAAoB,QAAQ,qBACzB,QAAQ,qBACR,OAAO,iBAAiB;AACxB,UAAO,mBAAmB;IACzB;IACA,SAAS;KACR,UAAU,QAAQ;KAClB,WAAW,QAAQ;KACnB,cAAc,QAAQ;KACtB;IACD,eAAe;IACf,CAAC;;EAEL,MAAM,YAAY,OAAO;AACxB,OAAI,QAAQ,YACX,QAAO,QAAQ,YAAY,MAAM;GAElC,MAAM,EAAE,MAAM,SAAS,UAAU,MAAM,YACtC,iDACA,EACC,SAAS,EACR,eAAe,UAAU,MAAM,eAC/B,EACD,CACD;AAED,OAAI,MACH,QAAO;GAGR,MAAM,UAAU,MAAM,QAAQ,mBAAmB,QAAQ;AACzD,UAAO;IACN,MAAM;KACL,IAAI,QAAQ;KACZ,MAAM,QAAQ,QAAQ;KACtB,OAAO,QAAQ;KACf,eAAe,QAAQ;KACvB,OAAO,QAAQ,WAAW,QAAQ;KAClC,GAAG;KACH;IACD,MAAM;IACN;;EAEF;EACA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/spotify.d.ts
|
|
5
|
+
interface SpotifyProfile {
|
|
6
|
+
id: string;
|
|
7
|
+
display_name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
images: {
|
|
10
|
+
url: string;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
interface SpotifyOptions extends ProviderOptions<SpotifyProfile> {
|
|
14
|
+
clientId: string;
|
|
15
|
+
}
|
|
16
|
+
declare const spotify: (options: SpotifyOptions) => {
|
|
17
|
+
id: "spotify";
|
|
18
|
+
name: string;
|
|
19
|
+
createAuthorizationURL({
|
|
20
|
+
state,
|
|
21
|
+
scopes,
|
|
22
|
+
codeVerifier,
|
|
23
|
+
redirectURI
|
|
24
|
+
}: {
|
|
25
|
+
state: string;
|
|
26
|
+
codeVerifier: string;
|
|
27
|
+
scopes?: string[] | undefined;
|
|
28
|
+
redirectURI: string;
|
|
29
|
+
display?: string | undefined;
|
|
30
|
+
loginHint?: string | undefined;
|
|
31
|
+
}): Promise<URL>;
|
|
32
|
+
validateAuthorizationCode: ({
|
|
33
|
+
code,
|
|
34
|
+
codeVerifier,
|
|
35
|
+
redirectURI
|
|
36
|
+
}: {
|
|
37
|
+
code: string;
|
|
38
|
+
redirectURI: string;
|
|
39
|
+
codeVerifier?: string | undefined;
|
|
40
|
+
deviceId?: string | undefined;
|
|
41
|
+
}) => Promise<OAuth2Tokens>;
|
|
42
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
43
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
44
|
+
user?: {
|
|
45
|
+
name?: {
|
|
46
|
+
firstName?: string;
|
|
47
|
+
lastName?: string;
|
|
48
|
+
};
|
|
49
|
+
email?: string;
|
|
50
|
+
} | undefined;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
user: {
|
|
53
|
+
id: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
email?: string | null;
|
|
56
|
+
image?: string;
|
|
57
|
+
emailVerified: boolean;
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
};
|
|
60
|
+
data: any;
|
|
61
|
+
} | null>;
|
|
62
|
+
options: SpotifyOptions;
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { SpotifyOptions, SpotifyProfile, spotify };
|
|
66
|
+
//# sourceMappingURL=spotify.d.mts.map
|
|
@@ -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/spotify.ts
|
|
8
|
+
const spotify = (options) => {
|
|
9
|
+
return {
|
|
10
|
+
id: "spotify",
|
|
11
|
+
name: "Spotify",
|
|
12
|
+
createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
13
|
+
const _scopes = options.disableDefaultScope ? [] : ["user-read-email"];
|
|
14
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
15
|
+
if (scopes) _scopes.push(...scopes);
|
|
16
|
+
return createAuthorizationURL({
|
|
17
|
+
id: "spotify",
|
|
18
|
+
options,
|
|
19
|
+
authorizationEndpoint: "https://accounts.spotify.com/authorize",
|
|
20
|
+
scopes: _scopes,
|
|
21
|
+
state,
|
|
22
|
+
codeVerifier,
|
|
23
|
+
redirectURI
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
27
|
+
return validateAuthorizationCode({
|
|
28
|
+
code,
|
|
29
|
+
codeVerifier,
|
|
30
|
+
redirectURI,
|
|
31
|
+
options,
|
|
32
|
+
tokenEndpoint: "https://accounts.spotify.com/api/token"
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
36
|
+
return refreshAccessToken({
|
|
37
|
+
refreshToken,
|
|
38
|
+
options: {
|
|
39
|
+
clientId: options.clientId,
|
|
40
|
+
clientKey: options.clientKey,
|
|
41
|
+
clientSecret: options.clientSecret
|
|
42
|
+
},
|
|
43
|
+
tokenEndpoint: "https://accounts.spotify.com/api/token"
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
async getUserInfo(token) {
|
|
47
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
48
|
+
const { data: profile, error } = await betterFetch("https://api.spotify.com/v1/me", {
|
|
49
|
+
method: "GET",
|
|
50
|
+
headers: { Authorization: `Bearer ${token.accessToken}` }
|
|
51
|
+
});
|
|
52
|
+
if (error) return null;
|
|
53
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
54
|
+
return {
|
|
55
|
+
user: {
|
|
56
|
+
id: profile.id,
|
|
57
|
+
name: profile.display_name,
|
|
58
|
+
email: profile.email,
|
|
59
|
+
image: profile.images[0]?.url,
|
|
60
|
+
emailVerified: false,
|
|
61
|
+
...userMap
|
|
62
|
+
},
|
|
63
|
+
data: profile
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
options
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { spotify };
|
|
72
|
+
//# sourceMappingURL=spotify.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spotify.mjs","names":[],"sources":["../../src/social-providers/spotify.ts"],"sourcesContent":["import { betterFetch } from \"@better-fetch/fetch\";\nimport type { OAuthProvider, ProviderOptions } from \"../oauth2\";\nimport {\n\tcreateAuthorizationURL,\n\trefreshAccessToken,\n\tvalidateAuthorizationCode,\n} from \"../oauth2\";\n\nexport interface SpotifyProfile {\n\tid: string;\n\tdisplay_name: string;\n\temail: string;\n\timages: {\n\t\turl: string;\n\t}[];\n}\n\nexport interface SpotifyOptions extends ProviderOptions<SpotifyProfile> {\n\tclientId: string;\n}\n\nexport const spotify = (options: SpotifyOptions) => {\n\treturn {\n\t\tid: \"spotify\",\n\t\tname: \"Spotify\",\n\t\tcreateAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {\n\t\t\tconst _scopes = options.disableDefaultScope ? [] : [\"user-read-email\"];\n\t\t\tif (options.scope) _scopes.push(...options.scope);\n\t\t\tif (scopes) _scopes.push(...scopes);\n\t\t\treturn createAuthorizationURL({\n\t\t\t\tid: \"spotify\",\n\t\t\t\toptions,\n\t\t\t\tauthorizationEndpoint: \"https://accounts.spotify.com/authorize\",\n\t\t\t\tscopes: _scopes,\n\t\t\t\tstate,\n\t\t\t\tcodeVerifier,\n\t\t\t\tredirectURI,\n\t\t\t});\n\t\t},\n\t\tvalidateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {\n\t\t\treturn validateAuthorizationCode({\n\t\t\t\tcode,\n\t\t\t\tcodeVerifier,\n\t\t\t\tredirectURI,\n\t\t\t\toptions,\n\t\t\t\ttokenEndpoint: \"https://accounts.spotify.com/api/token\",\n\t\t\t});\n\t\t},\n\t\trefreshAccessToken: options.refreshAccessToken\n\t\t\t? options.refreshAccessToken\n\t\t\t: async (refreshToken) => {\n\t\t\t\t\treturn refreshAccessToken({\n\t\t\t\t\t\trefreshToken,\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tclientId: options.clientId,\n\t\t\t\t\t\t\tclientKey: options.clientKey,\n\t\t\t\t\t\t\tclientSecret: options.clientSecret,\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttokenEndpoint: \"https://accounts.spotify.com/api/token\",\n\t\t\t\t\t});\n\t\t\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (options.getUserInfo) {\n\t\t\t\treturn options.getUserInfo(token);\n\t\t\t}\n\t\t\tconst { data: profile, error } = await betterFetch<SpotifyProfile>(\n\t\t\t\t\"https://api.spotify.com/v1/me\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst userMap = await options.mapProfileToUser?.(profile);\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.images[0]?.url,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t\t...userMap,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t\toptions,\n\t} satisfies OAuthProvider<SpotifyProfile>;\n};\n"],"mappings":";;;;;;;AAqBA,MAAa,WAAW,YAA4B;AACnD,QAAO;EACN,IAAI;EACJ,MAAM;EACN,uBAAuB,EAAE,OAAO,QAAQ,cAAc,eAAe;GACpE,MAAM,UAAU,QAAQ,sBAAsB,EAAE,GAAG,CAAC,kBAAkB;AACtE,OAAI,QAAQ,MAAO,SAAQ,KAAK,GAAG,QAAQ,MAAM;AACjD,OAAI,OAAQ,SAAQ,KAAK,GAAG,OAAO;AACnC,UAAO,uBAAuB;IAC7B,IAAI;IACJ;IACA,uBAAuB;IACvB,QAAQ;IACR;IACA;IACA;IACA,CAAC;;EAEH,2BAA2B,OAAO,EAAE,MAAM,cAAc,kBAAkB;AACzE,UAAO,0BAA0B;IAChC;IACA;IACA;IACA;IACA,eAAe;IACf,CAAC;;EAEH,oBAAoB,QAAQ,qBACzB,QAAQ,qBACR,OAAO,iBAAiB;AACxB,UAAO,mBAAmB;IACzB;IACA,SAAS;KACR,UAAU,QAAQ;KAClB,WAAW,QAAQ;KACnB,cAAc,QAAQ;KACtB;IACD,eAAe;IACf,CAAC;;EAEL,MAAM,YAAY,OAAO;AACxB,OAAI,QAAQ,YACX,QAAO,QAAQ,YAAY,MAAM;GAElC,MAAM,EAAE,MAAM,SAAS,UAAU,MAAM,YACtC,iCACA;IACC,QAAQ;IACR,SAAS,EACR,eAAe,UAAU,MAAM,eAC/B;IACD,CACD;AACD,OAAI,MACH,QAAO;GAER,MAAM,UAAU,MAAM,QAAQ,mBAAmB,QAAQ;AACzD,UAAO;IACN,MAAM;KACL,IAAI,QAAQ;KACZ,MAAM,QAAQ;KACd,OAAO,QAAQ;KACf,OAAO,QAAQ,OAAO,IAAI;KAC1B,eAAe;KACf,GAAG;KACH;IACD,MAAM;IACN;;EAEF;EACA"}
|