具有IdentityServer3 AccessTokenValidation的Identityserver4

时间:2017-03-10 17:47:04

标签: c# identityserver3 identityserver4

我使用IdentityServer3.AccessTokenValidation(v2.13.0)web api设置IdentityServer4。也许是因为密钥不是509x证书

问题是web api没有使用IdentityServer4进行身份验证。

WEB API startup.cs

public void Configuration(IAppBuilder app)
    {
        app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
        {
            Authority = "http://identity.positive.local:5000",
            RequiredScopes = new[] { "odbc" }
        });
    }

IdentityServer4 Startup.cs(http://identity.positive.local:5000

  services.AddIdentityServer()
            .AddSigningCredential(key)
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients());

IdentityServer4 Config.cs(http://identity.positive.local:5000

 public class Config
{
    public static IEnumerable<IdentityResource> GetIdentityResources()
    {
        return new List<IdentityResource>
        {
            new IdentityResources.OpenId(),
            new IdentityResources.Profile(),
        };
    }

    public static IEnumerable<ApiResource> GetApiResources()
    {
        return new List<ApiResource>
        {
            new ApiResource("api", "POSI_Master-API"),
            new ApiResource("odbc", "POSI_Odbc-API")
        };
    }
    public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
        {

             new Client
            {
                ClientId = "js",
                ClientName = "JavaScript Client",
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowAccessTokensViaBrowser = true,
                RequireConsent = false,
                RedirectUris = { "http://products.positive.local/auth" },
                PostLogoutRedirectUris = { "http://products.positive.local" },
                AllowedCorsOrigins = { "http://products.positive.local" },

                AllowedScopes =
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    "api",
                    "odbc"
                },
            }
        };
    }

}
}

enter image description here

编辑:

  

抛出异常:&#39; System.Reflection.ReflectionTypeLoadException&#39;在   mscorlib.dll iisexpress.exe警告:0:消息=&#39;抛出异常   从Microsoft.IdentityModel.Protocol.Extensions获取类型时,   版本= 1.0.40306.1554,文化=中立,   公钥= 31bf3856ad364e35&#39;&#39 ;,   Exception = System.Reflection.ReflectionTypeLoadException:无法执行   加载一个或多个请求的类型。检索LoaderExceptions   物业了解更多信息。在   System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)at   System.Reflection.RuntimeModule.GetTypes()at   System.Reflection.Assembly.GetTypes()at   System.Web.Http.Tracing.Tracers.DefaultHttpControllerTypeResolverTracer.GetTypesAndTrace(大会   组件)

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="IdentityModel" version="1.13.1" targetFramework="net452" />
  <package id="IdentityServer3.AccessTokenValidation" version="2.14.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.Cors" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.3" targetFramework="net452" />
  <package id="Microsoft.IdentityModel.Logging" version="1.1.3" targetFramework="net452" />
  <package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.4.403061554" targetFramework="net452" />
  <package id="Microsoft.IdentityModel.Tokens" version="5.1.3" targetFramework="net452" />
  <package id="Microsoft.Net.Compilers" version="2.0.1" targetFramework="net452" developmentDependency="true" />
  <package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
  <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net452" />
  <package id="Microsoft.Owin.Security.Jwt" version="3.0.1" targetFramework="net452" />
  <package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net452" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
  <package id="Owin" version="1.0" targetFramework="net452" />
  <package id="System.IdentityModel.Tokens.Jwt" version="5.1.3" targetFramework="net452" />
  <package id="System.Net.Http" version="4.3.1" targetFramework="net452" />
</packages>

1 个答案:

答案 0 :(得分:0)

针对HttpClient中的错误报告了一些问题 - 尝试手动更新到System.Net.Http 4.3.1。

我们昨天也更新了我们的套餐。

此repo执行各种IS3 / 4和API场景排列。

https://github.com/IdentityServer/CrossVersionIntegrationTests

将其与您的方案进行比较。