@@ -105,6 +105,21 @@ public async Task<FirebaseAuthLink> SignInWithOAuthAsync(FirebaseAuthType authTy
|
105 | 105 | return await this.ExecuteWithPostContentAsync(GoogleIdentityUrl, content).ConfigureAwait(false);
|
106 | 106 | }
|
107 | 107 |
|
| 108 | +/// <summary> |
| 109 | +/// Using the provided Id token from google signin, get the firebase auth with token and basic user credentials. |
| 110 | +/// </summary> |
| 111 | +/// <param name="authType"> The auth type. </param> |
| 112 | +/// <param name="oauthAccessToken"> The access token retrieved from twitter. </param> |
| 113 | +/// <param name="oauthAccessToken"> The access token secret supplied by twitter. </param> |
| 114 | +/// <returns> The <see cref="FirebaseAuth"/>. </returns> |
| 115 | +public async Task<FirebaseAuthLink> SignInWithOAuthTwitterTokenAsync(string oauthAccessToken, string oauthTokenSecret) |
| 116 | +{ |
| 117 | +var providerId = this.GetProviderId(FirebaseAuthType.Twitter); |
| 118 | +var content = $"{{\"postBody\":\"access_token={oauthAccessToken}&oauth_token_secret={oauthTokenSecret}&providerId={providerId}\",\"requestUri\":\"http://localhost\",\"returnSecureToken\":true}}"; |
| 119 | + |
| 120 | +return await this.ExecuteWithPostContentAsync(GoogleIdentityUrl, content).ConfigureAwait(false); |
| 121 | +} |
| 122 | + |
108 | 123 | /// <summary>
|
109 | 124 | /// Using the provided Id token from google signin, get the firebase auth with token and basic user credentials.
|
110 | 125 | /// </summary>
|
@@ -263,10 +278,20 @@ public async Task DeleteUserAsync(string firebaseToken)
|
263 | 278 | public async Task SendPasswordResetEmailAsync(string email)
|
264 | 279 | {
|
265 | 280 | var content = $"{{\"requestType\":\"PASSWORD_RESET\",\"email\":\"{email}\"}}";
|
266 |
| - |
267 |
| -var response = await this.client.PostAsync(new Uri(string.Format(GoogleGetConfirmationCodeUrl, this.authConfig.ApiKey)), new StringContent(content, Encoding.UTF8, "application/json")).ConfigureAwait(false); |
268 |
| - |
269 |
| -response.EnsureSuccessStatusCode(); |
| 281 | +var responseData = "N/A"; |
| 282 | + |
| 283 | +try |
| 284 | +{ |
| 285 | +var response = await this.client.PostAsync(new Uri(string.Format(GoogleGetConfirmationCodeUrl, this.authConfig.ApiKey)), new StringContent(content, Encoding.UTF8, "application/json")).ConfigureAwait(false); |
| 286 | +responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 287 | + |
| 288 | +response.EnsureSuccessStatusCode(); |
| 289 | +} |
| 290 | +catch (Exception ex) |
| 291 | +{ |
| 292 | +AuthErrorReason errorReason = GetFailureReason(responseData); |
| 293 | +throw new FirebaseAuthException(GoogleGetConfirmationCodeUrl, content, responseData, ex, errorReason); |
| 294 | +} |
270 | 295 | }
|
271 | 296 |
|
272 | 297 | /// <summary>
|
@@ -494,6 +519,10 @@ private static AuthErrorReason GetFailureReason(string responseData)
|
494 | 519 | failureReason = AuthErrorReason.LoginCredentialsTooOld;
|
495 | 520 | break;
|
496 | 521 |
|
| 522 | +case "OPERATION_NOT_ALLOWED": |
| 523 | +failureReason = AuthErrorReason.OperationNotAllowed; |
| 524 | +break; |
| 525 | + |
497 | 526 | //possible errors from Third Party Authentication using GoogleIdentityUrl
|
498 | 527 | case "INVALID_PROVIDER_ID : Provider Id is not supported.":
|
499 | 528 | failureReason = AuthErrorReason.InvalidProviderID;
|
@@ -514,9 +543,6 @@ private static AuthErrorReason GetFailureReason(string responseData)
|
514 | 543 | break;
|
515 | 544 |
|
516 | 545 | //possible errors from Email/Password Account Signup (via signupNewUser or setAccountInfo)
|
517 |
| -case "WEAK_PASSWORD : Password should be at least 6 characters": |
518 |
| -failureReason = AuthErrorReason.WeakPassword; |
519 |
| -break; |
520 | 546 | case "EMAIL_EXISTS":
|
521 | 547 | failureReason = AuthErrorReason.EmailExists;
|
522 | 548 | break;
|
@@ -541,6 +567,9 @@ private static AuthErrorReason GetFailureReason(string responseData)
|
541 | 567 | case "MISSING_EMAIL":
|
542 | 568 | failureReason = AuthErrorReason.MissingEmail;
|
543 | 569 | break;
|
| 570 | +case "RESET_PASSWORD_EXCEED_LIMIT": |
| 571 | +failureReason = AuthErrorReason.ResetPasswordExceedLimit; |
| 572 | +break; |
544 | 573 |
|
545 | 574 | //possible errors from Password Recovery
|
546 | 575 | case "MISSING_REQ_TYPE":
|
@@ -563,6 +592,14 @@ private static AuthErrorReason GetFailureReason(string responseData)
|
563 | 592 | failureReason = AuthErrorReason.AlreadyLinked;
|
564 | 593 | break;
|
565 | 594 | }
|
| 595 | + |
| 596 | +if(failureReason == AuthErrorReason.Undefined) |
| 597 | +{ |
| 598 | +//possible errors from Email/Password Account Signup (via signupNewUser or setAccountInfo) |
| 599 | +if(errorData?.error?.message?.StartsWith("WEAK_PASSWORD :") ?? false) failureReason = AuthErrorReason.WeakPassword; |
| 600 | +//possible errors from Email/Password Signin |
| 601 | +else if (errorData?.error?.message?.StartsWith("TOO_MANY_ATTEMPTS_TRY_LATER :") ?? false) failureReason = AuthErrorReason.TooManyAttemptsTryLater; |
| 602 | +} |
566 | 603 | }
|
567 | 604 | }
|
568 | 605 | catch (JsonReaderException)
|
|
0 commit comments