question

Javad-0679 avatar image
0 Votes"
Javad-0679 asked MarkAGregory-5624 commented

Azure AD authentication combined with individual user accounts authentication for WebAssembly Asp.net .NET 5 hosted

I am creating an app where some users can create an individual account and sign in with that. Also, I need users can sign in if they have Azure AD. I used Identity Server 4 for the individual accounts and it works correctly.

for Azure Ad, I found some answers on Stackoverflow and based on it I implemented my code as follows:

             services.AddDbContext<ApplicationDbContext>(options =>
                 options.UseSqlServer(
                     Configuration.GetConnectionString("DefaultConnection")));
    
             services.AddDatabaseDeveloperPageExceptionFilter();
    
             services.AddDefaultIdentity<ApplicationUser>(options => 
             options.SignIn.RequireConfirmedAccount = true)
                             .AddRoles<ApplicationRole>()
                             .AddEntityFrameworkStores<ApplicationDbContext>();
    
             services.AddIdentityServer()
                             .AddApiAuthorization<ApplicationUser, ApplicationDbContext>()
                             .AddProfileService<IdentityProfileService>();
                
             services.AddAuthentication(sharedOptions =>
             {
                 sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                 sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
             }).AddOpenIdConnect("AAD", "Azure Active Directory", options =>
                             {
                                 options.ClientSecret = "<Secrete>";
                                 options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
                                 options.ClientId = "<ClientId>";
                                 options.Authority = "https://login.microsoftonline.com/<tenantId>/";
                                 options.CallbackPath = "/authentication/login-callback";
                                 options.SaveTokens = true;
                                 options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                                    
                             }).AddCookie()
             .AddIdentityServerJwt();

I also created the callback URI in Azure as a web platform.

when I test that in the Postman, it works correctly and it gets the token. However, in my app, it redirect that to https://localhost:5001/identity/account/externallogin?returnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id ... and it shows "Sorry, there's nothing at this address."

I think this is because I am using WebAssembly with ASP.Net .NET 5 hosted.

Could someone help me with this or show me a sample?

Also, for authorization part , I also need manage users and roles inside the database and if there is not the user there, create a user in that user table.

azure-ad-authenticationdotnet-aspnet-core-blazor
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The examples don;t provide details on how to do multi-tenancy AAD with Blazor webassembly hosted .net 5 Core

Are there any examples on how to do this?

0 Votes 0 ·

0 Answers