From 147cb2930ace7c19dcd190520dfe9788533f48e9 Mon Sep 17 00:00:00 2001 From: DacongDA Date: Sat, 29 Nov 2025 16:56:48 +0800 Subject: [PATCH 1/2] feat(provider): add Casdoor provider --- .github/ISSUE_TEMPLATE/2_bug_provider.yml | 1 + docs/pages/data/manifest.json | 1 + .../getting-started/providers/casdoor.mdx | 87 +++++++++++++++++ docs/public/img/providers/casdoor.svg | 3 + packages/core/src/providers/casdoor.ts | 95 +++++++++++++++++++ 5 files changed, 187 insertions(+) create mode 100644 docs/pages/getting-started/providers/casdoor.mdx create mode 100644 docs/public/img/providers/casdoor.svg create mode 100644 packages/core/src/providers/casdoor.ts diff --git a/.github/ISSUE_TEMPLATE/2_bug_provider.yml b/.github/ISSUE_TEMPLATE/2_bug_provider.yml index 1ee4409a23..ab1e695be5 100644 --- a/.github/ISSUE_TEMPLATE/2_bug_provider.yml +++ b/.github/ISSUE_TEMPLATE/2_bug_provider.yml @@ -37,6 +37,7 @@ body: - "Bitbucket" - "Box" - "Bungie" + - "Casdoor" - "ClickUp" - "Cognito" - "Concept2" diff --git a/docs/pages/data/manifest.json b/docs/pages/data/manifest.json index 7fef03e029..d735fed24c 100644 --- a/docs/pages/data/manifest.json +++ b/docs/pages/data/manifest.json @@ -64,6 +64,7 @@ "box": "Box", "boxyhq-saml": "BoxyHQ SAML", "bungie": "Bungie", + "casdoor": "Casdoor", "click-up": "ClickUp", "cognito": "Cognito", "coinbase": "Coinbase", diff --git a/docs/pages/getting-started/providers/casdoor.mdx b/docs/pages/getting-started/providers/casdoor.mdx new file mode 100644 index 0000000000..601bab20ae --- /dev/null +++ b/docs/pages/getting-started/providers/casdoor.mdx @@ -0,0 +1,87 @@ +import { Code } from "@/components/Code" + + + +# Casdoor Provider + +## Resources + +- [Casdoor overview](https://casdoor.org/docs/overview) +- [Casdoor OpenID Connect API](https://door.casdoor.com/swagger/) + +> **_NOTE:_** Set `AUTH_CASDOOR_ISSUER` to the base URL of your Casdoor instance (defaults to `https://door.casdoor.com`). + +## Setup + +### Callback URL + + + + +```bash +https://example.com/api/auth/callback/casdoor +``` + + + + +```bash +https://example.com/auth/callback/casdoor +``` + + + + +```bash +https://example.com/auth/callback/casdoor +``` + + + + +### Environment Variables + +``` +AUTH_CASDOOR_ID +AUTH_CASDOOR_SECRET +AUTH_CASDOOR_ISSUER=https://door.casdoor.com +``` + +### Configuration + + + + +```ts filename="/auth.ts" +import NextAuth from "next-auth" +import Casdoor from "next-auth/providers/casdoor" + +export const { handlers, auth, signIn, signOut } = NextAuth({ + providers: [Casdoor], +}) +``` + + + + +```ts filename="/src/auth.ts" +import { SvelteKitAuth } from "@auth/sveltekit" +import Casdoor from "@auth/sveltekit/providers/casdoor" + +export const { handle, signIn, signOut } = SvelteKitAuth({ + providers: [Casdoor], +}) +``` + + + + +```ts filename="/src/app.ts" +import { ExpressAuth } from "@auth/express" +import Casdoor from "@auth/express/providers/casdoor" + +app.use("/auth/*", ExpressAuth({ providers: [Casdoor] })) +``` + + + \ No newline at end of file diff --git a/docs/public/img/providers/casdoor.svg b/docs/public/img/providers/casdoor.svg new file mode 100644 index 0000000000..78c25f2dea --- /dev/null +++ b/docs/public/img/providers/casdoor.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/core/src/providers/casdoor.ts b/packages/core/src/providers/casdoor.ts new file mode 100644 index 0000000000..fa8c2f3b6f --- /dev/null +++ b/packages/core/src/providers/casdoor.ts @@ -0,0 +1,95 @@ +/** + *
+ * + * Built-in sign in with Casdoor integration. + * + * + * + * + *
+ * + * @module providers/casdoor + */ + +import type { OIDCConfig, OIDCUserConfig } from "./index.js" + +/** + * The returned user profile from Casdoor when using the profile callback. Casdoor follows the + * [OpenID Connect standard claims](https://www.iana.org/assignments/jwt/jwt.xhtml#claims) and may return custom fields. + */ +export interface CasdoorProfile extends Record { + sub: string + name?: string + preferred_username?: string + email?: string + email_verified?: boolean + phone?: string + picture?: string +} + +/** + * ### Setup + * + * #### Callback URL + * ``` + * https://example.com/api/auth/callback/casdoor + * ``` + * + * #### Configuration + * ```ts + * import Casdoor from "@auth/core/providers/casdoor" + * ... + * providers: [ + * Casdoor({ + * clientId: env.AUTH_CASDOOR_ID, + * clientSecret: env.AUTH_CASDOOR_SECRET, + * issuer: env.AUTH_CASDOOR_ISSUER ?? "https://door.casdoor.com", // Your Casdoor instance + * }), + * ] + * ... + * ``` + * + * ### Resources + * + * - [Casdoor overview](https://casdoor.org/docs/overview) + * - [Casdoor OpenID Connect API](https://door.casdoor.com/swagger/) + * - [About OAuth in Auth.js](https://authjs.dev/concepts/oauth) + * + * ### Notes + * + * - Casdoor instances are self-hosted or cloud-hosted. Set the `issuer` to the base URL of the instance you manage (for example `https://door.casdoor.com`). + * - Casdoor exposes the standard `.well-known/openid-configuration` metadata, so no additional endpoints need to be configured. + * - Make sure the Redirect URI registered in Casdoor exactly matches the callback URL shown above. + * - The Casdoor provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/casdoor.ts). To override the defaults, see [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers). + * + * ## Help + * + * If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue). + * + * Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from + * the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, + * we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions). + */ +export default function Casdoor( + options: OIDCUserConfig +): OIDCConfig { + return { + id: "logto", + name: "Logto", + type: "oidc", + authorization: { + params: { + scope: "openid email profile phone", + }, + }, + profile(profile) { + return { + id: profile.sub, + name: profile.name ?? profile.username, + email: profile.email, + image: profile.picture, + } + }, + options, + } +} From cdfe0f71b856c64ccbad42ff4c870ef7ab889b9b Mon Sep 17 00:00:00 2001 From: DacongDA Date: Sat, 29 Nov 2025 17:01:19 +0800 Subject: [PATCH 2/2] fix: fix code error --- packages/core/src/providers/casdoor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/providers/casdoor.ts b/packages/core/src/providers/casdoor.ts index fa8c2f3b6f..6fd20e4a5c 100644 --- a/packages/core/src/providers/casdoor.ts +++ b/packages/core/src/providers/casdoor.ts @@ -74,8 +74,8 @@ export default function Casdoor( options: OIDCUserConfig ): OIDCConfig { return { - id: "logto", - name: "Logto", + id: "casdoor", + name: "Casdoor", type: "oidc", authorization: { params: { @@ -85,7 +85,7 @@ export default function Casdoor( profile(profile) { return { id: profile.sub, - name: profile.name ?? profile.username, + name: profile.name, email: profile.email, image: profile.picture, }