@@ -70,6 +70,8 @@ public sealed class PhoneAuthProvider : global::System.IDisposable {
70
70
/// Callback used when phone number auto-verification succeeded.
71
71
[ System . Obsolete ( "Please use `VerificationCompleted(PhoneAuthCredential)` instead" , false ) ]
72
72
public delegate void VerificationCompleted_DEPRECATED ( Credential credential ) ;
73
+ /// Callback used when phone number auto-verification succeeded.
74
+ public delegate void VerificationCompleted ( PhoneAuthCredential credential ) ;
73
75
/// Callback used when phone number verification fails.
74
76
public delegate void VerificationFailed ( string error ) ;
75
77
/// Callback used when a verification code is sent to the given number.
@@ -82,7 +84,8 @@ public delegate void CodeSent(string verificationId,
82
84
83
85
// Class to hold the delegates the user provides to the verification flow.
84
86
private class PhoneAuthDelegates {
85
- public VerificationCompleted_DEPRECATED verificationCompleted ;
87
+ public VerificationCompleted_DEPRECATED verificationCompleted_DEPRECATED ;
88
+ public VerificationCompleted verificationCompleted ;
86
89
public VerificationFailed verificationFailed ;
87
90
public CodeSent codeSent ;
88
91
public CodeAutoRetrievalTimeOut timeOut ;
@@ -99,12 +102,14 @@ private class PhoneAuthDelegates {
99
102
/// when the C++ library indicates a callback.
100
103
///
101
104
/// @return The unique identifier for the cached callbacks.
102
- private static int SaveCallbacks ( VerificationCompleted_DEPRECATED verificationCompleted ,
105
+ private static int SaveCallbacks ( VerificationCompleted_DEPRECATED verificationCompleted_DEPRECATED ,
106
+ VerificationCompleted verificationCompleted ,
103
107
VerificationFailed verificationFailed ,
104
108
CodeSent codeSent ,
105
109
CodeAutoRetrievalTimeOut timeOut ) {
106
110
int uid = uidGenerator ++ ;
107
111
var delegates = new PhoneAuthDelegates {
112
+ verificationCompleted_DEPRECATED = verificationCompleted_DEPRECATED ,
108
113
verificationCompleted = verificationCompleted ,
109
114
verificationFailed = verificationFailed ,
110
115
codeSent = codeSent ,
@@ -117,10 +122,27 @@ private static int SaveCallbacks(VerificationCompleted_DEPRECATED verificationCo
117
122
}
118
123
119
124
[ MonoPInvokeCallback ( typeof ( PhoneAuthProviderInternal . VerificationCompletedDelegate_DEPRECATED ) ) ]
120
- private static void VerificationCompleted_DEPRECATEDHandler ( int callbackId ,
125
+ private static void VerificationCompletedHandler_DEPRECATED ( int callbackId ,
121
126
System . IntPtr credential ) {
122
127
ExceptionAggregator . Wrap ( ( ) => {
123
128
Credential c = new Credential ( credential , true ) ;
129
+ lock ( authCallbacks ) {
130
+ PhoneAuthDelegates callbacks ;
131
+ if ( authCallbacks . TryGetValue ( callbackId , out callbacks ) &&
132
+ callbacks . verificationCompleted_DEPRECATED != null ) {
133
+ callbacks . verificationCompleted_DEPRECATED ( c ) ;
134
+ } else {
135
+ c . Dispose ( ) ;
136
+ }
137
+ }
138
+ } ) ;
139
+ }
140
+
141
+ [ MonoPInvokeCallback ( typeof ( PhoneAuthProviderInternal . VerificationCompletedDelegate ) ) ]
142
+ private static void VerificationCompletedHandler ( int callbackId ,
143
+ System . IntPtr credential ) {
144
+ ExceptionAggregator . Wrap ( ( ) => {
145
+ PhoneAuthCredential c = new PhoneAuthCredential ( credential , true ) ;
124
146
lock ( authCallbacks ) {
125
147
PhoneAuthDelegates callbacks ;
126
148
if ( authCallbacks . TryGetValue ( callbackId , out callbacks ) &&
@@ -178,7 +200,11 @@ private static void TimeOutHandler(int callbackId, string verificationId) {
178
200
private static PhoneAuthProviderInternal . VerificationCompletedDelegate_DEPRECATED
179
201
verificationCompletedDelegate_DEPRECATED =
180
202
new PhoneAuthProviderInternal . VerificationCompletedDelegate_DEPRECATED (
181
- VerificationCompleted_DEPRECATEDHandler ) ;
203
+ VerificationCompletedHandler_DEPRECATED ) ;
204
+ private static PhoneAuthProviderInternal . VerificationCompletedDelegate
205
+ verificationCompletedDelegate =
206
+ new PhoneAuthProviderInternal . VerificationCompletedDelegate (
207
+ VerificationCompletedHandler ) ;
182
208
private static PhoneAuthProviderInternal . VerificationFailedDelegate
183
209
verificationFailedDelegate =
184
210
new PhoneAuthProviderInternal . VerificationFailedDelegate (
@@ -197,6 +223,7 @@ private static void InitializeCallbacks() {
197
223
if ( ! callbacksInitialized ) {
198
224
callbacksInitialized = true ;
199
225
PhoneAuthProviderInternal . SetCallbacks ( verificationCompletedDelegate_DEPRECATED ,
226
+ verificationCompletedDelegate ,
200
227
verificationFailedDelegate ,
201
228
codeSentDelegate ,
202
229
timeOutDelegate ) ;
@@ -369,15 +396,59 @@ public void VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs,
369
396
VerificationFailed verificationFailed ,
370
397
CodeSent codeSent ,
371
398
CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut ) {
372
- int callbackId = SaveCallbacks ( verificationCompleted , verificationFailed ,
373
- codeSent , codeAutoRetrievalTimeOut ) ;
399
+ int callbackId = SaveCallbacks (
400
+ verificationCompleted_DEPRECATED : verificationCompleted ,
401
+ verificationCompleted : null ,
402
+ verificationFailed : verificationFailed ,
403
+ codeSent : codeSent ,
404
+ timeOut : codeAutoRetrievalTimeOut ) ;
374
405
System . IntPtr listener = InternalProvider . VerifyPhoneNumberInternal (
375
406
phoneNumber , autoVerifyTimeOutMs , forceResendingToken , callbackId ) ;
376
407
lock ( cppListeners ) {
377
408
cppListeners . Add ( callbackId , listener ) ;
378
409
}
379
410
}
380
411
412
+
413
+ /// Start the phone number authentication operation.
414
+ ///
415
+ /// @note On iOS the verificationCompleted callback is never invoked and the
416
+ /// codeAutoRetrievalTimeOut callback is invoked immediately since auto-validation is not
417
+ /// supported on that platform.
418
+ ///
419
+ /// @param[in] options The PhoneAuthOptions struct with a verification
420
+ /// configuration.
421
+ /// @param[in] verificationCompleted Phone number auto-verification succeeded.
422
+ /// Called when auto-sms-retrieval or instant validation succeeds.
423
+ /// Provided with the completed credential.
424
+ /// @param[in] verificationFailed Phone number verification failed with an
425
+ /// error. For example, quota exceeded or unknown phone number format.
426
+ /// Provided with a description of the error.
427
+ /// @param[in] codeSent SMS message with verification code sent to phone
428
+ /// number. Provided with the verification id to pass along to
429
+ /// `GetCredential` along with the sent code, and a token to use if
430
+ /// the user requests another SMS message be sent.
431
+ /// @param[in] codeAutoRetrievalTimeOut The timeout specified has expired.
432
+ /// Provided with the verification id for the transaction that timed out.
433
+ public void VerifyPhoneNumber (
434
+ PhoneAuthOptions options ,
435
+ VerificationCompleted verificationCompleted ,
436
+ VerificationFailed verificationFailed ,
437
+ CodeSent codeSent ,
438
+ CodeAutoRetrievalTimeOut codeAutoRetrievalTimeOut ) {
439
+ int callbackId = SaveCallbacks (
440
+ verificationCompleted_DEPRECATED : null ,
441
+ verificationCompleted : verificationCompleted ,
442
+ verificationFailed : verificationFailed ,
443
+ codeSent : codeSent ,
444
+ timeOut : codeAutoRetrievalTimeOut ) ;
445
+ System . IntPtr listener = InternalProvider . VerifyPhoneNumberInternal (
446
+ options , callbackId ) ;
447
+ lock ( cppListeners ) {
448
+ cppListeners . Add ( callbackId , listener ) ;
449
+ }
450
+ }
451
+
381
452
// The SWIG generated PhoneAuthProvider which contains the C++ object.
382
453
private PhoneAuthProviderInternal InternalProvider ;
383
454
internal PhoneAuthProvider ( FirebaseAuth auth ) {
@@ -435,6 +506,20 @@ public Credential GetCredential_DEPRECATED(string verificationId,
435
506
string verificationCode ) {
436
507
return InternalProvider . GetCredential_DEPRECATED ( verificationId , verificationCode ) ;
437
508
}
509
+
510
+ /// Generate a credential for the given phone number.
511
+ ///
512
+ /// @param[in] verification_id The id returned when sending the verification
513
+ /// code. Sent to the caller via @ref Listener::OnCodeSent.
514
+ /// @param[in] verification_code The verification code supplied by the user,
515
+ /// most likely by a GUI where the user manually enters the code
516
+ /// received in the SMS sent by @ref VerifyPhoneNumber.
517
+ ///
518
+ /// @returns New PhoneAuthCredential.
519
+ public PhoneAuthCredential GetCredential ( string verificationId ,
520
+ string verificationCode ) {
521
+ return InternalProvider . GetCredential ( verificationId , verificationCode ) ;
522
+ }
438
523
}
439
524
440
525
} // namespace Firebase.Auth
0 commit comments