@@ -211,16 +211,18 @@ public async Task<FirebaseAuthLink> ChangeUserEmail(string idToken, string newEm
|
211 | 211 |
|
212 | 212 | return await this.ExecuteWithPostContentAsync(GoogleUpdateUserPassword, content).ConfigureAwait(false);
|
213 | 213 | }
|
214 |
| -
|
| 214 | + |
215 | 215 | /// <summary>
|
216 | 216 | /// Creates new user with given credentials.
|
217 | 217 | /// </summary>
|
218 | 218 | /// <param name="email"> The email. </param>
|
219 | 219 | /// <param name="password"> The password. </param>
|
220 | 220 | /// <param name="displayName"> Optional display name. </param>
|
221 | 221 | /// <param name="sendVerificationEmail"> Optional. Whether to send user a link to verfiy his email address. </param>
|
| 222 | +/// <param name="locale"> The language code of language that the email will be in. </param> |
222 | 223 | /// <returns> The <see cref="FirebaseAuth"/>. </returns>
|
223 |
| -public async Task<FirebaseAuthLink> CreateUserWithEmailAndPasswordAsync(string email, string password, string displayName = "", bool sendVerificationEmail = false) |
| 224 | +public async Task<FirebaseAuthLink> CreateUserWithEmailAndPasswordAsync(string email, string password, string displayName = "", |
| 225 | +bool sendVerificationEmail = false, string locale = null) |
224 | 226 | {
|
225 | 227 | var content = $"{{\"email\":\"{email}\",\"password\":\"{password}\",\"returnSecureToken\":true}}";
|
226 | 228 |
|
@@ -239,7 +241,7 @@ public async Task<FirebaseAuthLink> CreateUserWithEmailAndPasswordAsync(string e
|
239 | 241 | if (sendVerificationEmail)
|
240 | 242 | {
|
241 | 243 | //send verification email
|
242 |
| -await this.SendEmailVerificationAsync(signup).ConfigureAwait(false); |
| 244 | +await this.SendEmailVerificationAsync(signup, locale).ConfigureAwait(false); |
243 | 245 | }
|
244 | 246 |
|
245 | 247 | return signup;
|
@@ -315,14 +317,21 @@ public async Task DeleteUserAsync(string firebaseToken)
|
315 | 317 | /// Sends user an email with a link to reset his password.
|
316 | 318 | /// </summary>
|
317 | 319 | /// <param name="email"> The email. </param>
|
318 |
| -public async Task SendPasswordResetEmailAsync(string email) |
| 320 | +/// <param name="locale"> The language code of language that the email will be in. </param> |
| 321 | +public async Task SendPasswordResetEmailAsync(string email, string locale = null) |
319 | 322 | {
|
320 | 323 | var content = $"{{\"requestType\":\"PASSWORD_RESET\",\"email\":\"{email}\"}}";
|
321 | 324 | var responseData = "N/A";
|
322 | 325 |
|
323 | 326 | try
|
324 | 327 | {
|
325 |
| -var response = await this.client.PostAsync(new Uri(string.Format(GoogleGetConfirmationCodeUrl, this.authConfig.ApiKey)), new StringContent(content, Encoding.UTF8, "application/json")).ConfigureAwait(false); |
| 328 | +var httpContent = new StringContent(content, Encoding.UTF8, "application/json"); |
| 329 | +if (locale != null) |
| 330 | +{ |
| 331 | +httpContent = AddFirebaseLocaleHeader(httpContent, locale); |
| 332 | +} |
| 333 | + |
| 334 | +var response = await this.client.PostAsync(new Uri(string.Format(GoogleGetConfirmationCodeUrl, this.authConfig.ApiKey)), httpContent).ConfigureAwait(false); |
326 | 335 | responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
327 | 336 |
|
328 | 337 | response.EnsureSuccessStatusCode();
|
@@ -338,11 +347,18 @@ public async Task SendPasswordResetEmailAsync(string email)
|
338 | 347 | /// Sends user an email with a link to verify his email address.
|
339 | 348 | /// </summary>
|
340 | 349 | /// <param name="firebaseToken"> The FirebaseToken (idToken) of an authenticated user. </param>
|
341 |
| -public async Task SendEmailVerificationAsync(string firebaseToken) |
| 350 | +/// <param name="locale"> The language code of language that the email will be in. </param> |
| 351 | +public async Task SendEmailVerificationAsync(string firebaseToken, string locale = null) |
342 | 352 | {
|
343 | 353 | var content = $"{{\"requestType\":\"VERIFY_EMAIL\",\"idToken\":\"{firebaseToken}\"}}";
|
344 | 354 |
|
345 |
| -var response = await this.client.PostAsync(new Uri(string.Format(GoogleGetConfirmationCodeUrl, this.authConfig.ApiKey)), new StringContent(content, Encoding.UTF8, "application/json")).ConfigureAwait(false); |
| 355 | +var httpContent = new StringContent(content, Encoding.UTF8, "application/json"); |
| 356 | +if (locale != null) |
| 357 | +{ |
| 358 | +httpContent = AddFirebaseLocaleHeader(httpContent, locale); |
| 359 | +} |
| 360 | + |
| 361 | +var response = await this.client.PostAsync(new Uri(string.Format(GoogleGetConfirmationCodeUrl, this.authConfig.ApiKey)), httpContent).ConfigureAwait(false); |
346 | 362 |
|
347 | 363 | response.EnsureSuccessStatusCode();
|
348 | 364 | }
|
@@ -351,9 +367,10 @@ public async Task SendEmailVerificationAsync(string firebaseToken)
|
351 | 367 | /// Sends user an email with a link to verify his email address.
|
352 | 368 | /// </summary>
|
353 | 369 | /// <param name="auth"> The authenticated user to verify email address. </param>
|
354 |
| -public async Task SendEmailVerificationAsync(FirebaseAuth auth) |
| 370 | +/// <param name="locale"> The language code of language that the email will be in. </param> |
| 371 | +public async Task SendEmailVerificationAsync(FirebaseAuth auth, string locale = null) |
355 | 372 | {
|
356 |
| -await this.SendEmailVerificationAsync(auth.FirebaseToken).ConfigureAwait(false); |
| 373 | +await this.SendEmailVerificationAsync(auth.FirebaseToken, locale).ConfigureAwait(false); |
357 | 374 | }
|
358 | 375 |
|
359 | 376 | /// <summary>
|
@@ -506,6 +523,21 @@ public void Dispose()
|
506 | 523 | this.client.Dispose();
|
507 | 524 | }
|
508 | 525 |
|
| 526 | +/// <summary> |
| 527 | +/// Adds firebase locale header used to send email in chosen language. |
| 528 | +/// If locale is incorrect default language will be chosen. |
| 529 | +/// </summary> |
| 530 | +/// <typeparam name="T"> Class deriving from HttpContent </typeparam> |
| 531 | +/// <param name="content"> Http content to add locale header to. </param> |
| 532 | +/// <param name="locale"> Locale string. </param> |
| 533 | +/// <returns> Passed http content with added header. </returns> |
| 534 | +private static T AddFirebaseLocaleHeader<T>(T content, string locale) where T : HttpContent |
| 535 | +{ |
| 536 | +content.Headers.Add("X-Firebase-Locale", locale); |
| 537 | + |
| 538 | +return content; |
| 539 | +} |
| 540 | + |
509 | 541 | private async Task<FirebaseAuthLink> ExecuteWithPostContentAsync(string googleUrl, string postContent)
|
510 | 542 | {
|
511 | 543 | string responseData = "N/A";
|
|
0 commit comments