diff --git a/integration/js/src/main/resources/keycloak.js b/integration/js/src/main/resources/keycloak.js index 51e564dd27..697f118ea5 100755 --- a/integration/js/src/main/resources/keycloak.js +++ b/integration/js/src/main/resources/keycloak.js @@ -120,7 +120,7 @@ redirectUri += (redirectUri.indexOf('?') == -1 ? '?' : '&') + 'prompt=' + options.prompt; } - sessionStorage.oauthState = state; + sessionStorage.oauthState = JSON.stringify({ state: state, redirectUri: encodeURIComponent(redirectUri) }); var url = getRealmUrl() + '/tokens/login' @@ -315,6 +315,8 @@ params += '&client_id=' + encodeURIComponent(kc.clientId); } + params += '&redirect_uri=' + oauth.redirectUri; + req.withCredentials = true; req.onreadystatechange = function() { @@ -538,9 +540,13 @@ } } - if ((oauth.code || oauth.error) && oauth.state && oauth.state == sessionStorage.oauthState) { + var sessionState = sessionStorage.oauthState && JSON.parse(sessionStorage.oauthState); + + if (sessionState && (oauth.code || oauth.error) && oauth.state && oauth.state == sessionState.state) { delete sessionStorage.oauthState; + oauth.redirectUri = sessionState.redirectUri; + if (oauth.fragment) { oauth.newUrl += '#' + oauth.fragment; }