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

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

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

問題描述

限時送ChatGPT賬號..

我正在針對 Azure Active Directory 對我的 Web api 用戶進行身份驗證.現在我想獲取該用戶所屬的組列表.

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.

我更改了應用程序清單以包含

I changed application manifest to include

"groupMembershipClaims": "All",

但這所做的只是添加聲明 hasGroups 但沒有組名.

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

我在門戶中為我的應用授予了 Windows Azure Active Directory 的所有 (8) 項委派權限.

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

推薦答案

我確實做到了.

讓我們將我的 Azure AD 應用程序稱為AD-App".

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

廣告應用

其他應用程序的權限設置為;

Windows Azure 活動目錄.

Windows Azure Active Directory.

應用程序權限:0.

委派權限 2(讀取目錄數據"、登錄并讀取用戶配置文件".

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

Manifest 有如下設置:

"groupMembershipClaims": "SecurityGroup"

"groupMembershipClaims": "SecurityGroup"

后端 API

以下是我返回用戶組的方法.要么您發送用戶 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;
    }

我不能告訴你這是否是最佳實踐,但它對我有用.

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

這篇關于在聲明中獲取 Azure AD 用戶所屬的組列表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 超時)
主站蜘蛛池模板: 天天干.com | 亚洲日韩第一页 | 国产毛片av | 国产精品观看 | 91久久精品一区二区二区 | 一区二区视频在线观看 | 国产精品一区二区三区四区 | 一区中文 | 国产福利91精品 | 中文字幕视频网 | 在线播放国产视频 | 久久精品中文 | 亚洲一区 中文字幕 | 久久久久久久国产精品 | 久久久免费少妇高潮毛片 | 天天久久 | 看av片网站 | 亚洲在线免费 | 久久国产精品-久久精品 | 日韩高清一区 | 激情欧美日韩一区二区 | 超碰人人人人 | 成人在线视频网站 | 三级av在线 | 久久久久国产精品 | 免费在线a视频 | 欧美一级毛片在线播放 | av天天干| 久久久青草婷婷精品综合日韩 | 国产日本精品视频 | 男女免费观看在线爽爽爽视频 | 九九久久国产精品 | 国产精品黄视频 | 在线免费观看a级片 | 久久精品日 | 精品国产伦一区二区三区观看方式 | 草久久久| 亚洲成人自拍 | 亚洲综合区 | 亚洲 欧美 日韩 在线 | 日韩综合色 |