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(auth-provider): add support for oidc auth provider #338

Closed
wants to merge 7 commits into from
Closed
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
9 changes: 9 additions & 0 deletions .changeset/olive-dancers-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'hasura-auth': patch
---

Added support for OpenID Connect auth provider

Tested with [Keycloak](http://keycloak.org/) but other OIDC providers should be working as well. It uses Authorization Code Flow.
In addition you can enable PKCE (Proof Key for Code Exchange) via the env variable `AUTH_PROVIDER_OIDC_PKCE`.

9 changes: 9 additions & 0 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,12 @@
| AUTH_PROVIDER_AZUREAD_CLIENT_ID | |
| AUTH_PROVIDER_AZUREAD_CLIENT_SECRET | |
| AUTH_PROVIDER_AZUREAD_TENANT | |
| AUTH_PROVIDER_OIDC_ENABLED | `false` |
| AUTH_PROVIDER_OIDC_AUTH_URL<b>\*</b> | |
| AUTH_PROVIDER_OIDC_TOKEN_URL<b>\*</b> | |
| AUTH_PROVIDER_OIDC_USERINFO_URL<b>\*</b> | |
| AUTH_PROVIDER_OIDC_CLIENT_ID<b>\*</b> | |
| AUTH_PROVIDER_OIDC_CLIENT_SECRET<b>\*</b> | |
| AUTH_PROVIDER_OIDC_SCOPE | `openid profile email` |
| AUTH_PROVIDER_OIDC_PKCE | `false` |

7 changes: 7 additions & 0 deletions migrations/00014_add-oidc-auth-provider.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- start a transaction
BEGIN;
INSERT INTO auth.providers (id)
VALUES ('oidc')
ON CONFLICT
DO NOTHING;
COMMIT;
21 changes: 21 additions & 0 deletions src/routes/oauth/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,25 @@ export const PROVIDERS_CONFIG: Record<
next();
},
},
oidc: {
grant: {
oauth: 2,
nonce: true,
scope_delimiter: ' ',
scope: ['openid', 'profile', 'email'],
elitan marked this conversation as resolved.
Show resolved Hide resolved
pkce: process.env.AUTH_PROVIDER_OIDC_PKCE === 'true',
authorize_url: `${process.env.AUTH_PROVIDER_OIDC_AUTH_URL}`,
access_url: `${process.env.AUTH_PROVIDER_OIDC_TOKEN_URL}`,
profile_url: `${process.env.AUTH_PROVIDER_OIDC_USER_INFO_URL}`,
client_id: process.env.AUTH_PROVIDER_OIDC_CLIEND_ID,
client_secret: process.env.AUTH_PROVIDER_OIDC_CLIENT_SECRET,
},
profile: ({ profile }) => ({
id: profile.sub,
email: profile.email,
emailVerified: profile.email_verified,
displayName: profile.name && profile.nickname,
avatarUrl: profile.picture,
elitan marked this conversation as resolved.
Show resolved Hide resolved
}),
},
};