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

通過 microsoft graph 從 azure ad 獲取組成員

get group members from azure ad via microsoft graph(通過 microsoft graph 從 azure ad 獲取組成員)
本文介紹了通過 microsoft graph 從 azure ad 獲取組成員的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在使用 asp.net 應用程序使用外部身份提供程序 (Azure Active Directory) 進行身份驗證

我想通過 microsoft graph 從 azure ad 獲取組成員

我該怎么做??

解決方案

似乎您正在嘗試從特定組中獲取所有組成員.只需

代碼片段:

您可以嘗試以下代碼片段,它可以按預期正常工作.

//令牌請求端點字符串 tokenUrl = $"https://login.microsoftonline.com/YourTenant.onmicrosoft.com/oauth2/token";var tokenRequest = new HttpRequestMessage(HttpMethod.Post, tokenUrl);//我正在使用 client_credentials 作為它主要推薦tokenRequest.Content = new FormUrlEncodedContent(new Dictionary<string, string>{["grant_type"] = "client_credentials",["client_id"] = "b6695c7be_YourClient_Id_e6921e61f659",["client_secret"] = "Vxf1SluKbgu4PF0Nf_Your_Secret_Yp8ns4sc=",["資源"] = "https://graph.microsoft.com/"});動態json;AccessTokenClass 結果 = new AccessTokenClass();HttpClient 客戶端 = 新 HttpClient();var tokenResponse = await client.SendAsync(tokenRequest);json = 等待 tokenResponse.Content.ReadAsStringAsync();結果 = JsonConvert.DeserializeObject(json);//用于從 Microsoft Graph Rest API 訪問組成員列表的新塊var groupId = "您要檢索的成員的組 ID";HttpClient _client = new HttpClient();HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, string.Format("https://graph.microsoft.com/v1.0/groups/{0}/members"),groupId);//為此請求傳遞令牌request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", results.access_token);HttpResponseMessage 響應 = 等待 _client.SendAsync(request);//獲取有商務電話和手機的用戶列表動態 objGpraphUserList = JsonConvert.DeserializeObject<動態>(等待響應.Content.ReadAsStringAsync());

使用的類:

 公共類 AccessTokenClass{公共字符串 token_type { 獲取;放;}公共字符串 expires_in { 獲取;放;}公共字符串資源 { 獲取;放;}公共字符串 access_token { 獲取;放;}}

權限:

您需要設置

測試請求結果:

有關更多詳細信息,您可以參考 官方文檔

希望它會有所幫助.如果您遇到任何問題,請隨時分享.

I am working in asp.net application Authenticate with external identity provider (Azure Active Directory)

I want to get group members from azure ad via microsoft graph

How can I do that ??

解決方案

Seems You are trying to get all group members from a specific group. Just Get the group Id that is Object Id on azure portal. See the below screen shot.

Code Snippet :

You could try following code snippet which work fine as expected.

    //Token Request End Point
    string tokenUrl = $"https://login.microsoftonline.com/YourTenant.onmicrosoft.com/oauth2/token";
    var tokenRequest = new HttpRequestMessage(HttpMethod.Post, tokenUrl);

    //I am Using client_credentials as It is mostly recommended
    tokenRequest.Content = new FormUrlEncodedContent(new Dictionary<string, string>
    {
        ["grant_type"] = "client_credentials",
        ["client_id"] = "b6695c7be_YourClient_Id_e6921e61f659",
        ["client_secret"] = "Vxf1SluKbgu4PF0Nf_Your_Secret_Yp8ns4sc=",
        ["resource"] = "https://graph.microsoft.com/" 
    });

    dynamic json;
    AccessTokenClass results = new AccessTokenClass();
    HttpClient client = new HttpClient();

    var tokenResponse = await client.SendAsync(tokenRequest);

    json = await tokenResponse.Content.ReadAsStringAsync();
    results = JsonConvert.DeserializeObject<AccessTokenClass>(json);


    //New Block For Accessing Group Member List from Microsoft Graph Rest API
    var groupId = "Group Id which Member You want to Retrieve";
    HttpClient _client = new HttpClient();
    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, string.Format("https://graph.microsoft.com/v1.0/groups/{0}/members"),groupId);
    //Passing Token For this Request
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", results.access_token);
    HttpResponseMessage response = await _client.SendAsync(request);
    //Get User List With Business Phones and Mobile Phones
    dynamic objGpraphUserList = JsonConvert.DeserializeObject<dynamic>(await response.Content.ReadAsStringAsync());

Class Used:

 public class AccessTokenClass
    {
        public string token_type { get; set; }
        public string expires_in { get; set; }
        public string resource { get; set; }
        public string access_token { get; set; }
    }

Permission:

You need to set User.Read.All, Group.Read.All, Directory.Read.All Application permission on Microsoft Graph API on azure portal.

Test Request Result:

For more details you could refer to Official Document

Hope it would help. Feel free to share if you encounter any problem.

這篇關于通過 microsoft graph 從 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 令牌授權不起作用)
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屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 2018天天干天天操 | 国产精品久久久久久久久久久免费看 | 亚洲一区二区免费视频 | 一区视频在线免费观看 | 欧美一级视频在线观看 | 性生生活大片免费看视频 | 亚洲欧美日韩国产综合 | 日本一区二区不卡 | 在线免费观看黄色网址 | 成人精品视频在线 | 一区二区精品在线 | 欧美一级片久久 | 国产精品久久久亚洲 | 男人的天堂中文字幕 | 国产精品成人一区二区三区 | 男人天堂免费在线 | 91精品在线观看入口 | 亚洲欧美综合 | 国产资源在线播放 | 好好的日在线视频 | 国产亚洲精品成人av久久ww | 免费成人高清在线视频 | 亚洲精品免费视频 | 91毛片网| 免费黄色av | 午夜av成人| 草草影院ccyy| 91久久精品一区二区三区 | 蜜桃视频一区二区三区 | 亚洲一区二区在线电影 | 国产精品久久久久久久久久三级 | 黄网站涩免费蜜桃网站 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | 91麻豆精品国产91久久久更新资源速度超快 | 国产成人精品午夜视频免费 | 亚洲欧洲成人av每日更新 | 99久久婷婷国产综合精品电影 | 一区二区三区亚洲 | 国产专区在线 | 中文字幕a√| 美女视频一区二区三区 |