@gatwech/core 0.0.11 → 1.0.0-beta.19
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/dist/api/index.d.mts +2 -2
- package/dist/context/index.d.mts +2 -2
- package/dist/db/adapter/index.d.mts +2 -2
- package/dist/db/index.d.mts +2 -2
- package/dist/env/index.d.mts +1 -1
- package/dist/env/index.mjs +1 -1
- package/dist/{env-JMSMESs1.mjs → env-ubiqEEZm.mjs} +10 -9
- package/dist/error/index.mjs +2 -2
- package/dist/{error-41YsFQ8b.mjs → error-DKIIiFmH.mjs} +1 -1
- package/dist/{index-DLP-K0uY.d.mts → index-CNtOUpmF.d.mts} +4 -3
- package/dist/index-Df0KhQRf.d.mts +3002 -0
- package/dist/index.d.mts +3 -3
- package/dist/oauth2/index.d.mts +2 -2
- package/dist/social-providers/index.d.mts +3 -3
- package/dist/social-providers/index.mjs +73 -2414
- package/dist/src/api/index.d.ts +119 -0
- package/dist/src/async_hooks/index.d.ts +6 -0
- package/dist/src/context/endpoint-context.d.ts +14 -0
- package/dist/src/context/index.d.ts +3 -0
- package/dist/src/context/request-state.d.ts +13 -0
- package/dist/src/context/transaction.d.ts +11 -0
- package/dist/src/db/adapter/index.d.ts +401 -0
- package/{src/db/index.ts → dist/src/db/index.d.ts} +2 -18
- package/dist/src/db/plugin.d.ts +10 -0
- package/dist/src/db/schema/account.d.ts +22 -0
- package/dist/src/db/schema/rate-limit.d.ts +10 -0
- package/dist/src/db/schema/session.d.ts +17 -0
- package/dist/src/db/schema/shared.d.ts +6 -0
- package/dist/src/db/schema/user.d.ts +16 -0
- package/{src/db/schema/verification.ts → dist/src/db/schema/verification.d.ts} +8 -8
- package/dist/src/db/type.d.ts +159 -0
- package/dist/src/env/color-depth.d.ts +1 -0
- package/dist/src/env/env-impl.d.ts +29 -0
- package/dist/src/env/index.d.ts +3 -0
- package/dist/src/env/logger.d.ts +52 -0
- package/dist/src/error/codes.d.ts +27 -0
- package/dist/src/error/index.d.ts +4 -0
- package/dist/src/oauth2/client-credentials-token.d.ts +21 -0
- package/dist/src/oauth2/create-authorization-url.d.ts +21 -0
- package/dist/src/oauth2/index.d.ts +6 -0
- package/dist/src/oauth2/oauth-provider.d.ts +178 -0
- package/dist/src/oauth2/refresh-access-token.d.ts +20 -0
- package/dist/src/oauth2/utils.d.ts +3 -0
- package/dist/src/oauth2/validate-authorization-code.d.ts +28 -0
- package/dist/src/social-providers/github.d.ts +89 -0
- package/dist/src/social-providers/google.d.ts +82 -0
- package/dist/src/social-providers/index.d.ts +93 -0
- package/dist/src/types/context.d.ts +177 -0
- package/dist/src/types/cookie.d.ts +15 -0
- package/dist/src/types/helper.d.ts +9 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/init-options.d.ts +1140 -0
- package/dist/src/types/plugin-client.d.ts +88 -0
- package/dist/src/types/plugin.d.ts +120 -0
- package/dist/src/utils/error-codes.d.ts +9 -0
- package/dist/utils/index.mjs +1 -1
- package/package.json +11 -5
- package/.turbo/turbo-build.log +0 -42
- package/dist/index-DjrJweYn.d.mts +0 -7312
- package/src/api/index.ts +0 -57
- package/src/async_hooks/index.ts +0 -35
- package/src/context/endpoint-context.ts +0 -48
- package/src/context/index.ts +0 -21
- package/src/context/request-state.test.ts +0 -346
- package/src/context/request-state.ts +0 -75
- package/src/context/transaction.ts +0 -72
- package/src/db/adapter/index.ts +0 -466
- package/src/db/plugin.ts +0 -11
- package/src/db/schema/account.ts +0 -34
- package/src/db/schema/rate-limit.ts +0 -21
- package/src/db/schema/session.ts +0 -17
- package/src/db/schema/shared.ts +0 -7
- package/src/db/schema/user.ts +0 -16
- package/src/db/type.ts +0 -180
- package/src/env/color-depth.ts +0 -172
- package/src/env/env-impl.ts +0 -124
- package/src/env/index.ts +0 -23
- package/src/env/logger.test.ts +0 -33
- package/src/env/logger.ts +0 -145
- package/src/error/codes.ts +0 -31
- package/src/error/index.ts +0 -11
- package/src/oauth2/client-credentials-token.ts +0 -102
- package/src/oauth2/create-authorization-url.ts +0 -85
- package/src/oauth2/index.ts +0 -21
- package/src/oauth2/oauth-provider.ts +0 -211
- package/src/oauth2/refresh-access-token.ts +0 -124
- package/src/oauth2/utils.ts +0 -36
- package/src/oauth2/validate-authorization-code.ts +0 -154
- package/src/social-providers/apple.ts +0 -213
- package/src/social-providers/atlassian.ts +0 -132
- package/src/social-providers/cognito.ts +0 -269
- package/src/social-providers/discord.ts +0 -169
- package/src/social-providers/dropbox.ts +0 -112
- package/src/social-providers/facebook.ts +0 -204
- package/src/social-providers/figma.ts +0 -115
- package/src/social-providers/github.ts +0 -154
- package/src/social-providers/gitlab.ts +0 -152
- package/src/social-providers/google.ts +0 -171
- package/src/social-providers/huggingface.ts +0 -118
- package/src/social-providers/index.ts +0 -124
- package/src/social-providers/kakao.ts +0 -178
- package/src/social-providers/kick.ts +0 -92
- package/src/social-providers/line.ts +0 -169
- package/src/social-providers/linear.ts +0 -120
- package/src/social-providers/linkedin.ts +0 -110
- package/src/social-providers/microsoft-entra-id.ts +0 -245
- package/src/social-providers/naver.ts +0 -112
- package/src/social-providers/notion.ts +0 -108
- package/src/social-providers/paybin.ts +0 -122
- package/src/social-providers/paypal.ts +0 -263
- package/src/social-providers/polar.ts +0 -107
- package/src/social-providers/reddit.ts +0 -122
- package/src/social-providers/roblox.ts +0 -110
- package/src/social-providers/salesforce.ts +0 -159
- package/src/social-providers/slack.ts +0 -111
- package/src/social-providers/spotify.ts +0 -93
- package/src/social-providers/tiktok.ts +0 -210
- package/src/social-providers/twitch.ts +0 -111
- package/src/social-providers/twitter.ts +0 -198
- package/src/social-providers/vk.ts +0 -126
- package/src/social-providers/zoom.ts +0 -217
- package/src/types/context.ts +0 -269
- package/src/types/cookie.ts +0 -7
- package/src/types/helper.ts +0 -6
- package/src/types/index.ts +0 -21
- package/src/types/init-options.ts +0 -1346
- package/src/types/plugin-client.ts +0 -100
- package/src/types/plugin.ts +0 -158
- package/src/utils/error-codes.ts +0 -51
- package/tsconfig.json +0 -7
- package/tsdown.config.ts +0 -20
- /package/{src/index.ts → dist/src/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/src/utils/index.d.ts} +0 -0
- /package/dist/{utils-BFQCAfNW.mjs → utils-CTOwq_Nj.mjs} +0 -0
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
import { createRemoteJWKSet, decodeJwt, jwtVerify } from "jose";
|
|
3
|
-
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
4
|
-
import {
|
|
5
|
-
createAuthorizationURL,
|
|
6
|
-
refreshAccessToken,
|
|
7
|
-
validateAuthorizationCode,
|
|
8
|
-
} from "../oauth2";
|
|
9
|
-
export interface FacebookProfile {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
email: string;
|
|
13
|
-
email_verified: boolean;
|
|
14
|
-
picture: {
|
|
15
|
-
data: {
|
|
16
|
-
height: number;
|
|
17
|
-
is_silhouette: boolean;
|
|
18
|
-
url: string;
|
|
19
|
-
width: number;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface FacebookOptions extends ProviderOptions<FacebookProfile> {
|
|
25
|
-
clientId: string;
|
|
26
|
-
/**
|
|
27
|
-
* Extend list of fields to retrieve from the Facebook user profile.
|
|
28
|
-
*
|
|
29
|
-
* @default ["id", "name", "email", "picture"]
|
|
30
|
-
*/
|
|
31
|
-
fields?: string[] | undefined;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The config id to use when undergoing oauth
|
|
35
|
-
*/
|
|
36
|
-
configId?: string | undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const facebook = (options: FacebookOptions) => {
|
|
40
|
-
return {
|
|
41
|
-
id: "facebook",
|
|
42
|
-
name: "Facebook",
|
|
43
|
-
async createAuthorizationURL({ state, scopes, redirectURI, loginHint }) {
|
|
44
|
-
const _scopes = options.disableDefaultScope
|
|
45
|
-
? []
|
|
46
|
-
: ["email", "public_profile"];
|
|
47
|
-
if (options.scope) _scopes.push(...options.scope);
|
|
48
|
-
if (scopes) _scopes.push(...scopes);
|
|
49
|
-
return await createAuthorizationURL({
|
|
50
|
-
id: "facebook",
|
|
51
|
-
options,
|
|
52
|
-
authorizationEndpoint: "https://www.facebook.com/v21.0/dialog/oauth",
|
|
53
|
-
scopes: _scopes,
|
|
54
|
-
state,
|
|
55
|
-
redirectURI,
|
|
56
|
-
loginHint,
|
|
57
|
-
additionalParams: options.configId
|
|
58
|
-
? {
|
|
59
|
-
config_id: options.configId,
|
|
60
|
-
}
|
|
61
|
-
: {},
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
65
|
-
return validateAuthorizationCode({
|
|
66
|
-
code,
|
|
67
|
-
redirectURI,
|
|
68
|
-
options,
|
|
69
|
-
tokenEndpoint: "https://graph.facebook.com/oauth/access_token",
|
|
70
|
-
});
|
|
71
|
-
},
|
|
72
|
-
async verifyIdToken(token, nonce) {
|
|
73
|
-
if (options.disableIdTokenSignIn) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (options.verifyIdToken) {
|
|
78
|
-
return options.verifyIdToken(token, nonce);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/* limited login */
|
|
82
|
-
// check is limited token
|
|
83
|
-
if (token.split(".").length === 3) {
|
|
84
|
-
try {
|
|
85
|
-
const { payload: jwtClaims } = await jwtVerify(
|
|
86
|
-
token,
|
|
87
|
-
createRemoteJWKSet(
|
|
88
|
-
// https://developers.facebook.com/docs/facebook-login/limited-login/token/#jwks
|
|
89
|
-
new URL(
|
|
90
|
-
"https://limited.facebook.com/.well-known/oauth/openid/jwks/",
|
|
91
|
-
),
|
|
92
|
-
),
|
|
93
|
-
{
|
|
94
|
-
algorithms: ["RS256"],
|
|
95
|
-
audience: options.clientId,
|
|
96
|
-
issuer: "https://www.facebook.com",
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
if (nonce && jwtClaims.nonce !== nonce) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return !!jwtClaims;
|
|
105
|
-
} catch (error) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/* access_token */
|
|
111
|
-
return true;
|
|
112
|
-
},
|
|
113
|
-
refreshAccessToken: options.refreshAccessToken
|
|
114
|
-
? options.refreshAccessToken
|
|
115
|
-
: async (refreshToken) => {
|
|
116
|
-
return refreshAccessToken({
|
|
117
|
-
refreshToken,
|
|
118
|
-
options: {
|
|
119
|
-
clientId: options.clientId,
|
|
120
|
-
clientKey: options.clientKey,
|
|
121
|
-
clientSecret: options.clientSecret,
|
|
122
|
-
},
|
|
123
|
-
tokenEndpoint:
|
|
124
|
-
"https://graph.facebook.com/v18.0/oauth/access_token",
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
async getUserInfo(token) {
|
|
128
|
-
if (options.getUserInfo) {
|
|
129
|
-
return options.getUserInfo(token);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (token.idToken && token.idToken.split(".").length === 3) {
|
|
133
|
-
const profile = decodeJwt(token.idToken) as {
|
|
134
|
-
sub: string;
|
|
135
|
-
email: string;
|
|
136
|
-
name: string;
|
|
137
|
-
picture: string;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const user = {
|
|
141
|
-
id: profile.sub,
|
|
142
|
-
name: profile.name,
|
|
143
|
-
email: profile.email,
|
|
144
|
-
picture: {
|
|
145
|
-
data: {
|
|
146
|
-
url: profile.picture,
|
|
147
|
-
height: 100,
|
|
148
|
-
width: 100,
|
|
149
|
-
is_silhouette: false,
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// https://developers.facebook.com/docs/facebook-login/limited-login/permissions
|
|
155
|
-
const userMap = await options.mapProfileToUser?.({
|
|
156
|
-
...user,
|
|
157
|
-
email_verified: true,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
user: {
|
|
162
|
-
...user,
|
|
163
|
-
emailVerified: true,
|
|
164
|
-
...userMap,
|
|
165
|
-
},
|
|
166
|
-
data: profile,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const fields = [
|
|
171
|
-
"id",
|
|
172
|
-
"name",
|
|
173
|
-
"email",
|
|
174
|
-
"picture",
|
|
175
|
-
...(options?.fields || []),
|
|
176
|
-
];
|
|
177
|
-
const { data: profile, error } = await betterFetch<FacebookProfile>(
|
|
178
|
-
"https://graph.facebook.com/me?fields=" + fields.join(","),
|
|
179
|
-
{
|
|
180
|
-
auth: {
|
|
181
|
-
type: "Bearer",
|
|
182
|
-
token: token.accessToken,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
);
|
|
186
|
-
if (error) {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
const userMap = await options.mapProfileToUser?.(profile);
|
|
190
|
-
return {
|
|
191
|
-
user: {
|
|
192
|
-
id: profile.id,
|
|
193
|
-
name: profile.name,
|
|
194
|
-
email: profile.email,
|
|
195
|
-
image: profile.picture.data.url,
|
|
196
|
-
emailVerified: profile.email_verified,
|
|
197
|
-
...userMap,
|
|
198
|
-
},
|
|
199
|
-
data: profile,
|
|
200
|
-
};
|
|
201
|
-
},
|
|
202
|
-
options,
|
|
203
|
-
} satisfies OAuthProvider<FacebookProfile>;
|
|
204
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
-
import { logger } from "../env";
|
|
3
|
-
import { PayvoAuthError } from "../error";
|
|
4
|
-
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
5
|
-
import {
|
|
6
|
-
createAuthorizationURL,
|
|
7
|
-
refreshAccessToken,
|
|
8
|
-
validateAuthorizationCode,
|
|
9
|
-
} from "../oauth2";
|
|
10
|
-
|
|
11
|
-
export interface FigmaProfile {
|
|
12
|
-
id: string;
|
|
13
|
-
email: string;
|
|
14
|
-
handle: string;
|
|
15
|
-
img_url: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface FigmaOptions extends ProviderOptions<FigmaProfile> {
|
|
19
|
-
clientId: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const figma = (options: FigmaOptions) => {
|
|
23
|
-
return {
|
|
24
|
-
id: "figma",
|
|
25
|
-
name: "Figma",
|
|
26
|
-
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
27
|
-
if (!options.clientId || !options.clientSecret) {
|
|
28
|
-
logger.error(
|
|
29
|
-
"Client Id and Client Secret are required for Figma. Make sure to provide them in the options."
|
|
30
|
-
);
|
|
31
|
-
throw new PayvoAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
32
|
-
}
|
|
33
|
-
if (!codeVerifier) {
|
|
34
|
-
throw new PayvoAuthError("codeVerifier is required for Figma");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const _scopes = options.disableDefaultScope ? [] : ["file_read"];
|
|
38
|
-
if (options.scope) _scopes.push(...options.scope);
|
|
39
|
-
if (scopes) _scopes.push(...scopes);
|
|
40
|
-
|
|
41
|
-
const url = await createAuthorizationURL({
|
|
42
|
-
id: "figma",
|
|
43
|
-
options,
|
|
44
|
-
authorizationEndpoint: "https://www.figma.com/oauth",
|
|
45
|
-
scopes: _scopes,
|
|
46
|
-
state,
|
|
47
|
-
codeVerifier,
|
|
48
|
-
redirectURI,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return url;
|
|
52
|
-
},
|
|
53
|
-
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
54
|
-
return validateAuthorizationCode({
|
|
55
|
-
code,
|
|
56
|
-
codeVerifier,
|
|
57
|
-
redirectURI,
|
|
58
|
-
options,
|
|
59
|
-
tokenEndpoint: "https://www.figma.com/api/oauth/token",
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
refreshAccessToken: options.refreshAccessToken
|
|
63
|
-
? options.refreshAccessToken
|
|
64
|
-
: async (refreshToken) => {
|
|
65
|
-
return refreshAccessToken({
|
|
66
|
-
refreshToken,
|
|
67
|
-
options: {
|
|
68
|
-
clientId: options.clientId,
|
|
69
|
-
clientKey: options.clientKey,
|
|
70
|
-
clientSecret: options.clientSecret,
|
|
71
|
-
},
|
|
72
|
-
tokenEndpoint: "https://www.figma.com/api/oauth/token",
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
async getUserInfo(token) {
|
|
76
|
-
if (options.getUserInfo) {
|
|
77
|
-
return options.getUserInfo(token);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const { data: profile } = await betterFetch<FigmaProfile>(
|
|
82
|
-
"https://api.figma.com/v1/me",
|
|
83
|
-
{
|
|
84
|
-
headers: {
|
|
85
|
-
Authorization: `Bearer ${token.accessToken}`,
|
|
86
|
-
},
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
if (!profile) {
|
|
91
|
-
logger.error("Failed to fetch user from Figma");
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const userMap = await options.mapProfileToUser?.(profile);
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
user: {
|
|
99
|
-
id: profile.id,
|
|
100
|
-
name: profile.handle,
|
|
101
|
-
email: profile.email,
|
|
102
|
-
image: profile.img_url,
|
|
103
|
-
emailVerified: !!profile.email,
|
|
104
|
-
...userMap,
|
|
105
|
-
},
|
|
106
|
-
data: profile,
|
|
107
|
-
};
|
|
108
|
-
} catch (error) {
|
|
109
|
-
logger.error("Failed to fetch user info from Figma:", error);
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
options,
|
|
114
|
-
} satisfies OAuthProvider<FigmaProfile>;
|
|
115
|
-
};
|
|
@@ -1,154 +0,0 @@
|
|
|
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 GithubProfile {
|
|
10
|
-
login: string;
|
|
11
|
-
id: string;
|
|
12
|
-
node_id: string;
|
|
13
|
-
avatar_url: string;
|
|
14
|
-
gravatar_id: string;
|
|
15
|
-
url: string;
|
|
16
|
-
html_url: string;
|
|
17
|
-
followers_url: string;
|
|
18
|
-
following_url: string;
|
|
19
|
-
gists_url: string;
|
|
20
|
-
starred_url: string;
|
|
21
|
-
subscriptions_url: string;
|
|
22
|
-
organizations_url: string;
|
|
23
|
-
repos_url: string;
|
|
24
|
-
events_url: string;
|
|
25
|
-
received_events_url: string;
|
|
26
|
-
type: string;
|
|
27
|
-
site_admin: boolean;
|
|
28
|
-
name: string;
|
|
29
|
-
company: string;
|
|
30
|
-
blog: string;
|
|
31
|
-
location: string;
|
|
32
|
-
email: string;
|
|
33
|
-
hireable: boolean;
|
|
34
|
-
bio: string;
|
|
35
|
-
twitter_username: string;
|
|
36
|
-
public_repos: string;
|
|
37
|
-
public_gists: string;
|
|
38
|
-
followers: string;
|
|
39
|
-
following: string;
|
|
40
|
-
created_at: string;
|
|
41
|
-
updated_at: string;
|
|
42
|
-
private_gists: string;
|
|
43
|
-
total_private_repos: string;
|
|
44
|
-
owned_private_repos: string;
|
|
45
|
-
disk_usage: string;
|
|
46
|
-
collaborators: string;
|
|
47
|
-
two_factor_authentication: boolean;
|
|
48
|
-
plan: {
|
|
49
|
-
name: string;
|
|
50
|
-
space: string;
|
|
51
|
-
private_repos: string;
|
|
52
|
-
collaborators: string;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface GithubOptions extends ProviderOptions<GithubProfile> {
|
|
57
|
-
clientId: string;
|
|
58
|
-
}
|
|
59
|
-
export const github = (options: GithubOptions) => {
|
|
60
|
-
const tokenEndpoint = "https://github.com/login/oauth/access_token";
|
|
61
|
-
return {
|
|
62
|
-
id: "github",
|
|
63
|
-
name: "GitHub",
|
|
64
|
-
createAuthorizationURL({ state, scopes, loginHint, redirectURI }) {
|
|
65
|
-
const _scopes = options.disableDefaultScope
|
|
66
|
-
? []
|
|
67
|
-
: ["read:user", "user:email"];
|
|
68
|
-
if (options.scope) _scopes.push(...options.scope);
|
|
69
|
-
if (scopes) _scopes.push(...scopes);
|
|
70
|
-
return createAuthorizationURL({
|
|
71
|
-
id: "github",
|
|
72
|
-
options,
|
|
73
|
-
authorizationEndpoint: "https://github.com/login/oauth/authorize",
|
|
74
|
-
scopes: _scopes,
|
|
75
|
-
state,
|
|
76
|
-
redirectURI,
|
|
77
|
-
loginHint,
|
|
78
|
-
prompt: options.prompt,
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
validateAuthorizationCode: async ({ code, redirectURI }) => {
|
|
82
|
-
return validateAuthorizationCode({
|
|
83
|
-
code,
|
|
84
|
-
redirectURI,
|
|
85
|
-
options,
|
|
86
|
-
tokenEndpoint,
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
refreshAccessToken: options.refreshAccessToken
|
|
90
|
-
? options.refreshAccessToken
|
|
91
|
-
: async (refreshToken) => {
|
|
92
|
-
return refreshAccessToken({
|
|
93
|
-
refreshToken,
|
|
94
|
-
options: {
|
|
95
|
-
clientId: options.clientId,
|
|
96
|
-
clientKey: options.clientKey,
|
|
97
|
-
clientSecret: options.clientSecret,
|
|
98
|
-
},
|
|
99
|
-
tokenEndpoint: "https://github.com/login/oauth/access_token",
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
async getUserInfo(token) {
|
|
103
|
-
if (options.getUserInfo) {
|
|
104
|
-
return options.getUserInfo(token);
|
|
105
|
-
}
|
|
106
|
-
const { data: profile, error } = await betterFetch<GithubProfile>(
|
|
107
|
-
"https://api.github.com/user",
|
|
108
|
-
{
|
|
109
|
-
headers: {
|
|
110
|
-
"User-Agent": "gatwech",
|
|
111
|
-
authorization: `Bearer ${token.accessToken}`,
|
|
112
|
-
},
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
if (error) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
const { data: emails } = await betterFetch<
|
|
119
|
-
{
|
|
120
|
-
email: string;
|
|
121
|
-
primary: boolean;
|
|
122
|
-
verified: boolean;
|
|
123
|
-
visibility: "public" | "private";
|
|
124
|
-
}[]
|
|
125
|
-
>("https://api.github.com/user/emails", {
|
|
126
|
-
headers: {
|
|
127
|
-
Authorization: `Bearer ${token.accessToken}`,
|
|
128
|
-
"User-Agent": "gatwech",
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
if (!profile.email && emails) {
|
|
133
|
-
profile.email = (emails.find((e) => e.primary) ?? emails[0])
|
|
134
|
-
?.email as string;
|
|
135
|
-
}
|
|
136
|
-
const emailVerified =
|
|
137
|
-
emails?.find((e) => e.email === profile.email)?.verified ?? false;
|
|
138
|
-
|
|
139
|
-
const userMap = await options.mapProfileToUser?.(profile);
|
|
140
|
-
return {
|
|
141
|
-
user: {
|
|
142
|
-
id: profile.id,
|
|
143
|
-
name: profile.name || profile.login,
|
|
144
|
-
email: profile.email,
|
|
145
|
-
image: profile.avatar_url,
|
|
146
|
-
emailVerified,
|
|
147
|
-
...userMap,
|
|
148
|
-
},
|
|
149
|
-
data: profile,
|
|
150
|
-
};
|
|
151
|
-
},
|
|
152
|
-
options,
|
|
153
|
-
} satisfies OAuthProvider<GithubProfile>;
|
|
154
|
-
};
|
|
@@ -1,152 +0,0 @@
|
|
|
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 GitlabProfile extends Record<string, any> {
|
|
10
|
-
id: number;
|
|
11
|
-
username: string;
|
|
12
|
-
email: string;
|
|
13
|
-
name: string;
|
|
14
|
-
state: string;
|
|
15
|
-
avatar_url: string;
|
|
16
|
-
web_url: string;
|
|
17
|
-
created_at: string;
|
|
18
|
-
bio: string;
|
|
19
|
-
location?: string | undefined;
|
|
20
|
-
public_email: string;
|
|
21
|
-
skype: string;
|
|
22
|
-
linkedin: string;
|
|
23
|
-
twitter: string;
|
|
24
|
-
website_url: string;
|
|
25
|
-
organization: string;
|
|
26
|
-
job_title: string;
|
|
27
|
-
pronouns: string;
|
|
28
|
-
bot: boolean;
|
|
29
|
-
work_information?: string | undefined;
|
|
30
|
-
followers: number;
|
|
31
|
-
following: number;
|
|
32
|
-
local_time: string;
|
|
33
|
-
last_sign_in_at: string;
|
|
34
|
-
confirmed_at: string;
|
|
35
|
-
theme_id: number;
|
|
36
|
-
last_activity_on: string;
|
|
37
|
-
color_scheme_id: number;
|
|
38
|
-
projects_limit: number;
|
|
39
|
-
current_sign_in_at: string;
|
|
40
|
-
identities: Array<{
|
|
41
|
-
provider: string;
|
|
42
|
-
extern_uid: string;
|
|
43
|
-
}>;
|
|
44
|
-
can_create_group: boolean;
|
|
45
|
-
can_create_project: boolean;
|
|
46
|
-
two_factor_enabled: boolean;
|
|
47
|
-
external: boolean;
|
|
48
|
-
private_profile: boolean;
|
|
49
|
-
commit_email: string;
|
|
50
|
-
shared_runners_minutes_limit: number;
|
|
51
|
-
extra_shared_runners_minutes_limit: number;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface GitlabOptions extends ProviderOptions<GitlabProfile> {
|
|
55
|
-
clientId: string;
|
|
56
|
-
issuer?: string | undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const cleanDoubleSlashes = (input: string = "") => {
|
|
60
|
-
return input
|
|
61
|
-
.split("://")
|
|
62
|
-
.map((str) => str.replace(/\/{2,}/g, "/"))
|
|
63
|
-
.join("://");
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const issuerToEndpoints = (issuer?: string | undefined) => {
|
|
67
|
-
let baseUrl = issuer || "https://gitlab.com";
|
|
68
|
-
return {
|
|
69
|
-
authorizationEndpoint: cleanDoubleSlashes(`${baseUrl}/oauth/authorize`),
|
|
70
|
-
tokenEndpoint: cleanDoubleSlashes(`${baseUrl}/oauth/token`),
|
|
71
|
-
userinfoEndpoint: cleanDoubleSlashes(`${baseUrl}/api/v4/user`),
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const gitlab = (options: GitlabOptions) => {
|
|
76
|
-
const { authorizationEndpoint, tokenEndpoint, userinfoEndpoint } =
|
|
77
|
-
issuerToEndpoints(options.issuer);
|
|
78
|
-
const issuerId = "gitlab";
|
|
79
|
-
const issuerName = "Gitlab";
|
|
80
|
-
return {
|
|
81
|
-
id: issuerId,
|
|
82
|
-
name: issuerName,
|
|
83
|
-
createAuthorizationURL: async ({
|
|
84
|
-
state,
|
|
85
|
-
scopes,
|
|
86
|
-
codeVerifier,
|
|
87
|
-
loginHint,
|
|
88
|
-
redirectURI,
|
|
89
|
-
}) => {
|
|
90
|
-
const _scopes = options.disableDefaultScope ? [] : ["read_user"];
|
|
91
|
-
if (options.scope) _scopes.push(...options.scope);
|
|
92
|
-
if (scopes) _scopes.push(...scopes);
|
|
93
|
-
return await createAuthorizationURL({
|
|
94
|
-
id: issuerId,
|
|
95
|
-
options,
|
|
96
|
-
authorizationEndpoint,
|
|
97
|
-
scopes: _scopes,
|
|
98
|
-
state,
|
|
99
|
-
redirectURI,
|
|
100
|
-
codeVerifier,
|
|
101
|
-
loginHint,
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
validateAuthorizationCode: async ({ code, redirectURI, codeVerifier }) => {
|
|
105
|
-
return validateAuthorizationCode({
|
|
106
|
-
code,
|
|
107
|
-
redirectURI,
|
|
108
|
-
options,
|
|
109
|
-
codeVerifier,
|
|
110
|
-
tokenEndpoint,
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
refreshAccessToken: options.refreshAccessToken
|
|
114
|
-
? options.refreshAccessToken
|
|
115
|
-
: async (refreshToken) => {
|
|
116
|
-
return refreshAccessToken({
|
|
117
|
-
refreshToken,
|
|
118
|
-
options: {
|
|
119
|
-
clientId: options.clientId,
|
|
120
|
-
clientKey: options.clientKey,
|
|
121
|
-
clientSecret: options.clientSecret,
|
|
122
|
-
},
|
|
123
|
-
tokenEndpoint: tokenEndpoint,
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
async getUserInfo(token) {
|
|
127
|
-
if (options.getUserInfo) {
|
|
128
|
-
return options.getUserInfo(token);
|
|
129
|
-
}
|
|
130
|
-
const { data: profile, error } = await betterFetch<GitlabProfile>(
|
|
131
|
-
userinfoEndpoint,
|
|
132
|
-
{ headers: { authorization: `Bearer ${token.accessToken}` } },
|
|
133
|
-
);
|
|
134
|
-
if (error || profile.state !== "active" || profile.locked) {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
const userMap = await options.mapProfileToUser?.(profile);
|
|
138
|
-
return {
|
|
139
|
-
user: {
|
|
140
|
-
id: profile.id,
|
|
141
|
-
name: profile.name ?? profile.username,
|
|
142
|
-
email: profile.email,
|
|
143
|
-
image: profile.avatar_url,
|
|
144
|
-
emailVerified: true,
|
|
145
|
-
...userMap,
|
|
146
|
-
},
|
|
147
|
-
data: profile,
|
|
148
|
-
};
|
|
149
|
-
},
|
|
150
|
-
options,
|
|
151
|
-
} satisfies OAuthProvider<GitlabProfile>;
|
|
152
|
-
};
|