@@ -15,10 +15,12 @@ import {
1515 OAuthCredentialOptions ,
1616 UserCredential ,
1717 UserProfileChangeRequest ,
18- AdditionalUserInfo
18+ AdditionalUserInfo ,
19+ IOAuthProvider
1920} from './common' ;
2021import lazy from '@nativescript/core/utils/lazy' ;
2122import { Application } from '@nativescript/core' ;
23+ import { FirebaseAuth } from '.' ;
2224
2325export { AdditionalUserInfo , ActionCodeInfo , ActionCodeInfoOperation , UserCredential , UserProfileChangeRequest } ;
2426
@@ -275,6 +277,30 @@ export class User implements IUser {
275277 } ) ;
276278 }
277279
280+ reauthenticateWithProvider ( provider : OAuthProvider ) : Promise < UserCredential > {
281+ return new Promise ( ( resolve , reject ) => {
282+ if ( provider . _isCustomProvider && provider . _builder ) {
283+ org . nativescript . firebaseauth . FirebaseAuth . User . reauthenticateWithProvider (
284+ Application . android . foregroundActivity || Application . android . startActivity ,
285+ this . native , provider . _builder , new org . nativescript . firebaseauth . FirebaseAuth . Callback ( {
286+ onSuccess ( success ) {
287+ resolve ( toUserCredential ( success ) ) ;
288+ } ,
289+ onError ( error ) {
290+ reject ( {
291+ message : error . getMessage ( ) ,
292+ native : error ,
293+ } ) ;
294+ } ,
295+ } )
296+ )
297+ } else {
298+ reject ( FirebaseError . fromNative ( null , 'OAuthProvider not configured' ) ) ;
299+ }
300+ } )
301+ }
302+
303+
278304 reauthenticateWithCredential ( credential : AuthCredential ) : Promise < UserCredential > {
279305 return new Promise ( ( resolve , reject ) => {
280306 if ( ! this . native ) {
@@ -775,11 +801,45 @@ export class OAuthCredential extends AuthCredential implements IOAuthCredential
775801 }
776802}
777803
778- export class OAuthProvider {
779- #providerId: string ;
780804
805+
806+ export class OAuthProvider implements IOAuthProvider {
807+ #providerId: string ;
808+ #customProvider: boolean ;
809+ #builder: com . google . firebase . auth . OAuthProvider . Builder ;
781810 constructor ( providerId : string ) {
782811 this . #providerId = providerId ;
812+ this . #customProvider = false ;
813+ }
814+
815+ get _isCustomProvider ( ) {
816+ return this . #customProvider;
817+ }
818+
819+ get _builder ( ) {
820+ return this . #builder
821+ }
822+
823+ addCustomParameter ( key : string , value : string ) {
824+ if ( ! this . #builder) {
825+ this . #builder = com . google . firebase . auth . OAuthProvider . newBuilder ( this . #providerId) ;
826+ this . #customProvider = true ;
827+ }
828+ this . #builder. addCustomParameter ( key , value ) ;
829+ }
830+
831+ setScopes ( scopes : string [ ] ) {
832+ if ( ! this . #builder) {
833+ this . #builder = com . google . firebase . auth . OAuthProvider . newBuilder ( this . #providerId) ;
834+ this . #customProvider = true ;
835+ }
836+ if ( Array . isArray ( scopes ) ) {
837+ const array = new java . util . ArrayList < string > ( ) ;
838+ scopes . forEach ( item => {
839+ array . add ( item ) ;
840+ } )
841+ this . #builder. setScopes ( array ) ;
842+ }
783843 }
784844
785845 credential ( optionsOrIdToken : OAuthCredentialOptions | string | null , accessToken ?: string ) {
@@ -1053,6 +1113,29 @@ export class Auth implements IAuth {
10531113 } ) ;
10541114 }
10551115
1116+ signInWithProvider ( provider : OAuthProvider ) : Promise < UserCredential > {
1117+ return new Promise ( ( resolve , reject ) => {
1118+ if ( provider . _isCustomProvider && provider . _builder ) {
1119+ org . nativescript . firebaseauth . FirebaseAuth . signInWithProvider (
1120+ Application . android . foregroundActivity || Application . android . startActivity ,
1121+ this . native , provider . _builder , new org . nativescript . firebaseauth . FirebaseAuth . Callback ( {
1122+ onSuccess ( success ) {
1123+ resolve ( toUserCredential ( success ) ) ;
1124+ } ,
1125+ onError ( error ) {
1126+ reject ( {
1127+ message : error . getMessage ( ) ,
1128+ native : error ,
1129+ } ) ;
1130+ } ,
1131+ } )
1132+ )
1133+ } else {
1134+ reject ( FirebaseError . fromNative ( null , 'OAuthProvider not configured' ) ) ;
1135+ }
1136+ } )
1137+ }
1138+
10561139 signInWithCredential ( credential : AuthCredential ) : Promise < UserCredential > {
10571140 return new Promise ( ( resolve , reject ) => {
10581141 if ( ! this . native ) {
0 commit comments