小编Ama*_*ues的帖子

使用多个身份提供商对 Blazor WebAssembly 进行身份验证

我正在学习 Blazor WebAssembly 并构建一个小项目,以在 Azure 中作为静态 Web 应用程序托管。

目标框架是net5.0。

当用户单击“登录”超链接或按钮时,新页面将显示一些身份提供商的名称(Microsoft、Google、SackOverflow 等)。然后用户将选择其中之一进行登录。

我只使用一个身份提供商(仅 Microsoft、仅 Google 等)来完成此操作。

如何在同一个应用程序中使用多个身份提供商?

有人可以帮助我吗?

Blazor WebAssembly 应用程序

目标框架:net5.0

在 Azure 中作为静态 Web 应用程序托管

程序.cs

using Blazored.LocalStorage;

using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace FileProcApp
{
    public class Program
    {
        public static async Task Main(string[] args) {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("#app");

            builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

            builder.Services.AddOidcAuthentication(options => {
                options.ProviderOptions.DefaultScopes.Clear();
                options.ProviderOptions.DefaultScopes.Add("openid");
                options.ProviderOptions.DefaultScopes.Add("offline_access");
                builder.Configuration.Bind("AzureAd", options.ProviderOptions);
            });
            
            builder.Services.AddOidcAuthentication(options …
Run Code Online (Sandbox Code Playgroud)

c# authentication blazor-webassembly

6
推荐指数
0
解决办法
491
查看次数

标签 统计

authentication ×1

blazor-webassembly ×1

c# ×1