.NetCore3.1配置IdentityServer4认证服务,一直不能获取Token,请高手指点迷津??
请求工具:postman
posturl:http://localhost:5000/connect/token
参数:grant_type:client_credentials
client_id:1001
client_secret:jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=
结果:{
"error": "invalid_client"
}
回答
问题补充:public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddIdentityServer()
//设置临时签名凭据
.AddDeveloperSigningCredential()
.AddInMemoryIdentityResources(Config.GetIdentityResourceResources())
//从Config类里面读取刚刚定义的Api资源
.AddInMemoryApiResources(Config.GetApiResources())
//从Config类里面读取刚刚定义的Client集合
.AddInMemoryClients(Config.GetClients());
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
//app.UseAuthorization();
app.UseIdentityServer();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
请求返回结果
IdentityServer4.Validation.TokenRequestValidator[0]
Client cannot request OpenID scopes in client credentials flow{ clientId = client1 }, details: {
"ClientId": "client1",
"GrantType": "client_credentials",
"Scopes": "api1",
"AuthorizationCode": "",
"RefreshToken": "",
"Raw": {
"grant_type": "client_credentials",
"client_id": "client1",
"client_secret": "REDACTED",
"scope": "api1"
}
}
以上是 .NetCore3.1配置IdentityServer4认证服务,一直不能获取Token,请高手指点迷津?? 的全部内容, 来源链接: utcz.com/a/66638.html