繁体   English   中英

OpenID 连接 ASP.NET MVC

[英]OpenID Connect with ASP.NET MVC

标题中的问题相当简单。 Internet 上所有可用的教程都讨论了 .NET Core 中的 OpenID Connect 实现。 我当前的项目是在 ASP.NET MVC(不是 ASP.NET Core)中开发的,我需要在其中实现 OpenID Connect。

我关注了这篇文章并尝试过,但没有运气!

对此的任何帮助/澄清将不胜感激。

首先,您必须忘记在 web.config 中配置权限。
然后,您必须确保为每个控制器分配Authorize属性(确保使用全局过滤器方法)。
参考Microsoft.Owin.Security.OpenIdConnect及其所有依赖项。
使用public void Configuration(IAppBuilder app)方法添加 Owin Startup 类。 如下:

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",
        });
    }
  }
}

使用“Owin”、“Katana”和“Identityserver3”关键字进行进一步搜索。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM