Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/2_bug_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ body:
- "Bitbucket"
- "Box"
- "Bungie"
- "Casdoor"
- "ClickUp"
- "Cognito"
- "Concept2"
Expand Down
1 change: 1 addition & 0 deletions docs/pages/data/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"box": "Box",
"boxyhq-saml": "BoxyHQ SAML",
"bungie": "Bungie",
"casdoor": "Casdoor",
"click-up": "ClickUp",
"cognito": "Cognito",
"coinbase": "Coinbase",
Expand Down
87 changes: 87 additions & 0 deletions docs/pages/getting-started/providers/casdoor.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Code } from "@/components/Code"

<img align="right" src="/img/providers/casdoor.svg" width="64" height="65" />

# 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

<Code>
<Code.Next>

```bash
https://example.com/api/auth/callback/casdoor
```

</Code.Next>
<Code.Qwik>

```bash
https://example.com/auth/callback/casdoor
```

</Code.Qwik>
<Code.Svelte>

```bash
https://example.com/auth/callback/casdoor
```

</Code.Svelte>
</Code>

### Environment Variables

```
AUTH_CASDOOR_ID
AUTH_CASDOOR_SECRET
AUTH_CASDOOR_ISSUER=https://door.casdoor.com
```

### Configuration

<Code>
<Code.Next>

```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],
})
```

</Code.Next>
<Code.Svelte>

```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],
})
```

</Code.Svelte>
<Code.Express>

```ts filename="/src/app.ts"
import { ExpressAuth } from "@auth/express"
import Casdoor from "@auth/express/providers/casdoor"

app.use("/auth/*", ExpressAuth({ providers: [Casdoor] }))
```

</Code.Express>
</Code>
3 changes: 3 additions & 0 deletions docs/public/img/providers/casdoor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions packages/core/src/providers/casdoor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* <div class="provider" style={{display: "flex", justifyContent: "space-between", alignItems: "center"}}>
* <span style={{fontSize: "1.35rem" }}>
* Built-in sign in with <b>Casdoor</b> integration.
* </span>
* <a href="https://casdoor.org" style={{backgroundColor: "#1772ff", padding: "12px", borderRadius: "100%" }}>
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/casdoor.svg" width="24"/>
* </a>
* </div>
*
* @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<string, any> {
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<CasdoorProfile>
): OIDCConfig<CasdoorProfile> {
return {
id: "casdoor",
name: "Casdoor",
type: "oidc",
authorization: {
params: {
scope: "openid email profile phone",
},
},
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: profile.picture,
}
},
options,
}
}