【问题标题】:Protocol to implement Azure AD实现 Azure AD 的协议
【发布时间】:2023-03-14 08:58:02
【问题描述】:

我有一个旧的 ASP.NET Web 窗体应用程序。它目前使用带有 Cookie 身份验证和 WSFederation 协议的本地 ADFS。

我们希望将其移至 Azure AD。我想知道是否需要更改 WSFederation 协议,或者它也适用于 Azure AD。另外,是否需要更改Cookie Authentication?

Startup.CS 代码如下:

app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        //interactive logon process
        AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
        //name of the authentication type
        AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
        //TODO: Enable this to always send and receive cookies in SSL when in production
        CookieSecure = CookieSecureOption.Always,
        //enable sliding expiration
        SlidingExpiration = true,
        //Cookie expires in 4 hours
        ExpireTimeSpan = TimeSpan.FromTicks(DateTime.Now.AddHours(4).Ticks)

    });

    app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
    {
        MetadataAddress = adfsMetadata,
        Wtrealm = realm
    });
  • 已编辑 *

代码修改如下:

   app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        //interactive logon process
        AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
        //name of the authentication type
        AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
        //Login path should be below
        // LoginPath = new PathString("login"),
        //TODO: Enable this to always send and receive cookies in SSL when in production
        CookieSecure = CookieSecureOption.Always,
        //enable sliding expiration
        SlidingExpiration = true,
        //Cookie expires in 4 hours
        ExpireTimeSpan = TimeSpan.FromTicks(DateTime.Now.AddHours(4).Ticks)

    });
    Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;

    app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
    {
        MetadataAddress = AzureMetaData,
       Tenant = Tenant,
       Realm = Realm
                    

    });

现在抛出错误:

System.ArgumentNullException: '值不能为空。参数名称: allowedAudience'

【问题讨论】:

  • 您想知道它是否有效吗?您是否尝试过运行它并查看是否遇到错误?正确测试您的代码是无可替代的。
  • Azure AD 支持 WS-Fed。
  • @mason 代码正在运行。我对代码没有任何问题。我只是想知道相同的代码是否也适用于 Azure AD?
  • 您想知道它是否适用于 Azure AD?您是否尝试过运行它并查看是否遇到错误?正确测试您的代码是无可替代的。
  • @mason 我执行了上面发布的更新代码。它抛出错误。我已经提到了。

标签: asp.net azure webforms azure-active-directory adfs


【解决方案1】:

是的,Azure AD 支持 WS-Fed。参考:Integrating a web app with Azure AD using WS-Federation

对于 allowedAudiences,此字段的值必须与发送到您的服务的令牌的“受众”字段中的值相匹配。您可以转到您的服务的 Azure AD 应用注册,并在“identifierUris”字段中查看清单。此处的值应与您在 Allowed Token Audiences 列表中输入的值匹配。

您也可以转到https://resources.azure.com/ > 深入了解应用服务资源 > 配置 > authsettings 并更正 allowedAudiences 值:

"allowedAudiences":[
"https://mysite.azurewebsites.net"
  ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-08
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    相关资源
    最近更新 更多