Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(providers): add Duende IdentityServer 6 #4850

Merged
merged 12 commits into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/dev/pages/api/auth/[...nextauth].ts
Expand Up @@ -8,6 +8,7 @@ import TwitterProvider, {
} from "next-auth/providers/twitter"
import CredentialsProvider from "next-auth/providers/credentials"
import IDS4Provider from "next-auth/providers/identity-server4"
import DuendeIDS6Provider from "next-auth/providers/duende-identity-server6"
import Twitch from "next-auth/providers/twitch"
import GoogleProvider from "next-auth/providers/google"
import FacebookProvider from "next-auth/providers/facebook"
Expand Down Expand Up @@ -150,6 +151,11 @@ export const authOptions: NextAuthOptions = {
clientSecret: process.env.IDS4_SECRET,
issuer: process.env.IDS4_ISSUER,
}),
DuendeIDS6Provider({
clientId: process.env.DUENDE_IDS6_ID,
clientSecret: process.env.DUENDE_IDS6_SECRET,
issuer: process.env.DUENDE_IDS6_ISSUER,
}),
josh-the-dev marked this conversation as resolved.
Show resolved Hide resolved
DiscordProvider({
clientId: process.env.DISCORD_ID,
clientSecret: process.env.DISCORD_SECRET,
Expand Down
@@ -0,0 +1,53 @@
---
id: duende-identityserver6
title: DuendeIdentityServer6
---

## Documentation

https://docs.duendesoftware.com/identityserver/v6

## Options

The **DuendeIdentityServer6 Provider** comes with a set of default options:

- [DuendeIdentityServer6 Provider options](https://github.com/nextauthjs/next-auth/blob/main/src/providers/duende-identity-server6.ts)
josh-the-dev marked this conversation as resolved.
Show resolved Hide resolved

You can override any of the options to suit your own use case.

## Example

```js
import DuendeIDS6Provider from "next-auth/providers/duende-identity-server6"

...
providers: [
DuendeIDS6Provider({
clientId: process.env.DUENDE_IDS6_ID,
clientSecret: process.env.DUENDE_IDS6_SECRET,
issuer: process.env.DUENDE_IDS6_ISSUER,
})
]
...
```

## Demo IdentityServer

The configuration below is for the demo server at https://demo.duendesoftware.com/

If you want to try it out, you can copy and paste the configuration below.

You can sign in to the demo service with either <b>bob/bob</b> or <b>alice/alice</b>.

```js
import DuendeIDS6Provider from "next-auth/providers/duende-identity-server6"
...
providers: [
DuendeIDS6Provider({
clientId: process.env.DUENDE_IDS6_ID,
clientSecret: process.env.DUENDE_IDS6_SECRET,
issuer: "demo.duendesoftware.com",
})
josh-the-dev marked this conversation as resolved.
Show resolved Hide resolved
]
...
```
Expand Up @@ -54,6 +54,6 @@ providers: [
clientSecret: "secret",
protection: "pkce"
})
}
]
...
```
29 changes: 29 additions & 0 deletions packages/next-auth/src/providers/duende-identity-server6.ts
@@ -0,0 +1,29 @@
import type { OAuthConfig, OAuthUserConfig } from "./oauth"

export interface DuendeISUser extends Record<string, any> {
email: string
id: string
name: string
verified: boolean
}

export default function DuendeIdentityServer6<P extends DuendeISUser> (options :OAuthUserConfig<P>) : OAuthConfig<P> {
josh-the-dev marked this conversation as resolved.
Show resolved Hide resolved
return {
id: "duende-identityserver6",
name: "DuendeIdentityServer6",
type: "oauth",
wellKnown: `${options.issuer}/.well-known/openid-configuration`,
authorization: { params: { scope: "openid profile email" } },
checks: ["pkce", "state"],
idToken: true,
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: null,
}
},
options,
}
}