/// <summary> /// Send password reset email to the existing account provided with the <paramref name="email"/>. /// </summary> /// <param name="email"> /// The email of the user to send the password reset. /// </param> /// <returns> /// The <see cref="CallResult"/> of the specified task. /// </returns> public async Task <CallResult> SendPasswordResetEmail(string email) { try { var content = $"{{\"requestType\":\"PASSWORD_RESET\",\"email\":\"{email}\"}}"; var responseData = "N/A"; try { var response = await GetClient().PostAsync( new Uri(string.Format(GoogleGetConfirmationCodeUrl, App.Config.ApiKey)), new StringContent(content, Encoding.UTF8, "Application/json"), new CancellationTokenSource(App.Config.AuthRequestTimeout).Token).ConfigureAwait(false); responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); response.EnsureSuccessStatusCode(); } catch (OperationCanceledException ex) { throw new FirebaseException(FirebaseExceptionReason.OperationCancelled, ex); } catch (Exception ex) { FirebaseExceptionReason errorReason = GetFailureReason(responseData); throw new FirebaseException(errorReason, ex); } return(CallResult.Success()); } catch (FirebaseException ex) { return(CallResult.Error(ex)); } }
internal async Task <FirebaseAuth> ExecuteWithPostContent(string googleUrl, string postContent) { string responseData = "N/A"; try { var response = await GetClient().PostAsync( new Uri(string.Format(googleUrl, App.Config.ApiKey)), new StringContent(postContent, Encoding.UTF8, "Application/json"), new CancellationTokenSource(App.Config.AuthRequestTimeout).Token).ConfigureAwait(false); responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); response.EnsureSuccessStatusCode(); var user = JsonConvert.DeserializeObject <User>(responseData); var auth = JsonConvert.DeserializeObject <FirebaseAuth>(responseData); auth.User = user; return(auth); } catch (OperationCanceledException ex) { throw new FirebaseException(FirebaseExceptionReason.OperationCancelled, ex); } catch (Exception ex) { Type s = ex.GetType(); FirebaseExceptionReason errorReason = GetFailureReason(responseData); throw new FirebaseException(errorReason, ex); } }
internal async Task <CallResult> RefreshUserInfo(FirebaseAuth auth) { try { var content = $"{{\"idToken\":\"{auth.FirebaseToken}\"}}"; var responseData = "N/A"; try { var response = await GetClient().PostAsync( new Uri(string.Format(GoogleGetUser, App.Config.ApiKey)), new StringContent(content, Encoding.UTF8, "Application/json"), new CancellationTokenSource(App.Config.AuthRequestTimeout).Token).ConfigureAwait(false); responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); response.EnsureSuccessStatusCode(); var resultJson = JObject.Parse(responseData); var user = JsonConvert.DeserializeObject <User>(resultJson["users"].First().ToString()); auth.User = user; session.UpdateAuth(auth); OnAuthRefreshed(); return(CallResult.Success(user)); } catch (OperationCanceledException ex) { throw new FirebaseException(FirebaseExceptionReason.OperationCancelled, ex); } catch (Exception ex) { FirebaseExceptionReason errorReason = GetFailureReason(responseData); throw new FirebaseException(errorReason, ex); } } catch (FirebaseException ex) { return(CallResult.Error(ex)); } }
internal FirebaseException(FirebaseExceptionReason reason, Exception innerException) : base(innerException.Message, innerException) { Reason = reason; }
internal FirebaseException(FirebaseExceptionReason reason) : base() { Reason = reason; }