I'm pretty new to ASP.NET Core 5 Identity, and I have several questions (that I will break in several posts here on StackOverflow) but please, while answering, consider that my knowledge about this topic is limited as I have little to no experience with this system.
I have an intranet application (Blazor server side, lets call it Application A) where its users can create guest users that will use an android app (through a different, public, WEB API application, lets call this Application B) to access their data. The users of Application B can NOT register by themselves, their accounts can ONLY be set up by the users of Application A.
I want to keep the users of the android app (Application B) on a different database (I don't want to mix the two since Application A holds sensitive data and is an intranet application while Application B is publicly accessible from the Internet).
Both applications (A and B) will use ASP.NET Identity to authenticate their respective users but each one has its own independent database (so each one has its own independent Identity tables), of course Application A can access the database of Application B but NOT the other way around (Application B can't see Application A's database).
In short: I want to create users from Application A in the database of Application B. How can I do that?
Is there any example that would help me accomplish something like this? As I said, I have very little experience with ASP.NET Identity so any example would be very helpful.
Thank you
P.S.: I hope I have been sufficiently clear, English is not my native language.
EDIT: I'm going to add some code to show what I have now.
This is how the Identity framework is currently set-up in my Startup.cs file. As you can see there is an ApplicationDbContext that points to the Blazor's database (Application A) and the Identity uses the same ApplicationDbContext to read and write to the database.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options =>
options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
How do I add a SECOND Identity Framework to point to a different DbContext to read and write from/to the database of Application B (the WEB-API used by my Android's app)?
Right now if I wanted to create a new user in Application A's database programmatically I would do this from my Blazor (Application A) page:
@using Microsoft.AspNetCore.Identity;
@inject UserManager<IdentityUser> userManager;
<button class="btn btn-danger" @onclick="AddUser">Add User</button>
@code {
private async Task AddUser()
{
var user = new IdentityUser() { Email = "john@test.com", UserName = "john@test.com" };
await userManager.CreateAsync(user);
await userManager.AddPasswordAsync(user, "TestPassword_123");
await userManager.ConfirmEmailAsync(user, await userManager.GenerateEmailConfirmationTokenAsync(user));
}
}
How would I do the same but inside Application B's database (but still from Application A)?