2015-05-01 39 views
9

我已经使用了IdentityServer v3,现在我想让一个网站既是身份主机又是web api主机。UseIdentityServerBearerTokenAuthentication对IdentityServer3不起作用

机构选项不用于验证令牌。我已经验证了令牌端点,并且令牌验证端点按预期工作(我可以使用邮递员获取并验证令牌)。我使用[Authorize]属性来装饰我的控制器方法。在IdentityServer上启用完整日志记录,当使用'Bearer mytokenhere'等值的标头名称'Authorization'进行api请求时,没有任何记录。

这是使用Visual Studio 2015 CTP6的ASP.NET 5上的vNext网站。

 app.UseMvc(); 

     var certFile = AppDomain.CurrentDomain.BaseDirectory + "\\myawesomesite.pfx"; 

     app.Map("/core", core => 
     { 
      var factory = InMemoryFactory.Create(
          users: Users.Get(), 
          clients: Clients.Get(), 
          scopes: Scopes.Get()); 

      var idsrvOptions = new IdentityServerOptions 
      { 
       SiteName = "Lektieplan", 
       Factory = factory, 
       RequireSsl = false, 
       SigningCertificate = new X509Certificate2(certFile, "lektieplan"), 
       CorsPolicy = CorsPolicy.AllowAll, 
       LoggingOptions = new LoggingOptions { EnableWebApiDiagnostics = true,EnableHttpLogging = true, IncludeSensitiveDataInLogs = true, WebApiDiagnosticsIsVerbose = true } 
      }; 

      core.UseIdentityServer(idsrvOptions); 
     }); 

     app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions 
     { 
      Authority = "http://localhost:57540/core", 
      RequiredScopes = new[] { "api1" }, 
     }); 

而且我project.json

我的依赖关系:

"Microsoft.AspNet.Server.IIS": "1.0.0-beta3", 
    "Microsoft.AspNet.Mvc": "6.0.0-beta3", 
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta3", 
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta3", 
    "Thinktecture.IdentityServer3": "1.3.0.0", 
    "Microsoft.AspNet.Owin": "1.0.0.0-beta3", 
    "Microsoft.AspNet.Security.DataProtection": "1.0.0.0-beta3", 
    "Thinktecture.IdentityServer3.AccessTokenValidation": "1.2.2", 
    "Autofac": "4.0.0-alpha1", 
    "log4net": "2.0.3" 

我在我看来,一些提供的样品的工作,因为一个基于cookie的选项。我不想使用cookie。

+1

我认为用于身份验证的owin中间件与/ core owin中间件冲突,任何提示如何调试? – Jacee

+2

有什么消息吗?它现在工作吗?我也想这样做。 – dknaack

回答

3

是UseIdentityServerBearerTokenAuthentication您唯一的身份验证类型?你有没有为MVC定义过滤器?

我会尝试将应用程序拆分为单独的katana管道,因此它们根本不冲突。

伪:

app.Map("/core", a => a.UseIdsrv()); 
app.Map("/somethingweb", a => a.UseMvc()); 
app.Map("/api", a => { 
    a.UseBearerTokenAuth(); 
    a.UseWebApi(); //or Mvc from now on, with v5 
}); 

猜测你将需要cookieauth添加到MVC管道为好,这取决于你想要达到的目标。