Skip to content

Commit

Permalink
add Keycloak provider
Browse files Browse the repository at this point in the history
  • Loading branch information
bbigras committed Aug 18, 2021
1 parent e06ced5 commit ffbec8e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/.env.local.example
Expand Up @@ -13,6 +13,10 @@ AUTH0_ID=
AUTH0_SECRET=
AUTH0_ISSUER=

KEYCLOAK_ID=
KEYCLOAK_SECRET=
KEYCLOAK_ISSUER=

IDS4_ID=
IDS4_SECRET=
IDS4_ISSUER=
Expand Down
6 changes: 6 additions & 0 deletions app/pages/api/auth/[...nextauth].ts
Expand Up @@ -2,6 +2,7 @@ import NextAuth from "next-auth"
import EmailProvider from "next-auth/providers/email"
import GitHubProvider from "next-auth/providers/github"
import Auth0Provider from "next-auth/providers/auth0"
import KeycloakProvider from "next-auth/providers/keycloak"
import TwitterProvider from "next-auth/providers/twitter"
import CredentialsProvider from "next-auth/providers/credentials"
import IDS4Provider from "next-auth/providers/identity-server4"
Expand Down Expand Up @@ -77,6 +78,11 @@ export default NextAuth({
clientSecret: process.env.AUTH0_SECRET,
issuer: process.env.AUTH0_ISSUER,
}),
KeycloakProvider({
clientId: process.env.KEYCLOAK_ID,
clientSecret: process.env.KEYCLOAK_SECRET,
issuer: process.env.KEYCLOAK_ISSUER,
}),
Twitch({
clientId: process.env.TWITCH_ID,
clientSecret: process.env.TWITCH_SECRET,
Expand Down
20 changes: 20 additions & 0 deletions src/providers/keycloak.js
@@ -0,0 +1,20 @@
/** @type {import("types/providers").OAuthProvider} */
export default function Keycloak(options) {
return {
id: "keycloak",
name: "Keycloak",
wellKnown: `${options.issuer}/.well-known/openid-configuration`,
type: "oauth",
authorization: { params: { scope: "openid email profile" } },
checks: ["pkce", "state"],
idToken: true,
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
}
},
options,
}
}
41 changes: 41 additions & 0 deletions www/docs/providers/keycloak.md
@@ -0,0 +1,41 @@
---
id: keycloak
title: Keycloak
---

## Documentation

https://www.keycloak.org/docs/latest/server_admin/#_oidc_clients

## Configuration

:::tip
Create an openid-connect client in Keycloak with "confidential" as the "Access Type".
:::

## Options

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

- [Keycloak Provider options](https://github.com/nextauthjs/next-auth/blob/main/src/providers/keycloak.js)

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

## Example

```js
import Providers from `next-auth/providers`
...
providers: [
Providers.Keycloak({
clientId: process.env.KEYCLOAK_ID,
clientSecret: process.env.KEYCLOAK_SECRET,
issuer: process.env.KEYCLOAK_ISSUER,
})
]
...
```

:::note
`issuer` should include the realm – e.g. `https://my-keycloak-domain.com/auth/realms/My_Realm`
:::

0 comments on commit ffbec8e

Please sign in to comment.