久久久久久久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精品热| 亚洲国产精品一区二区三区 | 亚洲国产精品久久久久久久 | 午夜激情网站 | 黄色1级片 | 秋霞福利视频 | 亚洲欧美精品一区二区 | 国产午夜影院 | 免费理论片 | 日本少妇久久 | cao视频 | 久久性生活视频 | 一级黄色免费 | 久久婷婷网 | 美女视频福利 | 久久99久久久 | 国产精品久久久久久久久久久久久久 | 欧美三级 欧美一级 | 中文字幕高清在线 | 欧美三级精品 | 久久综合五月天 | 亚洲精品麻豆 | 97国产在线观看 | 欧美激情综合五月色丁香 | 欧美日韩精品久久 | 伊人操| 四虎精品视频 | 成人国产精品一区二区 | 91亚洲国产成人久久精品网站 | av网站在线播放 | 九月色婷婷 | 久久性色 | 欧美成人综合 | 黄色三级在线观看 | 国产伦精品一区二区免费 | 青青草网站| 亚洲成人一区 | 国产精品三级在线 | 一区二区三区四区精品 |