久久久久久久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 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 亚洲精品一区二区三区中文字幕 | 天天操精品视频 | 久久男人 | 日韩另类| 国产精品视频二区三区 | 免费在线一区二区 | 先锋影音资源网站 | 国产精品亚洲二区 | 四虎首页 | 久久99精品国产 | 成人精品一区二区 | 成人免费在线观看视频 | 欧美v免费 | 亚洲欧美日韩成人在线 | 久久中文免费视频 | 中文字幕亚洲欧美 | 一区二区在线 | 久久综合伊人 | 欧美 日韩 国产 成人 | 涩爱av一区二区三区 | 自拍视频精品 | 日本一区二区三区在线观看 | 欧美日韩黄| 婷婷91| 日韩欧美国产一区二区三区 | 日韩欧美网 | 精品1区| 97av视频在线| 久草久草久草 | 婷婷色婷婷 | 欧美精品在线免费观看 | 成年人在线观看 | 羞羞午夜 | 激情欧美一区二区三区中文字幕 | 一区二区三区在线免费 | 久久久久久久久久毛片 | 精品一区二区三区在线观看 | 91社影院在线观看 | 日韩一区av | 美国a级毛片免费视频 | 国产女人与拘做受免费视频 |