New Blazor project with connection to local Identity Server 4

Viewed 707

When I create the new Blazor project there is an option to use authentication via Individual User Accounts, Connect to an existing user store in the cloud. I have local Identity Server 4 installed and configured. Could I use it for authentication? In such case, which parameters should I specify there for Sign-up or Sign-ii policy, Reset Password Policy, and Edit Profile Policy options?

enter image description here

1 Answers

No,that option is used to connect Azure AD B2C application,one of Microsoft's cloud identity service .

If you want to connect to local Identity Server 4 , you can firstly installl package IdentityServer4 , and then add authentication in blazor app , use OIDC middleware to connect to IDS4 :

services.AddAuthentication(options =>
{
    options.DefaultScheme = "Cookies";
    options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
    options.Authority = "http://localhost:5000";
    options.RequireHttpsMetadata = false;

    options.ClientId = "mvcBlazor";
    options.SaveTokens = true;
    options.Scope.Add("openid");
    options.Scope.Add("profile");
});

services.AddMvcCore(options =>
{
    var policy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .Build();
    options.Filters.Add(new AuthorizeFilter(policy));
});

and

app.UseAuthentication();

You can refer to below article for code sample and explanation :

https://nightbaker.github.io/blazor/identityserver4/serverapp/2019/08/29/blazor-serverapp-identity-server-4/

Related