【问题标题】:Trying to implement Azure Active Directory B2C gives me a 404 error尝试实施 Azure Active Directory B2C 时出现 404 错误
【发布时间】:2017-02-08 01:47:13
【问题描述】:

我正在尝试在我正在开发的新页面中实施 Azure Active Directory B2C,但我在尝试从我的页面登录时收到此 404 - File or directory not found 错误。

我创建了租户,注册了我的应用程序,创建了我的政策,整个交易。我可以毫无问题地从 Azure 门户测试它们。但是,我按照official tutorial 上的指示在我的页面中实施策略无济于事,我收到提到的 404 错误,好像缺少某些东西一样。
我什至下载了那里发布的代码,它可以工作!

我尝试比较两个代码,但看不出有什么区别。但是,我将代码粘贴在这里,希望您能帮我解决这个问题。

WEB.CONFIG

<add key="ida:Tenant" value="PlataformaXXX.onmicrosoft.com" />
<add key="ida:ClientId" value="84d2a6e6-4cac-4c53-a5ff-XXXXXXXXXXXX" />
<add key="ida:AadInstance" value="https://login.microsoftonline.com/{0}/v2.0/.well-known/openid-configuration?p={1}" />
<add key="ida:RedirectUri" value="https://localhost:59744/" />
<add key="ida:SignUpPolicyId" value="B2C_1_Sign_Up" />
<add key="ida:SignInPolicyId" value="B2C_1_Sign_In" />
<add key="ida:UserProfilePolicyId" value="B2C_1_Edit" />

STARTUP.AUTH.CS

public partial class Startup
{
    // App config settings
    private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
    private static string aadInstance = ConfigurationManager.AppSettings["ida:AadInstance"];
    private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
    private static string redirectUri = ConfigurationManager.AppSettings["ida:RedirectUri"];

    // B2C policy identifiers
    public static string SignUpPolicyId = ConfigurationManager.AppSettings["ida:SignUpPolicyId"];
    public static string SignInPolicyId = ConfigurationManager.AppSettings["ida:SignInPolicyId"];
    public static string ProfilePolicyId = ConfigurationManager.AppSettings["ida:UserProfilePolicyId"];

    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        // Configure OpenID Connect middleware for each policy
        app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(SignUpPolicyId));
        app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(ProfilePolicyId));
        app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(SignInPolicyId));
    } ...

如果需要任何其他代码块,请告诉我。

真的,非常感谢任何帮助。

最好的问候,托尼奥。

【问题讨论】:

    标签: azure http-status-code-404 azure-ad-b2c


    【解决方案1】:

    看起来您的参数 ida:AadInstance 错误。应该是:

    https://{0}.b2clogin.com/{1}/v2.0/.well-known/openid-configuration?p={2}
    {0}: tenantid
    {1}: tenantid.onmicrosoft.com
    {2}: policy name
    

    如果您想保留 login.microsoftonline.com,则 url 必须是:

    https://login.microsoftonline.com/tfp/{0}/{1}/v2.0/
    {0}: tenantid.onmicrosoft.com
    {1}: policy name
    

    问候 康拉德

    【讨论】:

    • 谢谢。我被困在这小时。 Msft 文档说使用 login.microsoftonline.com/tfp,这是行不通的。当我尝试 {tenantid}.bc2login.com 版本时,它立即起作用。 :) 谢谢!
    【解决方案2】:

    如果您尝试使用 .auth/me,请确保您的商店令牌已在身份验证设置中启用。否则它会给你一个 404。:)

    【讨论】:

      【解决方案3】:

      我也遇到了同样的问题。您可以检查的一些内容是:

      • 确保您的 webconfig 和 Azure AD 中的策略名称 完全一样,包括正确的大写/小写

      • 确保 AadInstance 有一个尾部斜杠 (/)

      • 确保您拥有最新版本的 owin 和 microsoft.identitymodel.protocol.extensions 库(建议 从 NuGet 重新加载它们)

        • 最后一个问题是我最难找到的问题。如果 浏览器中生成的 URL 包含 2 个问号,然后 这是解决办法。

      【讨论】:

      • 抱歉这么晚才回复。扩展包丢失了,在我安装它并更新了 WebGrease 和 Antlr 包之后,一切都很顺利。谢谢!
      • 我必须更新 microsoft.identitymodel.protocol.extensions 并解决了我的问题。谢谢!
      • @scottshelton ,microsoft.identitymodel.protocol.extensions 在 .net framework 4.6.1 中不支持吗?
      猜你喜欢
      • 2017-10-28
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 2020-10-07
      • 2016-08-13
      相关资源
      最近更新 更多