From 3f34ad66f77d39159a56b7b18ce8ae0509a48cc6 Mon Sep 17 00:00:00 2001
From: wushide <1747583024@qq.com>
Date: Tue, 7 Jan 2025 14:15:28 +0800
Subject: [PATCH 1/3] feat: add Gitee provider
---
packages/core/src/providers/gitee.ts | 94 ++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
create mode 100644 packages/core/src/providers/gitee.ts
diff --git a/packages/core/src/providers/gitee.ts b/packages/core/src/providers/gitee.ts
new file mode 100644
index 0000000000..fa3f60ab80
--- /dev/null
+++ b/packages/core/src/providers/gitee.ts
@@ -0,0 +1,94 @@
+/**
+ *
+ *
Built-in Gitee integration.
+ *
+ *
+ *
+ *
+ *
+ * @module providers/gitee
+ */
+import type { OAuthConfig, OAuthUserConfig } from "./index.js"
+import type { TokenSet } from "../types.js"
+export interface GiteeProfile {
+ id: number;
+ name?: string;
+ login: string;
+ email?: string;
+ avatar_url?: string;
+}
+
+export default function Gitee(
+ config: OAuthUserConfig
+): OAuthConfig {
+ const baseUrl = "https://gitee.com";
+ const apiBaseUrl = "https://gitee.com/api/v5";
+
+ return {
+ id: "gitee",
+ name: "Gitee",
+ type: "oauth",
+ authorization: {
+ url: `${baseUrl}/oauth/authorize`,
+ params: {
+ scope: "",
+ },
+ },
+ token: {
+ url: `${baseUrl}/oauth/token`,
+ params: {
+ grant_type: "authorization_code",
+ },
+ },
+ userinfo: {
+ url: `${apiBaseUrl}/user`,
+ request: async function ({
+ tokens,
+ provider,
+ }: {
+ tokens: TokenSet;
+ provider: {
+ token?: {
+ url: URL;
+ };
+ userinfo?: {
+ url?: URL;
+ };
+ };
+ }) {
+ const profile = await fetch(provider.userinfo?.url as URL, {
+ headers: {
+ Authorization: `Bearer ${tokens.access_token}`,
+ "User-Agent": "authjs",
+ },
+ }).then(async (res) => await res.json());
+
+ if (!profile.email) {
+ const res = await fetch(`${apiBaseUrl}/user/emails`, {
+ headers: {
+ Authorization: `Bearer ${tokens.access_token}`,
+ "User-Agent": "authjs",
+ },
+ });
+
+ if (res.ok) {
+ const emails: { primary: boolean; email: string }[] =
+ await res.json();
+ profile.email = (emails.find((e) => e.primary) ?? emails[0])?.email;
+ }
+ }
+
+ return profile;
+ },
+ },
+ profile(profile) {
+ return {
+ id: profile.id.toString(),
+ name: profile.name ?? profile.login,
+ email: profile.email,
+ image: profile.avatar_url,
+ };
+ },
+ options: config,
+ };
+}
From ab0d1fc6c3af4f9b14c79ab1d45144abb4ead9c5 Mon Sep 17 00:00:00 2001
From: wushide <1747583024@qq.com>
Date: Tue, 7 Jan 2025 14:38:59 +0800
Subject: [PATCH 2/3] feat: add Gitee provider SVG logo
---
docs/public/img/providers/gitee.svg | 1 +
1 file changed, 1 insertion(+)
create mode 100644 docs/public/img/providers/gitee.svg
diff --git a/docs/public/img/providers/gitee.svg b/docs/public/img/providers/gitee.svg
new file mode 100644
index 0000000000..8a79a649fc
--- /dev/null
+++ b/docs/public/img/providers/gitee.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
From 9149fe8bae878e7b4c4b13bdb1f8408e0cb0be7b Mon Sep 17 00:00:00 2001
From: wushide <1747583024@qq.com>
Date: Wed, 8 Jan 2025 09:10:32 +0800
Subject: [PATCH 3/3] fix: update gitee.svg
---
docs/public/img/providers/gitee.svg | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/public/img/providers/gitee.svg b/docs/public/img/providers/gitee.svg
index 8a79a649fc..3fbfac73df 100644
--- a/docs/public/img/providers/gitee.svg
+++ b/docs/public/img/providers/gitee.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file