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

向 AspNetCore Azure Authenticated Application 添加自定義聲

Adding Custom Claims to AspNetCore Azure Authenticated Application(向 AspNetCore Azure Authenticated Application 添加自定義聲明)
本文介紹了向 AspNetCore Azure Authenticated Application 添加自定義聲明的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在通過這行代碼使用 AspNetCore 模板授權:

I am using the AspNetCore template authorization with this line of code:

       services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
            .AddAzureAD(options => Configuration.Bind("AzureAd", options));

用戶獲得 Azure 授權后,如何添加我的自定義聲明?

How can I add my custom Claims after the user is authorized by Azure?

推薦答案

您可以在OIDC事件的OnTokenValidated中添加自定義cliams:

You can add custom cliams in OnTokenValidated of OIDC event :

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
            .AddAzureAD(options => Configuration.Bind("AzureAd", options));


services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
{
    options.Events = new OpenIdConnectEvents
    {
        OnTokenValidated = ctx =>
        {


            // add claims
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.Role, "Admin")
            };
            var appIdentity = new ClaimsIdentity(claims);

            ctx.Principal.AddIdentity(appIdentity);

            return Task.CompletedTask;
        },
    };
});

然后在控制器中,您可以獲得如下聲明:

Then in controller , you can get the claim like :

var role = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Role)?.Value;

這篇關于向 AspNetCore Azure Authenticated Application 添加自定義聲明的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
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(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 国产一区不卡 | a级片在线观看 | 国产三级久久 | 日韩精品| 欧美在线播放 | 成人精品在线 | 日本精品视频 | 九九热视频在线 | 久久av网站 | 五月婷婷综合在线 | 日韩精品久久久久 | 国产精品视频一区二区三区 | 黄色在线观看网址 | 国产激情在线观看 | 亚洲视频免费在线观看 | 色综合av| 一级黄色片网站 | www.久久久久 | 亚洲激情视频在线 | 另类小说第一草 | 亚洲欧美中文字幕 | 99久久精品国产毛片 | 国产va在线观看 | 在线观看av片 | 免费看黄色小视频 | 精品成人在线 | 欧美日韩中文字幕在线观看 | 日产精品久久久一区二区 | 蜜桃视频一区二区三区 | 一级久久 | 美女扒开腿让人桶爽原神 | 亚洲欧美在线视频 | 夜间福利视频 | 饥渴放荡受np公车奶牛 | 久久a级片| 国产又粗又大又硬 | 一级片在线观看视频 | 中文字幕高清在线 | 日韩不卡一区二区 | 欧美精品在线观看 | 伊人天堂网|