From e478cedef7a76511ff4a0fa83bf03fd0cb51d588 Mon Sep 17 00:00:00 2001 From: Felix Eckhofer Date: Wed, 31 Aug 2022 10:22:06 +0000 Subject: [PATCH] Add generic SSO authentication support --- .../installation/backend-config.md | 6 ++++ .../installation/frontend-config.md | 8 +++++ frontend/nuxt.config.js | 6 +++- frontend/pages/login.vue | 19 ++++++++++-- frontend/schemes/maybeSSO.ts | 21 ++++++++++++++ frontend/store/index.js | 24 +++++++++++++++ frontend/types/ts-shim.d.ts | 4 +++ mealie/core/security/security.py | 29 +++++++++++++++++-- mealie/core/settings/settings.py | 5 ++++ mealie/routes/auth/auth.py | 7 ++--- template.env | 5 ++++ 11 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 frontend/schemes/maybeSSO.ts diff --git a/docs/docs/documentation/getting-started/installation/backend-config.md b/docs/docs/documentation/getting-started/installation/backend-config.md index 051bc1f6a3..636ecf9714 100644 --- a/docs/docs/documentation/getting-started/installation/backend-config.md +++ b/docs/docs/documentation/getting-started/installation/backend-config.md @@ -67,3 +67,9 @@ Changing the webworker settings may cause unforeseen memory leak issues with Mea | LDAP_SERVER_URL | None | LDAP server URL (e.g. ldap://ldap.example.com) | | LDAP_BIND_TEMPLATE | None | Templated DN for users, `{}` will be replaced with the username (e.g. `cn={},dc=example,dc=com`) | | LDAP_ADMIN_FILTER | None | Optional LDAP filter, which tells Mealie the LDAP user is an admin (e.g. `(memberOf=cn=admins,dc=example,dc=com)`) | + +### SSO + +| Variables | Default | Description | +| ----------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| SSO_TRUSTED_HEADER_USER | None | Authenticate via an external SSO server with this HTTP header being trusted from a reverse proxy. Must be identical to the frontend setting of the same name. | diff --git a/docs/docs/documentation/getting-started/installation/frontend-config.md b/docs/docs/documentation/getting-started/installation/frontend-config.md index ad1c28ba73..b8dc3dddd1 100644 --- a/docs/docs/documentation/getting-started/installation/frontend-config.md +++ b/docs/docs/documentation/getting-started/installation/frontend-config.md @@ -27,3 +27,11 @@ Setting the following environmental variables will change the theme of the front | THEME_DARK_INFO | #1976D2 | Dark Theme Config Variable | | THEME_DARK_WARNING | #FF6D00 | Dark Theme Config Variable | | THEME_DARK_ERROR | #EF5350 | Dark Theme Config Variable | + +### SSO + +| Variables | Default | Description | +| ----------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| SSO_TRUSTED_HEADER_USER | None | Authenticate via an external SSO server with this HTTP header being trusted from a reverse proxy. Must be identical to the backend setting of the same name. | +| SSO_LOGIN_URL | None | URL to redirect to when a login is required. Must be an absolute URL. | +| SSO_LOGOUT_URL | None | URL to redirect to after the frontend logs the user out (logout page of the IdP) | diff --git a/frontend/nuxt.config.js b/frontend/nuxt.config.js index 53a7d030c4..8d8dbc2eb0 100644 --- a/frontend/nuxt.config.js +++ b/frontend/nuxt.config.js @@ -110,7 +110,8 @@ export default { }, // Options strategies: { - local: { + maybeSSO: { + scheme: './schemes/maybeSSO', resetOnError: true, token: { property: "access_token", @@ -235,6 +236,9 @@ export default { publicRuntimeConfig: { GLOBAL_MIDDLEWARE: process.env.GLOBAL_MIDDLEWARE || null, SUB_PATH: process.env.SUB_PATH || "", + SSO_TRUSTED_HEADER_USER: process.env.SSO_TRUSTED_HEADER_USER || null, + SSO_LOGIN_URL: process.env.SSO_LOGIN_URL || null, + SSO_LOGOUT_URL: process.env.SSO_LOGOUT_URL || null, axios: { browserBaseURL: process.env.SUB_PATH || "", }, diff --git a/frontend/pages/login.vue b/frontend/pages/login.vue index ea550e0a88..1e144a984b 100644 --- a/frontend/pages/login.vue +++ b/frontend/pages/login.vue @@ -109,7 +109,7 @@