From ff3defd057fbff2db87764ab764bbc0bae1350b5 Mon Sep 17 00:00:00 2001 From: konarfil Date: Thu, 21 Sep 2023 13:44:08 +0200 Subject: [PATCH] Redirection fixes --- src/flow/code-1.html | 8 +++++++- src/flow/code-3.html | 23 +++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/flow/code-1.html b/src/flow/code-1.html index b562eac..12d467a 100644 --- a/src/flow/code-1.html +++ b/src/flow/code-1.html @@ -145,13 +145,19 @@ + "&" + "state=" + state; } + function getRedirectUri() { + return window.location.protocol + "//" + window.location.host + "/flow/code-2"; + } + const baseUrl = "https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/auth"; const responseType = "code"; const clientId = "oauth-playground"; - const redirectUri = "http://localhost:5555/flow/code-2"; + const redirectUri = getRedirectUri(); const scope = "offline_access"; const state = generateSessionState(); +console.debug(window.location); + $("#sendRequestBtn").attr("href", constructRequestUrl()); $("#baseUrl").text(baseUrl); diff --git a/src/flow/code-3.html b/src/flow/code-3.html index 3245950..9cc7261 100644 --- a/src/flow/code-3.html +++ b/src/flow/code-3.html @@ -102,29 +102,32 @@ $(".page-footer").load("../layout/footer.html"); $("#page-header").load("../layout/header.html"); + const tokenEndpoint = 'https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/token'; + const clientID = 'oauth-playground'; + const code = new URLSearchParams(window.location.search).get('code'); + function fillRequestExample() { const requestExample = "POST https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/token?" + "\n\n" + "grant_type=authorization_code" + "\n" - + "&client_id=oauth-playground" + "\n" - + "&redirect_uri=http://localhost:5555/flow/code-2" + "\n" - + "&code=--Vto71vecBQbZnbA7ErehWHVQq4x1pm5YtA9Rr7x5zjhMGS"; + + "&client_id=" + clientID + "\n" + + "&redirect_uri=" + getRedirectUri() + "\n" + + "&code=" + code; $("#requestExample").text(requestExample); } - function getToken() { - const urlParams = new URLSearchParams(window.location.search); - const code = urlParams.get('code'); + function getRedirectUri() { + return window.location.protocol + "//" + window.location.host + "/flow/code-2"; + } - const tokenEndpoint = 'https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/token'; - const clientID = 'oauth-playground'; - const redirectURI = 'http://localhost:5555/flow/code-2'; + function getToken() { + const redirectURI = getRedirectUri(); const bodyData = new URLSearchParams(); bodyData.append('grant_type', 'authorization_code'); bodyData.append('client_id', clientID); - bodyData.append('redirect_uri', redirectURI); + bodyData.append('redirect_uri', getRedirectUri()); bodyData.append('code', code); fetch(tokenEndpoint, {