H5W3
当前位置:H5W3 > 问答 > 正文

.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”
}.NetCore3.1配置IdentityServer4认证服务,一直不能获取Token,请高手指点迷津??

回答

问题补充:

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”
}
}

未经允许不得转载:H5W3 » .NetCore3.1配置IdentityServer4认证服务,一直不能获取Token,请高手指点迷津??

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址