@@ -70,6 +70,8 @@ public sealed class PhoneAuthProvider : global::System.IDisposable {
7070 /// Callback used when phone number auto-verification succeeded.
7171 [ System . Obsolete ( "Please use `VerificationCompleted(PhoneAuthCredential)` instead" , false ) ]
7272 public delegate void VerificationCompleted_DEPRECATED ( Credential credential ) ;
73+ /// Callback used when phone number auto-verification succeeded.
74+ public delegate void VerificationCompleted ( PhoneAuthCredential credential ) ;
7375 /// Callback used when phone number verification fails.
7476 public delegate void VerificationFailed ( string error ) ;
7577 /// Callback used when a verification code is sent to the given number.
@@ -82,7 +84,8 @@ public delegate void CodeSent(string verificationId,
8284
8385 // Class to hold the delegates the user provides to the verification flow.
8486 private class PhoneAuthDelegates {
85- public VerificationCompleted_DEPRECATED verificationCompleted ;
87+ public VerificationCompleted_DEPRECATED verificationCompleted_DEPRECATED ;
88+ public VerificationCompleted verificationCompleted ;
8689 public VerificationFailed verificationFailed ;
8790 public CodeSent codeSent ;
8891 public CodeAutoRetrievalTimeOut timeOut ;
@@ -99,12 +102,14 @@ private class PhoneAuthDelegates {
99102 /// when the C++ library indicates a callback.
100103 ///
101104 /// @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 ,
103107 VerificationFailed verificationFailed ,
104108 CodeSent codeSent ,
105109 CodeAutoRetrievalTimeOut timeOut ) {
106110 int uid = uidGenerator ++ ;
107111 var delegates = new PhoneAuthDelegates {
112+ verificationCompleted_DEPRECATED = verificationCompleted_DEPRECATED ,
108113 verificationCompleted = verificationCompleted ,
109114 verificationFailed = verificationFailed ,
110115 codeSent = codeSent ,
@@ -117,10 +122,27 @@ private static int SaveCallbacks(VerificationCompleted_DEPRECATED verificationCo
117122 }
118123
119124 [ MonoPInvokeCallback ( typeof ( PhoneAuthProviderInternal . VerificationCompletedDelegate_DEPRECATED ) ) ]
120- private static void VerificationCompleted_DEPRECATEDHandler ( int callbackId ,
125+ private static void VerificationCompletedHandler_DEPRECATED ( int callbackId ,
121126 System . IntPtr credential ) {
122127 ExceptionAggregator . Wrap ( ( ) => {
123128 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 ) ;
124146 lock ( authCallbacks ) {
125147 PhoneAuthDelegates callbacks ;
126148 if ( authCallbacks . TryGetValue ( callbackId , out callbacks ) &&
@@ -178,7 +200,11 @@ private static void TimeOutHandler(int callbackId, string verificationId) {
178200 private static PhoneAuthProviderInternal . VerificationCompletedDelegate_DEPRECATED
179201 verificationCompletedDelegate_DEPRECATED =
180202 new PhoneAuthProviderInternal . VerificationCompletedDelegate_DEPRECATED (
181- VerificationCompleted_DEPRECATEDHandler ) ;
203+ VerificationCompletedHandler_DEPRECATED ) ;
204+ private static PhoneAuthProviderInternal . VerificationCompletedDelegate
205+ verificationCompletedDelegate =
206+ new PhoneAuthProviderInternal . VerificationCompletedDelegate (
207+ VerificationCompletedHandler ) ;
182208 private static PhoneAuthProviderInternal . VerificationFailedDelegate
183209 verificationFailedDelegate =
184210 new PhoneAuthProviderInternal . VerificationFailedDelegate (
@@ -197,6 +223,7 @@ private static void InitializeCallbacks() {
197223 if ( ! callbacksInitialized ) {
198224 callbacksInitialized = true ;
199225 PhoneAuthProviderInternal . SetCallbacks ( verificationCompletedDelegate_DEPRECATED ,
226+ verificationCompletedDelegate ,
200227 verificationFailedDelegate ,
201228 codeSentDelegate ,
202229 timeOutDelegate ) ;
@@ -369,15 +396,59 @@ public void VerifyPhoneNumber(string phoneNumber, uint autoVerifyTimeOutMs,
369396 VerificationFailed verificationFailed ,
370397 CodeSent codeSent ,
371398 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 ) ;
374405 System . IntPtr listener = InternalProvider . VerifyPhoneNumberInternal (
375406 phoneNumber , autoVerifyTimeOutMs , forceResendingToken , callbackId ) ;
376407 lock ( cppListeners ) {
377408 cppListeners . Add ( callbackId , listener ) ;
378409 }
379410 }
380411
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+
381452 // The SWIG generated PhoneAuthProvider which contains the C++ object.
382453 private PhoneAuthProviderInternal InternalProvider ;
383454 internal PhoneAuthProvider ( FirebaseAuth auth ) {
@@ -435,6 +506,20 @@ public Credential GetCredential_DEPRECATED(string verificationId,
435506 string verificationCode ) {
436507 return InternalProvider . GetCredential_DEPRECATED ( verificationId , verificationCode ) ;
437508 }
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+ }
438523}
439524
440525} // namespace Firebase.Auth
0 commit comments