Skip to content

Commit a605530

Browse files
committed
allowing session, cache and approval params to be configured
nraboy#128
1 parent 32d8190 commit a605530

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

dist/ng-cordova-oauth.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -680,16 +680,44 @@ function google($q, $http, $cordovaOauthUtility) {
680680
* @return promise
681681
*/
682682
function oauthGoogle(clientId, appScope, options) {
683+
683684
var deferred = $q.defer();
685+
684686
if(window.cordova) {
687+
685688
if($cordovaOauthUtility.isInAppBrowserInstalled()) {
686-
var redirect_uri = "http://localhost/callback";
689+
690+
var redirect_uri = "http://localhost/callback",
691+
clear_cache = 'no',
692+
clear_session = 'no',
693+
approval_prompt = 'auto';
694+
687695
if(options !== undefined) {
688696
if(options.hasOwnProperty("redirect_uri")) {
689697
redirect_uri = options.redirect_uri;
690698
}
699+
if(options.hasOwnProperty("clear_cache")) {
700+
clear_cache = options.clear_cache === true ? 'yes' : 'no';
701+
}
702+
if(options.hasOwnProperty("clear_session")) {
703+
clear_session = options.clear_session === true ? 'yes' : 'no';
704+
}
705+
if(options.hasOwnProperty("approval_prompt")) {
706+
approval_prompt = options.approval_prompt === true ? 'force' : 'auto';
707+
}
691708
}
692-
var browserRef = window.cordova.InAppBrowser.open('https://accounts.google.com/o/oauth2/auth?client_id=' + clientId + '&redirect_uri=' + redirect_uri + '&scope=' + appScope.join(" ") + '&approval_prompt=force&response_type=token', '_blank', 'location=no,clearsessioncache=yes,clearcache=yes');
709+
710+
var browserRef = window.cordova.InAppBrowser.open(
711+
'https://accounts.google.com/o/oauth2/auth?client_id=' + clientId
712+
+ '&redirect_uri=' + redirect_uri
713+
+ '&scope=' + appScope.join(" ")
714+
+ '&approval_prompt=' + approval_prompt
715+
+ '&response_type=token'
716+
, '_blank'
717+
, 'location=no,clearsessioncache=' + clear_session
718+
+ ',clearcache=' + clear_cache
719+
);
720+
693721
browserRef.addEventListener("loadstart", function(event) {
694722
if((event.url).indexOf(redirect_uri) === 0) {
695723
browserRef.removeEventListener("exit",function(event){});
@@ -707,15 +735,19 @@ function google($q, $http, $cordovaOauthUtility) {
707735
}
708736
}
709737
});
738+
710739
browserRef.addEventListener('exit', function(event) {
711740
deferred.reject("The sign in flow was canceled");
712741
});
742+
713743
} else {
714744
deferred.reject("Could not find InAppBrowser plugin");
715745
}
746+
716747
} else {
717748
deferred.reject("Cannot authenticate via a web browser");
718749
}
750+
719751
return deferred.promise;
720752
}
721753
}

0 commit comments

Comments
 (0)