IdentityServer4.Validation.AuthorizationRequestValidator[0]“;重定向“uri丢失或太长”;

IdentityServer4.Validation.AuthorizationRequestValidator[0]“;重定向“uri丢失或太长”;,identityserver4,Identityserver4,我正在使用IdentityServer4和asp.netcore 2.2设置安全服务器。我想使用Azure AD进行身份验证,并使用Asp.Net IdentityCore保留我的用户数据。我已经使用AddMicrosoftAccount设置了外部身份验证。身份验证工作正常,但我总是收到“IdentityServer4.Validation.AuthorizationRequestValidator[0]重定向\u uri缺失或太长”。我已经调试了代码,并注意到返回url在querystring

我正在使用IdentityServer4和asp.netcore 2.2设置安全服务器。我想使用Azure AD进行身份验证,并使用Asp.Net IdentityCore保留我的用户数据。我已经使用AddMicrosoftAccount设置了外部身份验证。身份验证工作正常,但我总是收到“IdentityServer4.Validation.AuthorizationRequestValidator[0]重定向\u uri缺失或太长”。我已经调试了代码,并注意到返回url在querystring中被正确地传递到Login.cshtml.cs。但是,OnGetAsync方法的returnUrl参数没有返回url。它看起来像是在什么地方被剥掉的。请帮忙

我正在使用IdentityServer 4,SQL Server用于配置和操作数据,SQL Server用于使用Asp.NetCoreIdentity的用户数据。我已经创建了一个mvc客户端并将其注册到服务器。我已经向客户端应用程序的主控制器添加了authorize属性,以触发身份验证

//my server client registration code

var webClient = new IdentityServer4.EntityFramework.Entities.Client
{
    ClientId = "mvc",
    ClientName = "MVC Client",
    Description = "Test MVC Client",
    RequireConsent = false,
    AlwaysIncludeUserClaimsInIdToken = true,
    AllowedScopes = new List<ClientScope>
    {
        new ClientScope
        {                       
            Scope = IdentityServerConstants.StandardScopes.OpenId 
        },
        new ClientScope
        {
            Scope = IdentityServerConstants.StandardScopes.Profile
        }
    }
};

//set the grant type
webClient.AllowedGrantTypes = new List<ClientGrantType>
{
    new ClientGrantType
    {
        GrantType = GrantType.Implicit,
        Client = webClient
    }
};

// where to redirect to after login
webClient.RedirectUris = new List<ClientRedirectUri>
{
    new ClientRedirectUri
    {
        RedirectUri = "http://localhost:5000/signin-oidc",
        Client = webClient
    }
};

// where to redirect to after logout
webClient.PostLogoutRedirectUris = new List<ClientPostLogoutRedirectUri>               
{
    new ClientPostLogoutRedirectUri
    {
      PostLogoutRedirectUri="http://localhost:5000/signout-callback-oidc",                       
      Client = webClient
    }
};


//Client configuration
services.AddAuthentication(options => 
{
    options.DefaultScheme = "Cookies";
    options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
    options.Authority = "http://localhost:5010";
    options.RequireHttpsMetadata = false;
    options.ClientId = "mvc";
    options.ClientSecret = "client secret".ToSha256();
    options.SaveTokens = true;
    options.CallbackPath = "/signin-oidc";                
});  

