@@ -680,16 +680,44 @@ function google($q, $http, $cordovaOauthUtility) {
680
680
* @return promise
681
681
*/
682
682
function oauthGoogle ( clientId , appScope , options ) {
683
+
683
684
var deferred = $q . defer ( ) ;
685
+
684
686
if ( window . cordova ) {
687
+
685
688
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
+
687
695
if ( options !== undefined ) {
688
696
if ( options . hasOwnProperty ( "redirect_uri" ) ) {
689
697
redirect_uri = options . redirect_uri ;
690
698
}
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
+ }
691
708
}
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
+
693
721
browserRef . addEventListener ( "loadstart" , function ( event ) {
694
722
if ( ( event . url ) . indexOf ( redirect_uri ) === 0 ) {
695
723
browserRef . removeEventListener ( "exit" , function ( event ) { } ) ;
@@ -707,15 +735,19 @@ function google($q, $http, $cordovaOauthUtility) {
707
735
}
708
736
}
709
737
} ) ;
738
+
710
739
browserRef . addEventListener ( 'exit' , function ( event ) {
711
740
deferred . reject ( "The sign in flow was canceled" ) ;
712
741
} ) ;
742
+
713
743
} else {
714
744
deferred . reject ( "Could not find InAppBrowser plugin" ) ;
715
745
}
746
+
716
747
} else {
717
748
deferred . reject ( "Cannot authenticate via a web browser" ) ;
718
749
}
750
+
719
751
return deferred . promise ;
720
752
}
721
753
}
0 commit comments