New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KEYCLOAK-6655] Javascript Adapter - Allow users to provide cordova-specific options to login and register #4998
Changes from all commits
9043e64
65786f3
5d210fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1177,17 +1177,41 @@ | |
return window.open(loginUrl, target, options); | ||
} | ||
}; | ||
|
||
var shallowCloneCordovaOptions = function (userOptions) { | ||
if (userOptions && userOptions.cordovaOptions) { | ||
return Object.keys(userOptions.cordovaOptions).reduce(function (options, optionName) { | ||
options[optionName] = userOptions.cordovaOptions[optionName]; | ||
return options; | ||
}, {}); | ||
} else { | ||
return {}; | ||
} | ||
}; | ||
|
||
var formatCordovaOptions = function (cordovaOptions) { | ||
return Object.keys(cordovaOptions).reduce(function (options, optionName) { | ||
options.push(optionName+"="+cordovaOptions[optionName]); | ||
return options; | ||
}, []).join(","); | ||
}; | ||
|
||
var createCordovaOptions = function (userOptions) { | ||
var cordovaOptions = shallowCloneCordovaOptions(userOptions); | ||
cordovaOptions.location = 'no'; | ||
if (userOptions && userOptions.prompt == 'none') { | ||
cordovaOptions.hidden = 'yes'; | ||
} | ||
return formatCordovaOptions(cordovaOptions); | ||
}; | ||
|
||
return { | ||
login: function(options) { | ||
var promise = createPromise(); | ||
|
||
var o = 'location=no'; | ||
if (options && options.prompt == 'none') { | ||
o += ',hidden=yes'; | ||
} | ||
|
||
var cordovaOptions = createCordovaOptions(options); | ||
var loginUrl = kc.createLoginUrl(options); | ||
var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', o); | ||
var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions); | ||
var completed = false; | ||
|
||
ref.addEventListener('loadstart', function(event) { | ||
|
@@ -1218,7 +1242,7 @@ | |
|
||
logout: function(options) { | ||
var promise = createPromise(); | ||
|
||
var logoutUrl = kc.createLogoutUrl(options); | ||
var ref = cordovaOpenWindowWrapper(logoutUrl, '_blank', 'location=no,hidden=yes'); | ||
|
||
|
@@ -1253,7 +1277,8 @@ | |
|
||
register : function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a notion: It is not possible to add app-specific options for registration. Probably because registration is mostly invoked from the login page and not from some application page. Maybe it is possible to somehow get around this for example with some global options specified by a creator of the app. @looorent and @stianst what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the options to register function for the Cordova moda is missing for some reason. It does have it for the default mode. Not sure why, but sure that's not correct. I don't think it's in the scope of this PR though as it's already missing in master. |
||
var registerUrl = kc.createRegisterUrl(); | ||
var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', 'location=no'); | ||
var cordovaOptions = createCordovaOptions(options); | ||
var ref = cordovaOpenWindowWrapper(registerUrl, '_blank', cordovaOptions); | ||
ref.addEventListener('loadstart', function(event) { | ||
if (event.url.indexOf('http://localhost') == 0) { | ||
ref.close(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this empty line