Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过microsoft graph从azure广告中获取组成员_C#_Asp.net Mvc_Azure Active Directory_Microsoft Graph Api - Fatal编程技术网

C# 通过microsoft graph从azure广告中获取组成员

C# 通过microsoft graph从azure广告中获取组成员,c#,asp.net-mvc,azure-active-directory,microsoft-graph-api,C#,Asp.net Mvc,Azure Active Directory,Microsoft Graph Api,我正在使用asp.net应用程序通过外部身份提供程序(Azure Active Directory)进行身份验证 我想通过microsoft graph从azure广告中获取组成员 我该怎么做???似乎您正在尝试从特定组获取所有组成员。就在azure门户上。请参见下面的屏幕截图 代码片段: 您可以尝试以下代码段,这些代码段工作正常 //Token Request End Point string tokenUrl = $"https://login.microsoftonlin

我正在使用asp.net应用程序通过外部身份提供程序(Azure Active Directory)进行身份验证

我想通过microsoft graph从azure广告中获取组成员


我该怎么做???

似乎您正在尝试从特定组获取所有组成员。就在azure门户上。请参见下面的屏幕截图

代码片段:

您可以尝试以下代码段,这些代码段工作正常

    //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());
权限:

您需要在azure portal上的Microsoft Graph API上设置应用程序权限

测试请求结果:

有关更多详细信息,请参阅


希望能有帮助。如果您遇到任何问题,请随时与他人分享。

似乎您正在尝试从特定组中获取所有组成员。就在azure门户上。请参见下面的屏幕截图

代码片段:

您可以尝试以下代码段,这些代码段工作正常

    //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());
权限:

您需要在azure portal上的Microsoft Graph API上设置应用程序权限

测试请求结果:

有关更多详细信息,请参阅


希望能有帮助。如果您遇到任何问题,请随时与我们分享。

什么是[“授权类型”]=“客户端凭据”?这是一个。对于任何
Microsoft Graph
操作,您必须首先获取令牌,
客户端凭据
协议是最推荐的令牌协议之一。希望你能理解我的观点。如果你有代币,只需跳过代币部分,关注Microsoft Graph Request的
部分即可。如果您还有任何问题,请随时与我们分享。我得到以下信息{“错误”:{“代码”:“InvalidAuthenticationToken”,“消息”:“CompactToken解析失败,错误代码为:80049217”,“innerError”:{“请求id”:“7e8b8a5b-9c33-4162-bf02-68d8b8774555”,“日期”:“2020-02-28T08:37:12”}}您使用的是哪种协议?用您的令牌请求代码更新您的问题什么是[“授权类型”]=“客户端凭据”?它是一个。对于任何
Microsoft Graph
操作,您必须首先获取令牌,
客户端凭据
协议是最推荐的令牌协议之一。希望你能理解我的观点。如果你有代币,只需跳过代币部分,关注Microsoft Graph Request的
部分即可。如果您还有任何问题,请随时与我们分享。我得到以下信息{“错误”:{“代码”:“InvalidAuthenticationToken”,“消息”:“CompactToken解析失败,错误代码为:80049217”,“innerError”:{“请求id”:“7e8b8a5b-9c33-4162-bf02-68d8b8774555”,“日期”:“2020-02-28T08:37:12”}}您使用的是哪种协议?用您的令牌请求代码更新您的问题,您可以告诉我们,您被卡在哪里?这也有助于我们更好地回答您的问题。您能告诉我们,您被困在哪里吗?这也将帮助我们更好地回答您的问题。