From 568802ce7c90f1e24a5083551277a3aa7652084b Mon Sep 17 00:00:00 2001 From: Repumba Date: Wed, 4 Jan 2023 18:03:12 +0100 Subject: [PATCH 01/25] initial commit --- docker-compose-oidc-dev.yml | 2 ++ mwdb/web/src/components/Settings/Views/OAuthProvider.js | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/docker-compose-oidc-dev.yml b/docker-compose-oidc-dev.yml index 44f01e402..53cced4de 100644 --- a/docker-compose-oidc-dev.yml +++ b/docker-compose-oidc-dev.yml @@ -64,6 +64,8 @@ services: env_file: # NOTE: use gen_vars.sh in order to generate this file - postgres-vars.env + ports: + - "127.0.0.1:54322:5432" redis: image: redis:alpine mailhog: diff --git a/mwdb/web/src/components/Settings/Views/OAuthProvider.js b/mwdb/web/src/components/Settings/Views/OAuthProvider.js index cc1b32f2b..d52e9be72 100644 --- a/mwdb/web/src/components/Settings/Views/OAuthProvider.js +++ b/mwdb/web/src/components/Settings/Views/OAuthProvider.js @@ -131,6 +131,14 @@ export default function OAuthProvider() { onSubmit={handleSubmit} /> + + + Actions: From c4c2ebd5666fc8657110f74a6b47df7339f71947 Mon Sep 17 00:00:00 2001 From: Repumba Date: Wed, 4 Jan 2023 18:20:03 +0100 Subject: [PATCH 02/25] create logout_endpoint column --- ...3d1497694_create_logout_endpoint_column.py | 33 +++++++++++++++++++ .../Settings/Views/OAuthRegister.js | 10 ++++++ 2 files changed, 43 insertions(+) create mode 100644 mwdb/model/migrations/versions/bd93d1497694_create_logout_endpoint_column.py diff --git a/mwdb/model/migrations/versions/bd93d1497694_create_logout_endpoint_column.py b/mwdb/model/migrations/versions/bd93d1497694_create_logout_endpoint_column.py new file mode 100644 index 000000000..75599ca24 --- /dev/null +++ b/mwdb/model/migrations/versions/bd93d1497694_create_logout_endpoint_column.py @@ -0,0 +1,33 @@ +"""create_logout_endpoint_column + +Revision ID: bd93d1497694 +Revises: 25ea40a798ac +Create Date: 2023-01-04 17:14:22.271856 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "bd93d1497694" +down_revision = "25ea40a798ac" +branch_labels = None +depends_on = None + + +def upgrade(): + op.execute( + """ + ALTER TABLE public.openid_provider + ADD logout_endpoint text; + """ + ) + + +def downgrade(): + op.execute( + """ + ALTER TABLE public.openid_provider + DROP COLUMN logout_endpoint; + """ + ) diff --git a/mwdb/web/src/components/Settings/Views/OAuthRegister.js b/mwdb/web/src/components/Settings/Views/OAuthRegister.js index 72856251d..8ca191ec3 100644 --- a/mwdb/web/src/components/Settings/Views/OAuthRegister.js +++ b/mwdb/web/src/components/Settings/Views/OAuthRegister.js @@ -131,6 +131,16 @@ export default function OAuthRegister() { className="form-control" /> +
+ + +
Date: Thu, 5 Jan 2023 15:21:38 +0100 Subject: [PATCH 03/25] Implement using discovery/configuration endpoint --- .../Settings/Views/OAuthRegister.js | 100 +++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/mwdb/web/src/components/Settings/Views/OAuthRegister.js b/mwdb/web/src/components/Settings/Views/OAuthRegister.js index 8ca191ec3..1f2a5ea35 100644 --- a/mwdb/web/src/components/Settings/Views/OAuthRegister.js +++ b/mwdb/web/src/components/Settings/Views/OAuthRegister.js @@ -1,12 +1,14 @@ -import React, { useContext, useState } from "react"; +import React, { useContext, useState, useCallback, useEffect } from "react"; import { APIContext } from "@mwdb-web/commons/api/context"; -import { useViewAlert } from "@mwdb-web/commons/ui"; +import { ShowIf, useViewAlert } from "@mwdb-web/commons/ui"; export default function OAuthRegister() { const api = useContext(APIContext); const viewAlert = useViewAlert(); + const [discoverData, setDiscoverData] = useState(); + const [discoverURL, setDiscoverURL] = useState(); const [values, setValues] = useState({ userinfo_endpoint: "", jwks_endpoint: "", @@ -15,6 +17,7 @@ export default function OAuthRegister() { authorization_endpoint: "", client_id: "", client_secret: "", + logout_endpoint: "", }); function handleInputChange(event) { @@ -27,6 +30,24 @@ export default function OAuthRegister() { })); } + function autoFill() { + if (!discoverData) return; + console.log(values); + const keys = Object.keys(values); + for (const i in keys) { + values[keys[i]] = discoverData[keys[i]]; + } + if (typeof discoverData["jwks_uri"] === "undefined") + discoverData["jwks_uri"] = ""; + + if (typeof discoverData["end_session_endpoint"] === "undefined") + discoverData["end_session_endpoint"] = ""; + + values["jwks_endpoint"] = discoverData["jwks_uri"]; + values["logout_endpoint"] = discoverData["end_session_endpoint"]; + setDiscoverURL(""); + } + async function registerProvider() { try { await api.oauthRegisterProvider( @@ -47,9 +68,84 @@ export default function OAuthRegister() { } } + async function updateDiscoverData() { + try { + var req = new Request(discoverURL); + fetch(req) + .then(async (response) => { + return await response.json(); + }) + .then((x) => { + setDiscoverData(x); + }); + } catch (e) { + viewAlert.setAlert({ e }); + } + } + + const getDiscover = useCallback(updateDiscoverData, [ + discoverURL, + viewAlert, + ]); + const autoFillCallback = useCallback(autoFill, [ + discoverData, + values, + viewAlert, + ]); + + useEffect(() => { + getDiscover(); + }, [getDiscover]); + useEffect(() => { + autoFillCallback(); + }, [autoFillCallback]); + return (

Register new identity provider

+
{ + e.preventDefault(); + setDiscoverURL(e.target.discover_endpoint.value); + }} + > +
+ + +
+
+ +
+ +