Cant add IdentityServer4 to ASP.NET Framework 4.7.2 API OWIN

旧街凉风 提交于 2020-01-14 03:04:08

问题


I'm trying to setup Identity Server 4 Auth server in ASP.NET Framework 4.7.2 WEB API, but I can't get it working. I'm not able to add appBuilder.UseIdentityServer() in the Startup class.

My understanding is that the IdentityServer4 is compiled as DotNet Standard 2.0 and the ASP.NET Framework 4.7.2 is compatible with DotNet Standard 2.0, so IDS4 should be able to be used inside 4.7.2 project. Correct me if I'm wrong please.

Is it possible to use IdentityServer4 like that? What am I doing wrong here?

This is my startup class:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        var builder = services.AddIdentityServerBuilder()
        .AddInMemoryIdentityResources(
            IdentityServerConfig.GetIdentityResources())
        .AddInMemoryApiResources(IdentityServerConfig.GetApis())
        .AddInMemoryClients(IdentityServerConfig.GetClients());
}

    public void Configuration(IAppBuilder appBuilder)
    {
        HttpConfiguration httpConfiguration = new HttpConfiguration();
        WebApiConfig.Register(httpConfiguration);
        appBuilder.UseWebApi(httpConfiguration);
    }

}

Here is a link to my project:

I've been looking for solution for couple of days, but I can't find anytning helpful. Excuse me if I've missed something.

Thanks.


回答1:


In case the question is about .NET Framework, but not ASP.NET version, it is possible to use .NET 4.7.2. The TestApi3.csproj has to look like:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="IdentityServer4" Version="2.4.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
  </ItemGroup>

</Project>

Then it should work based on ASP.NET CORE MVC, not MVC 5.



来源:https://stackoverflow.com/questions/55459716/cant-add-identityserver4-to-asp-net-framework-4-7-2-api-owin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!