簡體   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