i have added app.UseAuthentication() to configure method
//我的服务器客户端注册码
var webClient=新标识服务器4.EntityFramework.Entities.Client
{
ClientId=“mvc”,
ClientName=“MVC客户端”,
Description=“测试MVC客户端”,
RequireSent=false,
AlwaysIncludeUserClaimsInIdToken=真,
AllowedScopes=新列表
{
新客户端示波器
{                       
Scope=IdentityServerConstants.StandardScopes.OpenId
},
新客户端示波器
{
Scope=IdentityServerConstants.StandardScopes.Profile
}
}
};
//设置授权类型
webClient.AllowedGrantTypes=新列表
{
新ClientGrantType
{
GrantType=GrantType.Implicit,
客户端=网络客户端
}
};
//登录后重定向到哪里
webClient.RedirectUris=新列表
{
新ClientRedirectUri
{
重定向URI=”http://localhost:5000/signin-oidc“,
客户端=网络客户端
}
};
//注销后重定向到何处
webClient.PostLogoutRedirectUris=新列表
{
新客户端PostLogoutRedirectUri
{
PostLogoutRedirectUri=”http://localhost:5000/signout-回调oidc“,
客户端=网络客户端
}
};
//客户端配置
services.AddAuthentication(选项=>
{
options.DefaultScheme=“Cookies”;
options.DefaultChallengeScheme=“oidc”;
})
.AddCookie(“Cookies”)
.AddOpenIdConnect(“oidc”,选项=>
{
选项。权限=”http://localhost:5010";
options.RequireHttpsMetadata=false;
options.ClientId=“mvc”;
options.ClientSecret=“client secret”.ToSha256();
options.SaveTokens=true;
options.CallbackPath=“/signin oidc”;
});  
我添加了app.UseAuthentication()来配置方法
我希望安全服务器在成功身份验证后重定向回我的客户端主控制器方法。相反,我得到了上面的错误。
我缺少什么

您尚未在客户端配置中配置任何重定向URI。您需要添加至少一个重定向uri

RedirectUris = {"http://<your redirect uri>"}
RedirectUris={“http://”}
例如:

var webClient = new IdentityServer4.EntityFramework.Entities.Client
{
    ClientId = "mvc",
    ClientName = "MVC Client",
    Description = "Test MVC Client",
    RequireConsent = false,
    AlwaysIncludeUserClaimsInIdToken = true,
    RedirectUris = {"http://<your redirect uri>"}
    AllowedScopes = new List<ClientScope>
    {
        new ClientScope
        {                       
            Scope = IdentityServerConstants.StandardScopes.OpenId 
        },
        new ClientScope
        {
            Scope = IdentityServerConstants.StandardScopes.Profile
        }
    }
};
var webClient=new IdentityServer4.EntityFramework.Entities.Client
{
ClientId=“mvc”,
ClientName=“MVC客户端”,
Description=“测试MVC客户端”,
RequireSent=false,
AlwaysIncludeUserClaimsInIdToken=真,
重定向URI={“http://”}
AllowedScopes=新列表
{
新客户端示波器
{                       
Scope=IdentityServerConstants.StandardScopes.OpenId
},
新客户端示波器
{
Scope=IdentityServerConstants.StandardScopes.Profile
}
}
};

您尚未在客户端配置中配置任何重定向URI。您需要添加至少一个重定向uri

RedirectUris = {"http://<your redirect uri>"}
RedirectUris={“http://”}
例如:

var webClient = new IdentityServer4.EntityFramework.Entities.Client
{
    ClientId = "mvc",
    ClientName = "MVC Client",
    Description = "Test MVC Client",
    RequireConsent = false,
    AlwaysIncludeUserClaimsInIdToken = true,
    RedirectUris = {"http://<your redirect uri>"}
    AllowedScopes = new List<ClientScope>
    {
        new ClientScope
        {                       
            Scope = IdentityServerConstants.StandardScopes.OpenId 
        },
        new ClientScope
        {
            Scope = IdentityServerConstants.StandardScopes.Profile
        }
    }
};
var webClient=new IdentityServer4.EntityFramework.Entities.Client
{
ClientId=“mvc”,
ClientName=“MVC客户端”,
Description=“测试MVC客户端”,
RequireSent=false,
AlwaysIncludeUserClaimsInIdToken=真,
重定向URI={“http://”}
AllowedScopes=新列表
{
新客户端示波器
{                       
Scope=IdentityServerConstants.StandardScopes.OpenId
},
新客户端示波器
{
Scope=IdentityServerConstants.StandardScopes.Profile
}
}
};

我确实配置了重定向URI。如果您签入代码,则有以下部分//在登录webClient.RedirectUris=new List{new ClientRedirectUri{RedirectUri=”“,Client=webClient}后重定向到何处;您可以添加身份验证请求吗?我已经配置了重定向URI。如果您签入代码,则有以下部分//在登录webClient.RedirectUris=new List{new ClientRedirectUri{RedirectUri=”“,Client=webClient}后重定向到何处;您可以添加您的身份验证请求吗?