[英]OpenID Connect with ASP.NET MVC
The question in the title is fairly simple.标题中的问题相当简单。 All the tutorials available on internet talk about OpenID Connect implementation in .NET Core. Internet 上所有可用的教程都讨论了 .NET Core 中的 OpenID Connect 实现。 My current project is developed in ASP.NET MVC (not ASP.NET Core) and I am required to implement OpenID Connect in it.我当前的项目是在 ASP.NET MVC(不是 ASP.NET Core)中开发的,我需要在其中实现 OpenID Connect。
I followed this post and tried but to no luck!我关注了这篇文章并尝试过,但没有运气!
Any help / clarification on this will be appreciated.对此的任何帮助/澄清将不胜感激。
First of all you have to forget about configuring authority in web.config.首先,您必须忘记在 web.config 中配置权限。
Then you have to ensure you assign Authorize
attribute to every controller (use global filter approach to be sure).然后,您必须确保为每个控制器分配Authorize
属性(确保使用全局过滤器方法)。
Reference Microsoft.Owin.Security.OpenIdConnect
and all its dependencies.参考Microsoft.Owin.Security.OpenIdConnect
及其所有依赖项。
Add Owin Startup class with public void Configuration(IAppBuilder app)
method.使用public void Configuration(IAppBuilder app)
方法添加 Owin Startup 类。 As the following:如下:
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
//before v5.0 was: using System.IdentityModel.Tokens;
[assembly: OwinStartup(typeof(MVC_OWIN_Client.Startup))]
namespace MVC_OWIN_Client
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap =
new Dictionary<string, string>();
// before v5.0 was: JwtSecurityTokenHandler.InboundClaimTypeMap
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = <Your app instance' identifier, must be registered in IdP>,
Authority = <your IdP>,
RedirectUri = <base address of your app as registered in IdP>,
ResponseType = "id_token",
Scope = "openid email",
UseTokenLifetime = false,
SignInAsAuthenticationType = "Cookies",
});
}
}
}
Use "Owin", "Katana" and "Identityserver3" keywords for further search.使用“Owin”、“Katana”和“Identityserver3”关键字进行进一步搜索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.