久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

.net 核心 [授權(quán)] 將 ClaimsIdentity 與 AAD 組一起使用

.net core [Authorize] using ClaimsIdentity with AAD groups(.net 核心 [授權(quán)] 將 ClaimsIdentity 與 AAD 組一起使用)
本文介紹了.net 核心 [授權(quán)] 將 ClaimsIdentity 與 AAD 組一起使用的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我在 ((System.Security.Claims.ClaimsIdentity)User.Identity).Claims 中看到了這一點(diǎn):

I am seeing this in my ((System.Security.Claims.ClaimsIdentity)User.Identity).Claims:

如何使用從 Azure AD 獲取的這些組 GUID(以基于組成員身份保護(hù)端點(diǎn))?

How do I make use of these group GUID's I am getting from our Azure AD (to secure the endpoint based on group membership)?

[Authorize(Roles="<group guid here>")]

[Authorize("<group guid here>")]

或者我需要在 startup.cs 文件中進(jìn)行設(shè)置嗎?

Or do I need to set something up in the startup.cs file?

推薦答案

您可以在 asp.net core 中使用策略,使用具有命名策略的屬性,然后在啟動(dòng)時(shí)定義策略以要求組聲明并設(shè)置允許的組 ID:

You could use policy in asp.net core , use an attribute with a named policy then you define the policy in startup to require group claim and set allowed Group ID :

        public void ConfigureServices(IServiceCollection services)
        {
            // Add MVC services to the services container.
            services.AddMvc();

            // Add Authentication services.
            services.AddAuthentication(sharedOptions => sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);


            services.AddAuthorization(options =>
            {
                options.AddPolicy(
                    "CanAccessGroup",
                    policyBuilder => policyBuilder.RequireClaim("groups", "8e39f882-3453-4aeb-9efa-f6ac6ad8e2e0"));
            });
        }

然后在控制器中:

 [Authorize(Policy = "CanAccessGroup")]
 public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

如果組 id 不在用戶組聲明中,它會(huì)將用戶重定向到訪問(wèn)拒絕頁(yè)面,您也可以編寫策略規(guī)則邏輯,如下所示 這里 .

If the group id is not in the user group claims, it will redirect user to access denied page , you could also write your policy rules logic as shown here .

這篇關(guān)于.net 核心 [授權(quán)] 將 ClaimsIdentity 與 AAD 組一起使用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請(qǐng)求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問(wèn)令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問(wèn)令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 欧美中文字幕一区二区 | 涩爱av一区二区三区 | 亚洲精品字幕 | 久久99深爱久久99精品 | 自拍在线| 天天操夜夜爽 | 国产情侣一区 | 人人草人人干 | 久久久人 | av中文字幕在线 | 国产精品免费一区二区三区 | 粉嫩一区二区三区四区公司1 | 日韩国产一区二区三区 | 91综合网 | 亚洲成人精品在线 | 日韩精品免费一区二区在线观看 | 成人欧美一区二区三区色青冈 | av免费观看在线 | 国产福利资源在线 | 久久国产精品久久国产精品 | 日本精品一区二区三区在线观看视频 | 国产片淫级awww | 蜜桃精品噜噜噜成人av | 久久国产精品一区二区三区 | 亚洲国产精品久久久久 | 高清av在线 | 日韩av在线一区二区 | 一本色道精品久久一区二区三区 | www久久爱| 国产免费人成xvideos视频 | 亚洲日本免费 | 日本视频在线播放 | 日韩av高清 | 性一爱一乱一交一视频 | 日本一区二区高清视频 | 国产中文在线 | 日韩国产专区 | 欧美一级欧美三级在线观看 | 久久网站免费视频 | 青娱乐av | 美女久久视频 |