Не удается подключиться к IdentityController в быстром запуске IdentityServer4 - PullRequest
1 голос
/ 07 января 2020

Я получаю сообщение «активно отказано» при выполнении этой строки кода в консольном клиенте. (Обратите внимание, что обнаружение работает и направлено на порт 60540).

  var c = new HttpClient();
  c.SetBearerToken(tr.AccessToken);
  var rsp = await c.GetAsync("http://localhost:5000/identity");

Ниже приведены мои параметры запуска. 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 и профиль службы, и результаты совпадают. Я начал этот проект как проект VS 2019 Worker Service для pnet core 3.1

1 Ответ

0 голосов
/ 10 января 2020

с тех пор, как вы сказали, что обнаружение работает на порту 60540, пытались ли вы получить доступ к http://localhost: 60540 / identity ?

...