Redirection fixes

This commit is contained in:
konarfil
2023-09-21 13:44:08 +02:00
parent e39fedfeac
commit ff3defd057
2 changed files with 20 additions and 11 deletions

View File

@@ -145,13 +145,19 @@
+ "&" + "state=" + state; + "&" + "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 baseUrl = "https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/auth";
const responseType = "code"; const responseType = "code";
const clientId = "oauth-playground"; const clientId = "oauth-playground";
const redirectUri = "http://localhost:5555/flow/code-2"; const redirectUri = getRedirectUri();
const scope = "offline_access"; const scope = "offline_access";
const state = generateSessionState(); const state = generateSessionState();
console.debug(window.location);
$("#sendRequestBtn").attr("href", constructRequestUrl()); $("#sendRequestBtn").attr("href", constructRequestUrl());
$("#baseUrl").text(baseUrl); $("#baseUrl").text(baseUrl);

View File

@@ -102,29 +102,32 @@
$(".page-footer").load("../layout/footer.html"); $(".page-footer").load("../layout/footer.html");
$("#page-header").load("../layout/header.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() { function fillRequestExample() {
const requestExample = const requestExample =
"POST https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/token?" + "\n\n" "POST https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/token?" + "\n\n"
+ "grant_type=authorization_code" + "\n" + "grant_type=authorization_code" + "\n"
+ "&client_id=oauth-playground" + "\n" + "&client_id=" + clientID + "\n"
+ "&redirect_uri=http://localhost:5555/flow/code-2" + "\n" + "&redirect_uri=" + getRedirectUri() + "\n"
+ "&code=--Vto71vecBQbZnbA7ErehWHVQq4x1pm5YtA9Rr7x5zjhMGS"; + "&code=" + code;
$("#requestExample").text(requestExample); $("#requestExample").text(requestExample);
} }
function getToken() { function getRedirectUri() {
const urlParams = new URLSearchParams(window.location.search); return window.location.protocol + "//" + window.location.host + "/flow/code-2";
const code = urlParams.get('code'); }
const tokenEndpoint = 'https://sso.rumbuddy.cz/realms/OAuthPlayground/protocol/openid-connect/token'; function getToken() {
const clientID = 'oauth-playground'; const redirectURI = getRedirectUri();
const redirectURI = 'http://localhost:5555/flow/code-2';
const bodyData = new URLSearchParams(); const bodyData = new URLSearchParams();
bodyData.append('grant_type', 'authorization_code'); bodyData.append('grant_type', 'authorization_code');
bodyData.append('client_id', clientID); bodyData.append('client_id', clientID);
bodyData.append('redirect_uri', redirectURI); bodyData.append('redirect_uri', getRedirectUri());
bodyData.append('code', code); bodyData.append('code', code);
fetch(tokenEndpoint, { fetch(tokenEndpoint, {