【问题标题】:Using Saml with Azure AD using Blazer Web assembly使用 Blazor Webassembly 将 Saml 与 Azure AD 结合使用
【发布时间】:2021-10-22 10:44:40
【问题描述】:

我正在尝试使用 main() 中的 .NET core Blazer webAssembly 客户端 UI,并使用 SAML 和以下代码对 Azure AD 进行身份验证,但出现错误。无法解决下面的一个问题。任何线索表示赞赏

尝试让您登录时出错:“无法读取未定义的属性 'redirectUri'”

OIDC 工作正常。

下面是我从 Program.cs 中的 Main 调用的代码

        var builder = WebAssemblyHostBuilder.CreateDefault(args);
        builder.RootComponents.Add<App>("app");

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

        builder.Services.AddHttpClient("BlazorWASMAuthApp.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
            .AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();

        builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>()
            .CreateClient("BlazorWASMAuthApp.ServerAPI"));

builder.Services.AddApiAuthorization(); builder.Services.AddAuthenticationCore(); builder.Services.AddAuthorizationCore();

    builder.Services.AddAuthentication().AddSaml2(options =>
    {
        // builder.Configuration.Bind("AzureAd", options.SPOptions.AuthenticateRequestSigningBehavior);
        //APP Registration keys Will be moved to Json in subsequent story
        options.SPOptions.EntityId = new EntityId("https://localhost:5001/saml2");

        //options.SPOptions..Add("https://localhost:5001/saml2/API.Access");

        options.IdentityProviders.Add(
            new IdentityProvider(
              new EntityId("https://sts.windows.net/{Clientid}/"), options.SPOptions)

            {

                //SingleSignOnServiceUrl = signinURI,
                MetadataLocation = ...federationdataxml?clientid={clientid}"


            });

        ;
    })

      .AddCookie();

【问题讨论】:

    标签: azure-active-directory saml-2.0 blazor-webassembly


    【解决方案1】:

    根据 ms 文档,大多数 common errors 是由不正确的配置引起的

    根据场景的要求,遗漏或不正确 授权、实例、租户 ID、租户域、客户端 ID 或重定向 URI 阻止应用对客户端进行身份验证。

    在与重定向中配置的端口不同的端口上运行应用程序 身份提供者的应用注册 URI。

    请检查原因是否在您提供的代码中配置中缺少返回url参数

    options.SPOptions.ReturnUrl = new Uri("https://localhost:5001/authentication/azurecallback"); 之后

    options.SPOptions.EntityId = new EntityId("https://localhost:5001/saml2");
    

    其他检查门户端配置。

    在注册 API 时,重定向 uri 设置为 web 并且其字段为空,并且 api 从 Expose api 中公开。 但是在注册client app时,必须设置redirect uri,希望你已经设置好了。 客户端应用程序>转到活动目录b2c>提供名称>选择支持的帐户>重定向uri>选择SPA-give重定向你如https://localhost:5001/authentication/login-callback

    (uri 格式:https://localhost:{PORT}/authentication/login-callback.)

    此“身份验证/登录回调”也必须存在于您的代码配置中。

    来自reference

    注意:在 Kestrel 上运行的应用程序的默认端口是 5001。如果 应用程序在不同的 Kestrel 端口上运行,请使用应用程序的端口。对于 IIS Express,应用程序随机生成的端口可以在 调试面板中的服务器应用程序属性。由于该应用程序不 此时存在且 IIS Express 端口未知,返回 创建应用程序并更新重定向 URI 后的此步骤。一种 备注出现在创建应用部分以提醒 IIS Express 用户更新重定向 URI

    所以检查正在运行的端口,如果没有完成则更新重定向 uri。

    参考资料:

    1. Reference 1
    2. Reference 2
    3. Cors

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 2021-09-20
      • 2022-08-16
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多