Azure Active Directory B2C、404 错误、URL 中出现意外问号

标签 azure active-directory http-status-code-404 azure-ad-b2c

我正在从 this 实现 Azure Active Directory B2C官方教程。 当我运行我的代码时它说 404 - 未找到文件或目录。 您正在查找的资源可能已被删除、更名或暂时不可用。 问题在于 URL,它包含问号 ( screenshot )。如果我手动替换“?”,则应该用“&”代替问号。用“&”它工作得很好。 这是我的启动类(class)

public partial class Startup
    {
        // App config settings
        public static string ClientId = ConfigurationManager.AppSettings["ida:ClientId"];
        public static string ClientSecret = ConfigurationManager.AppSettings["ida:ClientSecret"];
        public static string AadInstance = ConfigurationManager.AppSettings["ida:AadInstance"];
        public static string Tenant = ConfigurationManager.AppSettings["ida:Tenant"];
        public static string RedirectUri = ConfigurationManager.AppSettings["ida:RedirectUri"];
        public static string ServiceUrl = ConfigurationManager.AppSettings["api:TaskServiceUrl"];

    // B2C policy identifiers
    public static string SignUpSignInPolicyId = ConfigurationManager.AppSettings["ida:SignUpSignInPolicyId"];
    public static string EditProfilePolicyId = ConfigurationManager.AppSettings["ida:EditProfilePolicyId"];
    public static string ResetPasswordPolicyId = ConfigurationManager.AppSettings["ida:ResetPasswordPolicyId"];

    public static string DefaultPolicy = SignUpSignInPolicyId;

    // API Scopes
    public static string ApiIdentifier = ConfigurationManager.AppSettings["api:ApiIdentifier"];
    public static string ReadTasksScope = ApiIdentifier + ConfigurationManager.AppSettings["api:ReadScope"];
    public static string WriteTasksScope = ApiIdentifier + ConfigurationManager.AppSettings["api:WriteScope"];
    public static string[] Scopes = new string[] { ReadTasksScope, WriteTasksScope };

    // OWIN auth middleware constants
    public const string ObjectIdElement = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";

    // Authorities
    public static string Authority = String.Format(AadInstance, Tenant, DefaultPolicy);

    // Initialize variables ...

    // Configure the OWIN middleware
    public void ConfigureAuth(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions());
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
            // Generate the metadata address using the tenant and policy information
            MetadataAddress = Authority,

            // These are standard OpenID Connect parameters, with values pulled from web.config
            ClientId = ClientId,
                RedirectUri = RedirectUri,
                PostLogoutRedirectUri = RedirectUri,

            // Specify the callbacks for each type of notifications
            Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    RedirectToIdentityProvider = OnRedirectToIdentityProvider,
                    AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                    AuthenticationFailed = OnAuthenticationFailed,
                },

            // Specify the claims to validate
            TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name"
                },

            // Specify the scope by appending all of the scopes requested into one string (seperated by a blank space)
            Scope = $"{OpenIdConnectScopes.OpenId} {ReadTasksScope} {WriteTasksScope}"
            }
        );
    }`  

这里是 webconfig

<add key="ida:Tenant" value="explicarte.onmicrosoft.com" />
<add key="ida:ClientId" value="a2d**********************" />
<add key="ida:ClientSecret" value="0f**************" />
<add key="ida:AadInstance" value="https://login.microsoftonline.com/{0}/v2.0/.well-known/openid-configuration?p={1}" />
<add key="ida:RedirectUri" value="https://explicarted.azurewebsites.net/" />
<add key="ida:SignUpSignInPolicyId" value="B2C_1_MySignupSigninPolicy" />
<add key="EditProfilePolicyId" value="B2C_1_myProfileEditingPolicy" />
<add key="ResetPasswordPolicyId" value="B2C_1_PasswordResetPolicy" />
<add key="api:ApiIdentifier" value="https://explicarted.azurewebsites.net/tasks/" />
<add key="api:ReadScope" value="read" />
<add key="api:WriteScope" value="write" />
<add key="api:TaskServiceUrl" value="https://explicarted.azurewebsites.net/" />

最佳答案

处理 .Net 库之一中预先存在的查询字符串参数时存在一个已知问题。

您很可能正在使用这些旧版本之一。我相信具体有问题的库是 Microsoft.IdentityModel.Protocol.Extensions .

您应该尝试更新此库或仅以示例作为起点,因为该库已经具有正确的(更新的)库。

PS:您应该使用以下权限:

https://login.microsoftonline.com/tfp/{0}/{1}/v2.0/.well-known/openid-configuration

关于Azure Active Directory B2C、404 错误、URL 中出现意外问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44221248/

相关文章:

sql-server - 创建 Azure SQL 数据库时如何获取最新的 SQL Server 版本

部署到 IIS 时的 Azure 移动服务密码

c# - C#Active Directory添加用户

c# - 以编程方式在 Active Directory 中创建通讯组

azure - APIM - 验证消费层的内容

Azure Redis 缓存与 Azure 上的 Redis 云服务

c# - 如何使用 AccountManagement 获取 OU 列表 (C#)

jquery - 当浏览器具有以前的网站历史记录时,Magento多商店索引链接会找到404页面

python - 使用 Python 套接字出现意外的 HTML 错误响应

python - 我尝试在Flask中使用Blueprints进行404错误处理,但似乎无法正常工作。这是我的代码: