File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ public enum AuthErrorReason
77
/// </summary>
88
Undefined,
99
/// <summary>
10+
/// The sign in method is not enabled.
11+
/// </summary>
12+
OperationNotAllowed,
13+
/// <summary>
1014
/// The user was disabled and is not granted access anymore.
1115
/// </summary>
1216
UserDisabled,
@@ -63,10 +67,18 @@ public enum AuthErrorReason
6367
/// </summary>
6468
WrongPassword,
6569
/// <summary>
70+
/// Email/Password Signin: Too many password login have been attempted. Try again later.
71+
/// </summary>
72+
TooManyAttemptsTryLater,
73+
/// <summary>
6674
/// Password Recovery: Request does not contain a value for parameter: requestType or supplied value is invalid.
6775
/// </summary>
6876
MissingRequestType,
6977
/// <summary>
78+
/// Password Recovery: Reset password limit exceeded.
79+
/// </summary>
80+
ResetPasswordExceedLimit,
81+
/// <summary>
7082
/// Account Linking: Authenticated User ID Token is invalid!
7183
/// </summary>
7284
InvalidIDToken,
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ public async Task<FirebaseAuthLink> SignInWithOAuthAsync(FirebaseAuthType authTy
105105
return await this.ExecuteWithPostContentAsync(GoogleIdentityUrl, content).ConfigureAwait(false);
106106
}
107107

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+
108123
/// <summary>
109124
/// Using the provided Id token from google signin, get the firebase auth with token and basic user credentials.
110125
/// </summary>
@@ -263,10 +278,20 @@ public async Task DeleteUserAsync(string firebaseToken)
263278
public async Task SendPasswordResetEmailAsync(string email)
264279
{
265280
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+
}
270295
}
271296

272297
/// <summary>
@@ -494,6 +519,10 @@ private static AuthErrorReason GetFailureReason(string responseData)
494519
failureReason = AuthErrorReason.LoginCredentialsTooOld;
495520
break;
496521

522+
case "OPERATION_NOT_ALLOWED":
523+
failureReason = AuthErrorReason.OperationNotAllowed;
524+
break;
525+
497526
//possible errors from Third Party Authentication using GoogleIdentityUrl
498527
case "INVALID_PROVIDER_ID : Provider Id is not supported.":
499528
failureReason = AuthErrorReason.InvalidProviderID;
@@ -514,9 +543,6 @@ private static AuthErrorReason GetFailureReason(string responseData)
514543
break;
515544

516545
//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;
520546
case "EMAIL_EXISTS":
521547
failureReason = AuthErrorReason.EmailExists;
522548
break;
@@ -541,6 +567,9 @@ private static AuthErrorReason GetFailureReason(string responseData)
541567
case "MISSING_EMAIL":
542568
failureReason = AuthErrorReason.MissingEmail;
543569
break;
570+
case "RESET_PASSWORD_EXCEED_LIMIT":
571+
failureReason = AuthErrorReason.ResetPasswordExceedLimit;
572+
break;
544573

545574
//possible errors from Password Recovery
546575
case "MISSING_REQ_TYPE":
@@ -563,6 +592,14 @@ private static AuthErrorReason GetFailureReason(string responseData)
563592
failureReason = AuthErrorReason.AlreadyLinked;
564593
break;
565594
}
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+
}
566603
}
567604
}
568605
catch (JsonReaderException)

0 commit comments

Comments
 (0)