Use redirectUri for the Cordova adapter (#17038)

This commit is contained in:
Marco Schmidlin 2023-02-13 16:54:29 +01:00 committed by GitHub
parent 9d0bee9c59
commit 537be78455
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1418,6 +1418,8 @@ function Keycloak (config) {
return formatCordovaOptions(cordovaOptions); return formatCordovaOptions(cordovaOptions);
}; };
var cordovaRedirectUri = kc.redirectUri || 'http://localhost';
return { return {
login: function(options) { login: function(options) {
var promise = createPromise(); var promise = createPromise();
@ -1434,7 +1436,7 @@ function Keycloak (config) {
}; };
ref.addEventListener('loadstart', function(event) { ref.addEventListener('loadstart', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf(cordovaRedirectUri) == 0) {
var callback = parseCallback(event.url); var callback = parseCallback(event.url);
processCallback(callback, promise); processCallback(callback, promise);
closeBrowser(); closeBrowser();
@ -1444,7 +1446,7 @@ function Keycloak (config) {
ref.addEventListener('loaderror', function(event) { ref.addEventListener('loaderror', function(event) {
if (!completed) { if (!completed) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf(cordovaRedirectUri) == 0) {
var callback = parseCallback(event.url); var callback = parseCallback(event.url);
processCallback(callback, promise); processCallback(callback, promise);
closeBrowser(); closeBrowser();
@ -1476,13 +1478,13 @@ function Keycloak (config) {
var error; var error;
ref.addEventListener('loadstart', function(event) { ref.addEventListener('loadstart', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf(cordovaRedirectUri) == 0) {
ref.close(); ref.close();
} }
}); });
ref.addEventListener('loaderror', function(event) { ref.addEventListener('loaderror', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf(cordovaRedirectUri) == 0) {
ref.close(); ref.close();
} else { } else {
error = true; error = true;
@ -1508,7 +1510,7 @@ function Keycloak (config) {
var cordovaOptions = createCordovaOptions(options); var cordovaOptions = createCordovaOptions(options);
var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', cordovaOptions); var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', cordovaOptions);
ref.addEventListener('loadstart', function(event) { ref.addEventListener('loadstart', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf(cordovaRedirectUri) == 0) {
ref.close(); ref.close();
var oauth = parseCallback(event.url); var oauth = parseCallback(event.url);
processCallback(oauth, promise); processCallback(oauth, promise);
@ -1522,7 +1524,7 @@ function Keycloak (config) {
if (typeof accountUrl !== 'undefined') { if (typeof accountUrl !== 'undefined') {
var ref = cordovaOpenWindowWrapper(accountUrl, '_blank', 'location=no'); var ref = cordovaOpenWindowWrapper(accountUrl, '_blank', 'location=no');
ref.addEventListener('loadstart', function(event) { ref.addEventListener('loadstart', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf(cordovaRedirectUri) == 0) {
ref.close(); ref.close();
} }
}); });
@ -1532,7 +1534,7 @@ function Keycloak (config) {
}, },
redirectUri: function(options) { redirectUri: function(options) {
return 'http://localhost'; return cordovaRedirectUri;
} }
} }
} }