【问题标题】:Azure AD Graph API add member to groupAzure AD Graph API 将成员添加到组
【发布时间】:2014-10-12 17:47:10
【问题描述】:

我正在尝试使用 aad graph api 将成员添加到组中,但我不断收到 404。 当我尝试获取组成员时,类似的代码对我有用。 这是代码:

string requestUrl = string.Format("https://graph.windows.net/{0}/groups/{1}/$linkes/members?api-version=2013-04-05", tenantName, group.ObjectId);

string postData = string.Format("\"url\":\"https://graph.windows.net/{0}/users/{1}?api-version=2013-04-05\"", tenantName, user.ObjectId);

HttpWebRequest webRequest = WebRequest.Create(requestUrl) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.Headers["Authorization"] = authenticationResult.CreateAuthorizationHeader();
webRequest.ContentType = "application/json"; //"application/x-www-form-urlencoded"; 
webRequest.Host = "graph.windows.net";
webRequest.ContentLength = postData.Length;

byte[] byteArray = Encoding.UTF8.GetBytes(postData);
using (Stream dataStream = webRequest.GetRequestStream())
{
    dataStream.Write(byteArray, 0, byteArray.Length);
}

string jsonText;
var httpResponse = (HttpWebResponse)webRequest.GetResponse();
using (var streamReader =
       new StreamReader(httpResponse.GetResponseStream()))
{
    jsonText = streamReader.ReadToEnd();
}

我知道还有其他方法可以完成相同的工作,例如使用图形连接,但我更喜欢使用这种方式,因为它也适用于角色。 谢谢

【问题讨论】:

    标签: c# azure azure-active-directory


    【解决方案1】:

    您的网址似乎有错字:$linkes。应该是 $links。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-11
      • 2021-04-12
      • 1970-01-01
      相关资源
      最近更新 更多