Sam*_*rie 5 authentication nancy owin identityserver3
我们有一个以下环境:
...现在我们想开始添加一个OWIN托管的Web应用程序,该应用程序将使用NancyFx来提供服务器呈现的页面以及几个AngularJS SPA.此Nancy网站不会托管任何API,但可能会使用现有API中的数据.我想在OWIN管道中添加身份验证,以帮助保护我们的Angular应用程序不被发送给没有访问权限的用户.
这与发送SPA代码相反,并且让Angular确定用户是否应该看到任何内容.在那种情况下,我们已经公开了javascript代码库,我们希望避免这种情况.
我试图了解如何配置此Nancy站点以使用隐式流对IdentityServer的用户进行身份验证.我之前在独立SPA中实现了这种身份验证方案(其中所有身份验证都由AngularJS代码处理,令牌存储在HTML5本地存储中),但我对如何在OWIN管道中正确解决这个问题感到有点迷茫.
我认为OWIN cookie认证中间件是答案,但这是否意味着以下内容?
......或者我在想这一切都错了?
作为参考,我已经阅读了以下帖子,他们非常有帮助,但我不太了解OWIN的大局.接下来我将尝试使用UseOpenIdConnectAuthentication中间件,但我将非常感谢SO可能提供的任何指导.
https://github.com/IdentityServer/IdentityServer3/issues/487
从根本上来说,在通过 OWIN 托管的 Nancy 应用程序中实现 OpenID Connect 身份验证实际上与在任何 MVC/Katana 应用程序中实现它没有什么不同(Thinktecture 团队有一个针对此场景的示例: https: //github.com/IdentityServer/IdentityServer3.Samples ) /tree/master/source/Clients/MVC%20OWIN%20Client)
您基本上需要 3 个东西:cookie 中间件、OpenID Connect 中间件和 Nancy 中间件:
public class Startup {
public void Configuration(IAppBuilder app) {
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationMode = AuthenticationMode.Active,
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions {
AuthenticationMode = AuthenticationMode.Active,
// Set the address of your OpenID Connect server:
Authority = "http://localhost:54541/"
// Set your client identifier here:
ClientId = "myClient",
// Set the redirect_uri and post_logout_redirect_uri
// corresponding to your application:
RedirectUri = "http://localhost:56765/oidc",
PostLogoutRedirectUri = "http://localhost:56765/"
});
app.UseNancy(options => options.PerformPassThrough = context => context.Response.StatusCode == HttpStatusCode.NotFound);
}
}
Run Code Online (Sandbox Code Playgroud)
如果您正在寻找功能演示,可以查看https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server/tree/dev/samples/Nancy/Nancy.Client(注意:它不使用 IdentityServer3 作为 OIDC 服务器部分,但它不应该对客户端应用程序产生任何影响)。
| 归档时间: |
|
| 查看次数: |
1338 次 |
| 最近记录: |