@@ -7,6 +7,8 @@ firebase._launchNotification = null;
77
88// we need to cache and restore the context, otherwise the next invocation is broken
99firebase . _rememberedContext = null ;
10+ firebase . _googleSignInIdToken = null ;
11+ firebase . _facebookAccessToken = null ;
1012
1113var fbCallbackManager = null ;
1214var GOOGLE_SIGNIN_INTENT_ID = 123 ;
@@ -654,8 +656,8 @@ firebase.login = function (arg) {
654656 fbCallbackManager ,
655657 new com . facebook . FacebookCallback ( {
656658 onSuccess : function ( loginResult ) {
657- var token = loginResult . getAccessToken ( ) . getToken ( ) ;
658- var authCredential = com . google . firebase . auth . FacebookAuthProvider . getCredential ( token ) ;
659+ firebase . _facebookAccessToken = loginResult . getAccessToken ( ) . getToken ( ) ;
660+ var authCredential = com . google . firebase . auth . FacebookAuthProvider . getCredential ( firebase . _facebookAccessToken ) ;
659661
660662 var user = com . google . firebase . auth . FirebaseAuth . getInstance ( ) . getCurrentUser ( ) ;
661663 if ( user ) {
@@ -728,9 +730,9 @@ firebase.login = function (arg) {
728730 var success = googleSignInResult . isSuccess ( ) ;
729731 if ( success ) {
730732 var googleSignInAccount = googleSignInResult . getSignInAccount ( ) ;
731- var idToken = googleSignInAccount . getIdToken ( ) ;
733+ firebase . _googleSignInIdToken = googleSignInAccount . getIdToken ( ) ;
732734 var accessToken = null ;
733- var authCredential = com . google . firebase . auth . GoogleAuthProvider . getCredential ( idToken , accessToken ) ;
735+ var authCredential = com . google . firebase . auth . GoogleAuthProvider . getCredential ( firebase . _googleSignInIdToken , accessToken ) ;
734736
735737 firebase . _mGoogleApiClient . connect ( ) ;
736738
@@ -772,6 +774,62 @@ firebase._alreadyLinkedToAuthProvider = function (user, providerId) {
772774 return false ;
773775} ;
774776
777+ firebase . reauthenticate = function ( arg ) {
778+ return new Promise ( function ( resolve , reject ) {
779+ try {
780+ var user = com . google . firebase . auth . FirebaseAuth . getInstance ( ) . getCurrentUser ( ) ;
781+ if ( user === null ) {
782+ reject ( "no current user" ) ;
783+ return ;
784+ }
785+
786+ var authCredential = null ;
787+ if ( arg . type === firebase . LoginType . PASSWORD ) {
788+ if ( ! arg . email || ! arg . password ) {
789+ reject ( "Auth type emailandpassword requires an email and password argument" ) ;
790+ } else {
791+ authCredential = com . google . firebase . auth . EmailAuthProvider . getCredential ( arg . email , arg . password ) ;
792+ }
793+
794+ } else if ( arg . type === firebase . LoginType . GOOGLE ) {
795+ if ( ! firebase . _googleSignInIdToken ) {
796+ reject ( "Not currently logged in with Google" ) ;
797+ return ;
798+ }
799+ authCredential = com . google . firebase . auth . GoogleAuthProvider . getCredential ( firebase . _googleSignInIdToken , null ) ;
800+
801+ } else if ( arg . type === firebase . LoginType . FACEBOOK ) {
802+ if ( ! firebase . _facebookAccessToken ) {
803+ reject ( "Not currently logged in with Facebook" ) ;
804+ return ;
805+ }
806+ authCredential = com . google . firebase . auth . FacebookAuthProvider . getCredential ( firebase . _facebookAccessToken ) ;
807+ }
808+
809+ if ( authCredential === null ) {
810+ reject ( "arg.type should be one of LoginType.PASSWORD | LoginType.GOOGLE | LoginType.FACEBOOK" ) ;
811+ return ;
812+ }
813+
814+ var onCompleteListener = new com . google . android . gms . tasks . OnCompleteListener ( {
815+ onComplete : function ( task ) {
816+ if ( task . isSuccessful ( ) ) {
817+ resolve ( ) ;
818+ } else {
819+ // TODO extract error
820+ reject ( "Reathentication failed" ) ;
821+ }
822+ }
823+ } ) ;
824+ user . reauthenticate ( authCredential ) . addOnCompleteListener ( onCompleteListener ) ;
825+
826+ } catch ( ex ) {
827+ console . log ( "Error in firebase.reauthenticate: " + ex ) ;
828+ reject ( ex ) ;
829+ }
830+ } ) ;
831+ } ;
832+
775833firebase . resetPassword = function ( arg ) {
776834 return new Promise ( function ( resolve , reject ) {
777835 try {
0 commit comments