@@ -15,10 +15,12 @@ import {
15
15
OAuthCredentialOptions ,
16
16
UserCredential ,
17
17
UserProfileChangeRequest ,
18
- AdditionalUserInfo
18
+ AdditionalUserInfo ,
19
+ IOAuthProvider
19
20
} from './common' ;
20
21
import lazy from '@nativescript/core/utils/lazy' ;
21
22
import { Application } from '@nativescript/core' ;
23
+ import { FirebaseAuth } from '.' ;
22
24
23
25
export { AdditionalUserInfo , ActionCodeInfo , ActionCodeInfoOperation , UserCredential , UserProfileChangeRequest } ;
24
26
@@ -275,6 +277,30 @@ export class User implements IUser {
275
277
} ) ;
276
278
}
277
279
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
+
278
304
reauthenticateWithCredential ( credential : AuthCredential ) : Promise < UserCredential > {
279
305
return new Promise ( ( resolve , reject ) => {
280
306
if ( ! this . native ) {
@@ -775,11 +801,45 @@ export class OAuthCredential extends AuthCredential implements IOAuthCredential
775
801
}
776
802
}
777
803
778
- export class OAuthProvider {
779
- #providerId: string ;
780
804
805
+
806
+ export class OAuthProvider implements IOAuthProvider {
807
+ #providerId: string ;
808
+ #customProvider: boolean ;
809
+ #builder: com . google . firebase . auth . OAuthProvider . Builder ;
781
810
constructor ( providerId : string ) {
782
811
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
+ }
783
843
}
784
844
785
845
credential ( optionsOrIdToken : OAuthCredentialOptions | string | null , accessToken ?: string ) {
@@ -1053,6 +1113,29 @@ export class Auth implements IAuth {
1053
1113
} ) ;
1054
1114
}
1055
1115
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
+
1056
1139
signInWithCredential ( credential : AuthCredential ) : Promise < UserCredential > {
1057
1140
return new Promise ( ( resolve , reject ) => {
1058
1141
if ( ! this . native ) {
0 commit comments