简体   繁体   English

OpenID 连接 ASP.NET MVC

[英]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.

相关问题 IdentityServer4和ASP.NET MVC(.NET 4.6.2)之间的OpenID连接 - OpenID connect between IdentityServer4 and ASP.NET MVC (.NET 4.6.2) 将 OpenID Connect 用户映射到 ASP.NET Core 身份用户 - Map OpenID Connect User to ASP.NET Core Identity User ASP.NET 使用外部 OpenID Connect 提供程序进行核心认证/授权 - ASP.NET Core authentication/authorization with external OpenID Connect provider ASP.NET OWIN OpenID Connect 未创建用户身份验证 - ASP.NET OWIN OpenID Connect not creating user authentication 如何在Asp.net MVC中实现自定义OpenId提供程序 - How to implement custom OpenId provider in Asp.net MVC 未找到 DotNetOpenAuth ASP.NET MVC 登录示例的 OpenID 端点 - No OpenID endpoint found for DotNetOpenAuth ASP.NET MVC Login sample 将Google的Web表单ASP.NET Membership OpenAuth从OpenID 2.0迁移到OpenID Connect - Migrate web forms ASP.NET Membership OpenAuth for Google from OpenID 2.0 to OpenID Connect 连接到设备ASP.NET MVC - Connect to device ASP.NET MVC net.core / asp.net 身份 / openid 连接中的关联失败 - Correlation failed in net.core / asp.net identity / openid connect 不支持本机.Net身份验证的多租户OpenID集成到ASP.Net MVC Web应用程序 - Multi tenant OpenID integration to ASP.Net MVC web application without native .Net authentication support
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM