当我在控制台客户端执行这行代码时,我收到一条“积极拒绝”的消息。(请注意,发现是有效的,并被定向到端口60540)。
var c = new HttpClient();
c.SetBearerToken(tr.AccessToken);
var rsp = await c.GetAsync("http://localhost:5000/identity");下面是我的launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60540",
"sslPort": 44386
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"commandLineArgs": "debug=true",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Service": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5000"
}
}
}以下是来自Startup.cs的相关代码
public void ConfigureServices (IServiceCollection services)
{
IIdentityServerBuilder isb;
services.AddControllers();
services.AddAuthentication("Bearer").AddJwtBearer("Bearer", options =>
{
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.Audience = "api1";
});
isb = services.AddIdentityServer();
isb.AddInMemoryIdentityResources(new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile()
}).
AddInMemoryApiResources(new List<ApiResource>()
{
new ApiResource("api1", "My Api")
}).
AddInMemoryClients(new List<Client>()
{
new Client
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes =
{
"api1"
}
}
});
// not recommended for production - you need to store your key material somewhere secure
isb.AddDeveloperSigningCredential();
} /* method Startup ConfigureServices */
public void Configure (IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseIdentityServer();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
} /* method Startup Configure */我尝试了IIS Express配置文件和服务配置文件,结果是相同的。我开始这个项目是作为aspnet core 3.1的VS 2019 Worker Service项目
发布于 2020-01-11 02:20:14
因为您说发现工作在端口60540上,所以您是否尝试过访问http://localhost:60540/identity?
https://stackoverflow.com/questions/59635402
复制相似问题