|
13 | 13 | public class FirebaseAuthProvider : IDisposable
|
14 | 14 | {
|
15 | 15 | private const string GoogleIdentityUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key={0}";
|
16 |
| - private const string GoogleAnonymousUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key={0}"; |
| 16 | + private const string GoogleSignUpUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key={0}"; |
| 17 | + private const string GooglePasswordUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key={0}"; |
| 18 | + private const string GooglePasswordResetUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getOobConfirmationCode?key={0}"; |
17 | 19 |
|
18 | 20 | private readonly FirebaseConfig authConfig;
|
19 | 21 | private readonly HttpClient client;
|
@@ -50,7 +52,42 @@ public async Task<FirebaseAuth> SignInAnonymously()
|
50 | 52 | {
|
51 | 53 | var content = $"{{\"returnSecureToken\":true}}";
|
52 | 54 |
|
53 |
| - return await this.SignInWithPostContent(GoogleAnonymousUrl, content); |
| 55 | + return await this.SignInWithPostContent(GoogleSignUpUrl, content); |
| 56 | + } |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Using the provided email and passowrd, get the firebase auth with token and basic user credentials. |
| 60 | + /// </summary> |
| 61 | + /// <param name="email"> The email. </param> |
| 62 | + /// <param name="password"> The password. </param> |
| 63 | + /// <returns> The <see cref="FirebaseAuth"/>. </returns> |
| 64 | + public async Task<FirebaseAuth> SignInWithEmailAndPassword(string email, string password) |
| 65 | + { |
| 66 | + var content = $"{{\"email\":\"{email}\",\"password\":\"{password}\",\"returnSecureToken\":true}}"; |
| 67 | + |
| 68 | + return await this.SignInWithPostContent(GooglePasswordUrl, content); |
| 69 | + } |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Creates new user with given credentials. |
| 73 | + /// </summary> |
| 74 | + /// <param name="email"> The email. </param> |
| 75 | + /// <param name="password"> The password. </param> |
| 76 | + /// <returns> The <see cref="FirebaseAuth"/>. </returns> |
| 77 | + public async Task<FirebaseAuth> CreateUserWithEmailAndPassword(string email, string password) |
| 78 | + { |
| 79 | + var content = $"{{\"email\":\"{email}\",\"password\":\"{password}\",\"returnSecureToken\":true}}"; |
| 80 | + |
| 81 | + return await this.SignInWithPostContent(GoogleSignUpUrl, content); |
| 82 | + } |
| 83 | + |
| 84 | + public async Task SendPasswordResetEmail(string email) |
| 85 | + { |
| 86 | + var content = $"{{\"requestType\":\"PASSWORD_RESET\",\"email\":\"{email}\"}}"; |
| 87 | + |
| 88 | + var response = await this.client.PostAsync(new Uri(string.Format(GooglePasswordResetUrl, this.authConfig.ApiKey)), new StringContent(content, Encoding.UTF8, "application/json")); |
| 89 | + |
| 90 | + response.EnsureSuccessStatusCode(); |
54 | 91 | }
|
55 | 92 |
|
56 | 93 | /// <summary>
|
|
0 commit comments