From c3c6d4cbbabebb4488f750911fff42e78a578d85 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Wed, 14 Jan 2015 15:17:22 +0100 Subject: [PATCH] Add redirect_uri to access token request in keycloak.js --- integration/js/src/main/resources/keycloak.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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; }