Skip to content

Commit fc2d811

Browse files
authored
Add multi-tenancy to signin with email and password (#113)
Co-authored-by: Mohamed Haidar <[email protected]>
1 parent f75ec11 commit fc2d811

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/Firebase.Auth.Tests/IntegrationTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class IntegrationTests
2121
private const string FirebaseEmail = "<TEST USER EMAIL>";
2222
private const string FirebasePassword = "<TEST USER PASSWORD>";
2323

24+
private const string FirebaseTenant = "<TEST USER TENANT ID>";
25+
2426
[TestMethod]
2527
public void FacebookTest()
2628
{
@@ -54,6 +56,17 @@ public void EmailTest()
5456
auth.FirebaseToken.Should().NotBeNullOrWhiteSpace();
5557
}
5658

59+
[TestMethod]
60+
public void EmailWithTenantTest()
61+
{
62+
var authProvider = new FirebaseAuthProvider(new FirebaseConfig(ApiKey));
63+
64+
var auth = authProvider.SignInWithEmailAndPasswordAsync(FirebaseEmail, FirebasePassword, FirebaseTenant).Result;
65+
66+
auth.User.Email.Should().BeEquivalentTo(FirebaseEmail);
67+
auth.FirebaseToken.Should().NotBeNullOrWhiteSpace();
68+
}
69+
5770
[TestMethod]
5871
public void Unknown_email_address_should_be_reflected_by_failure_reason()
5972
{
@@ -178,4 +191,4 @@ public void RefreshAccessToken()
178191
freshAuth.FirebaseToken.Should().NotBe(originalToken);
179192
}
180193
}
181-
}
194+
}

src/Firebase.Auth/FirebaseAuthProvider.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,21 @@ public async Task<FirebaseAuthLink> SignInAnonymouslyAsync()
150150
/// </summary>
151151
/// <param name="email"> The email. </param>
152152
/// <param name="password"> The password. </param>
153+
/// <param name="tenantId"></param>
153154
/// <returns> The <see cref="FirebaseAuth"/>. </returns>
154-
public async Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password)
155+
public async Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password,
156+
string tenantId = null)
155157
{
156-
var content = $"{{\"email\":\"{email}\",\"password\":\"{password}\",\"returnSecureToken\":true}}";
158+
StringBuilder sb = new StringBuilder($"{{\"email\":\"{email}\",\"password\":\"{password}\",");
159+
160+
if (tenantId != null)
161+
{
162+
sb.Append($"\"tenantId\":\"{tenantId}\"");
163+
}
164+
165+
sb.Append("\"returnSecureToken\":true}}");
157166

158-
return await this.ExecuteWithPostContentAsync(GooglePasswordUrl, content).ConfigureAwait(false);
167+
return await ExecuteWithPostContentAsync(GooglePasswordUrl, sb.ToString()).ConfigureAwait(false);
159168
}
160169

161170
/// <summary>

src/Firebase.Auth/IFirebaseAuthProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public interface IFirebaseAuthProvider
3535
/// </summary>
3636
/// <param name="email"> The email. </param>
3737
/// <param name="password"> The password. </param>
38+
/// <param name="tenantId"></param>
3839
/// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
39-
Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password);
40+
Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password, string tenantId = null);
4041

4142
/// <summary>
4243
/// Using the provided access token from third party auth provider (google, facebook...), get the firebase auth with token and basic user credentials.

0 commit comments

Comments
 (0)