Skip to content

Commit ef48a5f

Browse files
committed
allowing prompt and login_hint params to be configured
nraboy#128
1 parent f1803f0 commit ef48a5f

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

dist/ng-cordova-oauth.js

+35-17
Original file line numberDiff line numberDiff line change
@@ -687,31 +687,49 @@ function google($q, $http, $cordovaOauthUtility) {
687687

688688
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
689689

690-
var redirect_uri, clear_cache, clear_session, approval_prompt, prompt, login_hint;
690+
var redirect_uri = 'http://localhost/callback',
691+
clear_cache = 'no',
692+
clear_session = 'no',
693+
prompt_options = [],
694+
login_hint;
691695

692-
options = options || {};
693-
694-
redirect_uri = options.redirect_uri || "http://localhost/callback";
695-
clear_cache = options.clear_cache === true ? 'yes' : 'no';
696-
clear_session = options.clear_session === true ? 'yes' : 'no';
697-
approval_prompt = options.approval_prompt === true ? 'force' : 'auto';
698-
prompt = options.prompt === true ? 'select_account' : 'consent select_account';
699-
login_hint = options.login_hint || '';
696+
if(options !== undefined) {
697+
if (options.hasOwnProperty("redirect_uri")) {
698+
redirect_uri = options.redirect_uri;
699+
}
700+
if (options.hasOwnProperty("clear_cache")) {
701+
clear_cache = options.clear_cache === true ? 'yes' : 'no';
702+
}
703+
if (options.hasOwnProperty("clear_session")) {
704+
clear_session = options.clear_session === true ? 'yes' : 'no';
705+
}
706+
if (options.hasOwnProperty("prompt")) {
707+
if (options.prompt === true) prompt_options.push('select_account');
708+
}
709+
if (options.hasOwnProperty("consent")) {
710+
if (options.consent === true) prompt_options.push('consent');
711+
}
712+
if (options.hasOwnProperty("login_hint")) {
713+
login_hint = options.login_hint;
714+
}
715+
}
700716

717+
if (prompt_options.length===0) prompt_options.push('none');
701718

702719
var browserRef = window.cordova.InAppBrowser.open(
703-
'https://accounts.google.com/o/oauth2/auth?client_id=' + clientId
704-
+ '&redirect_uri=' + redirect_uri
705-
+ '&scope=' + appScope.join(" ")
706-
+ '&approval_prompt=' + approval_prompt
720+
'https://accounts.google.com/o/oauth2/auth?'
721+
+ 'client_id=' + clientId
722+
+ '&redirect_uri=' + redirect_uri
723+
+ '&scope=' + appScope.join(" ")
707724
+ '&response_type=token'
708-
+ '&prompt=' + prompt
709-
+ '&login_hint=' + login_hint
725+
+ '&prompt=' + prompt_options.join(" ")
726+
+ '&login_hint=' + login_hint
710727

711728
, '_blank'
712729

713-
, 'location=no,clearsessioncache=' + clear_session
714-
+ ',clearcache=' + clear_cache
730+
, 'location=no'
731+
+ ',clearsessioncache=' + clear_session
732+
+ ',clearcache=' + clear_cache
715733
);
716734

717735
browserRef.addEventListener("loadstart", function(event) {

0 commit comments

Comments
 (0)