Azure Active Directory B2C,404错误,URL中的意外问号

时间:2017-05-27 20:18:42

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

我正在从this官方教程实施Azure Active Directory B2C。 当我运行我的代码时,它说 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable. 问题在于URL,它包含问号(screenshot)。如果我手动更换"?"代替问号,我应该使用&符号(&)。用"&"它工作正常。 这是我的启动课

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/" />

1 个答案:

答案 0 :(得分:2)

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

您最有可能使用其中一个旧版本。我认为具体的问题库是Microsoft.IdentityModel.Protocol.Extensions

你应该尝试更新这个库,或者只是将样本作为起点,因为那个库已经有了正确的(更新的)库。

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

  

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