Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

msal - Blazor Server website with Azure Identification

I'm spinning around and around trying to find a comprehensive description on how to upgrade a Blazor server website without authentication to use the latest MSAL authentication and not ADAL which is going to be dropped in 2022. The issue I had are that there are bit and pieces here and there and finally I got it to compile and start up, but when the website gives me a choice of the login since I have multiple ad connections, it repeats that choice after I select one. It never gets to complete the handshake in some form. Here is what I have:

Startup.cs in ConfigurationService:


    services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "AzureAd");

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

Appsettings is:

"AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "zzzzzzzzz.onmicrosoft.com",
    "TenantId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "ClientId": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
    "CallbackPath": "/signin-oidc"
},

LaunchSettings:

"ITraxBlazer": {
  "commandName": "Project",
  "launchBrowser": true,
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },

"applicationUrl": "https://localhost:5001;http://localhost:5000" }

Packages:

      <ItemGroup>
        <PackageReference Include="Blazored.Toast" Version="3.1.2" />
        <PackageReference Include="Microsoft.Identity.Web" Version="1.5.1" />
        <PackageReference Include="Microsoft.Identity.Web.UI" Version="1.5.1" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.1" />
        <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
        <PackageReference Include="Telerik.Documents.Spreadsheet" Version="2021.1.118" />
        <PackageReference Include="Telerik.UI.for.Blazor" Version="2.21.0" />
      </ItemGroup>

Thanks a bunch for any help!

question from:https://stackoverflow.com/questions/65908292/blazor-server-website-with-azure-identification

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The issue was that I didn't have the two indented lines here in StartUp.cs

app.UseRounting();

            app.UseAuthentication();
            app.UseAuthorization();

app.UseEndpoints();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...