C# ASP.NET核心MVC部署到azure Identity Server 4
当我尝试将MVC asp.net核心部署为客户端时,我在azure中部署了identity server。显示未筛选的客户端错误。我下面的配置有什么问题 启动客户端MVCC# ASP.NET核心MVC部署到azure Identity Server 4,c#,asp.net,asp.net-mvc,.net-core,identityserver4,C#,Asp.net,Asp.net Mvc,.net Core,Identityserver4,当我尝试将MVC asp.net核心部署为客户端时,我在azure中部署了identity server。显示未筛选的客户端错误。我下面的配置有什么问题 启动客户端MVC JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); services.AddAuthentication(options => { options.DefaultScheme = "Cookies
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options => {
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options => {
options.SignInScheme = "Cookies";
options.Authority = Configuration.GetValue<string>("server:identityurl");
options.RequireHttpsMetadata = false;
options.ClientId = Configuration.GetValue<string>("server:clientid");
options.ClientSecret = Configuration.GetValue<string>("server:clientsecret");
options.ResponseType = Configuration.GetValue<string>("server:responsetype");
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add(Configuration.GetValue<string>("server:scope1"));
options.Scope.Add(Configuration.GetValue<string>("server:scope2"));
});
身份服务器启动
public void ConfigureServices(IServiceCollection services)
{
var sqlConnectionString = Configuration.GetConnectionString("MySqlCon");
services.AddDbContext<PDJayaDB>(options =>
options.UseMySql(
sqlConnectionString,
b => b.MigrationsAssembly("PDJaya.Identity")
)
);
//my user repository
services.AddScoped<IUserRepository, UserRepository>();
services.AddSingleton<IConfiguration>(Configuration);
services.AddMvc();
// configure identity server with in-memory stores, keys, clients and resources
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetUsers())
.AddProfileService<ProfileService>();
//Inject the classes we just created
services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
services.AddTransient<IProfileService, ProfileService>();
}
使用混合流,而不是Ryan所说的隐式流。然后重新启动web应用程序。它应该会修复错误。Identity server日志会给出原因。查看日志或张贴日志以获得进一步帮助。您可以教我如何查看日志吗?我的identity server作为应用服务在azure上运行。@Richard如果您使用的是“代码id_令牌”响应类型,请尝试将客户端设置为使用混合流,而不是设置的隐式流。我更改为Hybridandclientcredential,并且,我的错误请求现在无效,有什么建议吗?
public void ConfigureServices(IServiceCollection services)
{
var sqlConnectionString = Configuration.GetConnectionString("MySqlCon");
services.AddDbContext<PDJayaDB>(options =>
options.UseMySql(
sqlConnectionString,
b => b.MigrationsAssembly("PDJaya.Identity")
)
);
//my user repository
services.AddScoped<IUserRepository, UserRepository>();
services.AddSingleton<IConfiguration>(Configuration);
services.AddMvc();
// configure identity server with in-memory stores, keys, clients and resources
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetUsers())
.AddProfileService<ProfileService>();
//Inject the classes we just created
services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
services.AddTransient<IProfileService, ProfileService>();
}
ClientId = "webapp2",
ClientName = "web with openid",
AllowedGrantTypes = GrantTypes.Implicit,
ClientSecrets =
{
new Secret("web123".Sha256())
},
RedirectUris = { "http://pdjayaauthapi.azurewebsites.net/signin-oidc" },
PostLogoutRedirectUris = { "http://pdjayaauthapi.azurewebsites.net/signout-callback-oidc" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"masterdataapi",
"transactionapi"
},
AllowOfflineAccess = true