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

在聲明中獲取 Azure AD 用戶所屬的組列表

Get a list of groups that Azure AD user belongs to in claims(在聲明中獲取 Azure AD 用戶所屬的組列表)
本文介紹了在聲明中獲取 Azure AD 用戶所屬的組列表的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

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

我正在針對(duì) Azure Active Directory 對(duì)我的 Web api 用戶進(jìn)行身份驗(yàn)證.現(xiàn)在我想獲取該用戶所屬的組列表.

I am authenticating users of my web api against Azure Active Directory. Now I want to get a list of groups that this user belongs.

我更改了應(yīng)用程序清單以包含

I changed application manifest to include

"groupMembershipClaims": "All",

但這所做的只是添加聲明 hasGroups 但沒(méi)有組名.

but all this does is to add claim hasGroups but no group names.

我在門(mén)戶中為我的應(yīng)用授予了 Windows Azure Active Directory 的所有 (8) 項(xiàng)委派權(quán)限.

I granted all (8) Delegated Permissions to Windows Azure Active Directory for my app in the portal.

推薦答案

我確實(shí)做到了.

讓我們將我的 Azure AD 應(yīng)用程序稱為AD-App".

Let's call my Azure AD appication "AD-App".

廣告應(yīng)用

其他應(yīng)用程序的權(quán)限設(shè)置為;

Windows Azure 活動(dòng)目錄.

Windows Azure Active Directory.

應(yīng)用程序權(quán)限:0.

委派權(quán)限 2(讀取目錄數(shù)據(jù)"、登錄并讀取用戶配置文件".

Delegated Permissions 2 ("Read directory data", "Sign in and read user profile".

Manifest 有如下設(shè)置:

"groupMembershipClaims": "SecurityGroup"

"groupMembershipClaims": "SecurityGroup"

后端 API

以下是我返回用戶組的方法.要么您發(fā)送用戶 ID,否則它使用聲明中的 ID.Id 的意思是objectIdentifier".

The following is my method to return the users groups. Either you send in the users id, if not it uses the id from claims. Id meaning "objectIdentifier".

        public static IEnumerable<string> GetGroupMembershipsByObjectId(string id = null)
    {
        if (string.IsNullOrEmpty(id))
            id = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

        IList<string> groupMembership = new List<string>();
        try
        {
            ActiveDirectoryClient activeDirectoryClient = ActiveDirectoryClient;
            IUser user = activeDirectoryClient.Users.Where(u => u.ObjectId == id).ExecuteSingleAsync().Result;
            var userFetcher = (IUserFetcher)user;

            IPagedCollection<IDirectoryObject> pagedCollection = userFetcher.MemberOf.ExecuteAsync().Result;
            do
            {
                List<IDirectoryObject> directoryObjects = pagedCollection.CurrentPage.ToList();
                foreach (IDirectoryObject directoryObject in directoryObjects)
                {
                    if (directoryObject is Group)
                    {
                        var group = directoryObject as Group;
                        groupMembership.Add(group.DisplayName);
                    }
                }
                pagedCollection = pagedCollection.GetNextPageAsync().Result;
            } while (pagedCollection != null);

        }
        catch (Exception e)
        {
            ExceptionHandler.HandleException(e);
            throw e;
        }

        return groupMembership;
    }

我不能告訴你這是否是最佳實(shí)踐,但它對(duì)我有用.

I can't tell you wether this is done by best practice or not, but it works for me.

這篇關(guān)于在聲明中獲取 Azure AD 用戶所屬的組列表的文章就介紹到這了,希望我們推薦的答案對(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屋-程序員軟件開(kāi)發(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í))
主站蜘蛛池模板: 国产成人小视频 | 99伊人网| 中文天堂在线一区 | 成人片免费看 | 国产精品欧美一区二区三区不卡 | 亚洲成人免费视频在线 | 岛国av在线免费观看 | 日韩免费在线观看视频 | 超碰在线播 | 黄色精品| 日韩a| 伊人网伊人网 | 中文字幕亚洲欧美日韩在线不卡 | 国产在线精品一区二区三区 | 91精品综合久久久久久五月天 | 精品视频在线观看 | 国产精品精品视频一区二区三区 | 日本不卡视频 | 国产精品久久久久aaaa | 丝袜美腿一区二区三区 | 中文字幕av色 | 伊人国产精品 | 欧美 日韩 视频 | 国产精品99视频 | 国产一二三区精品视频 | 国产日韩精品视频 | 日日干天天操 | 成人一区在线观看 | 狠狠干2020 | 看特级黄色片 | 日韩一区二区三区在线 | 91精品国产高清一区二区三区 | 在线免费黄色小视频 | 美美女高清毛片视频免费观看 | 日韩欧美中文字幕在线观看 | 国产成人av一区二区三区 | 日日摸日日添日日躁av | 日韩av在线一区二区三区 | 成人国产一区二区三区精品麻豆 | av毛片免费 | 日韩中文字幕一区 |