使用客户端凭证的服务到服务调用
Service to Service Calls Using Client Credentials
我尝试使用以下代码在 office 365 中为组创建别名,但它显示了一些 error.how 来解决这个问题。我尝试使用服务到服务调用方法。我得到了生成的令牌。如何检查其有效与否?是否可以使用 api 为没有 powershell 选项的组创建别名?如果没有请建议我其他选择..
string clientId = "************";
string clientsecret = "******";
string tenantId = "********";
//string resourceUri = "http://office.microsoft.com/outlook/";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
var authUri = "https://login.windows.net/" + tenantId + "/oauth2/authorize/";
var RESOURCE_URL = "https://graph.windows.net";
HttpClient client = new HttpClient();
var authContext = new AuthenticationContext(authUri);
var credential = new ClientCredential(clientId: clientId, clientSecret: clientsecret);
var result = authContext.AcquireTokenAsync(RESOURCE_URL, credential).Result;
client.DefaultRequestHeaders.Add("Authorization", "bearer " + result.AccessToken);
string content = @"{
'displayName': 'mailgrouptest',
'groupTypes': ['Unified'],
'mailEnabled': true,
'mailNickname': 'mailalias1',
'securityEnabled': false
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups", httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
当我 运行 控制台中的这段代码显示这样的错误....是令牌的问题吗?或租户 ID?
{
"error": {
"code": "InvalidAuthenticationToken",
"message": "Access token validation failure.",
"innerError": {``
"request-id": "*****-***-",
"date": "2016-05-25T04:53:08"
}
}
}
请建议我为 api
中的组创建别名
组的mailNickName目前无法使用Microsoft Graph更新。
作为一种变通方法,我们可以创建一个包含您想要的特定邮件昵称的新组并使用该新组。下面是用mailNicekName创建群组的代码供大家参考:
string clientId = "";
string clientsecret = "";
string tenant = "yourdomain.onmicrosoft.com";
var authUri = "https://login.microsoftonline.com/"+tenant+"/oauth2/token";
var RESOURCE_URL = "https://graph.microsoft.com";
HttpClient client = new HttpClient();
var authContext = new AuthenticationContext(authUri);
var credential = new ClientCredential(clientId: clientId, clientSecret: clientsecret);
var result = authContext.AcquireTokenAsync(RESOURCE_URL, credential).Result;
client.DefaultRequestHeaders.Add("Authorization", "bearer " + result.AccessToken);
string content = @"{
'description': 'description-value',
'displayName': 'displayName-value',
'groupTypes': [
'Unified'
],
'mailEnabled': true,
'mailNickname': 'mailNickname-value',
'securityEnabled': false
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
//var response = client.GetAsync("https://graph.microsoft.com/v1.0/groups").Result;
var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups",httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
更多关于 Goupr REST 的细节API,请参考here。
对于错误“InvalidAuthenticationToken”,您使用不正确的资源请求访问令牌。要使用 Microsoft Graph API,我们需要使用“https://graph.microsoft.com” instead of “https://graph.windows.net”指定资源。
另外,如果希望群的mailNickName可以更新,可以尝试提交here的反馈。
我尝试使用以下代码在 office 365 中为组创建别名,但它显示了一些 error.how 来解决这个问题。我尝试使用服务到服务调用方法。我得到了生成的令牌。如何检查其有效与否?是否可以使用 api 为没有 powershell 选项的组创建别名?如果没有请建议我其他选择..
string clientId = "************";
string clientsecret = "******";
string tenantId = "********";
//string resourceUri = "http://office.microsoft.com/outlook/";
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
var authUri = "https://login.windows.net/" + tenantId + "/oauth2/authorize/";
var RESOURCE_URL = "https://graph.windows.net";
HttpClient client = new HttpClient();
var authContext = new AuthenticationContext(authUri);
var credential = new ClientCredential(clientId: clientId, clientSecret: clientsecret);
var result = authContext.AcquireTokenAsync(RESOURCE_URL, credential).Result;
client.DefaultRequestHeaders.Add("Authorization", "bearer " + result.AccessToken);
string content = @"{
'displayName': 'mailgrouptest',
'groupTypes': ['Unified'],
'mailEnabled': true,
'mailNickname': 'mailalias1',
'securityEnabled': false
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups", httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
当我 运行 控制台中的这段代码显示这样的错误....是令牌的问题吗?或租户 ID?
{ "error": { "code": "InvalidAuthenticationToken", "message": "Access token validation failure.", "innerError": {`` "request-id": "*****-***-", "date": "2016-05-25T04:53:08" } } }
请建议我为 api
中的组创建别名组的mailNickName目前无法使用Microsoft Graph更新。
作为一种变通方法,我们可以创建一个包含您想要的特定邮件昵称的新组并使用该新组。下面是用mailNicekName创建群组的代码供大家参考:
string clientId = "";
string clientsecret = "";
string tenant = "yourdomain.onmicrosoft.com";
var authUri = "https://login.microsoftonline.com/"+tenant+"/oauth2/token";
var RESOURCE_URL = "https://graph.microsoft.com";
HttpClient client = new HttpClient();
var authContext = new AuthenticationContext(authUri);
var credential = new ClientCredential(clientId: clientId, clientSecret: clientsecret);
var result = authContext.AcquireTokenAsync(RESOURCE_URL, credential).Result;
client.DefaultRequestHeaders.Add("Authorization", "bearer " + result.AccessToken);
string content = @"{
'description': 'description-value',
'displayName': 'displayName-value',
'groupTypes': [
'Unified'
],
'mailEnabled': true,
'mailNickname': 'mailNickname-value',
'securityEnabled': false
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
//var response = client.GetAsync("https://graph.microsoft.com/v1.0/groups").Result;
var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups",httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
更多关于 Goupr REST 的细节API,请参考here。
对于错误“InvalidAuthenticationToken”,您使用不正确的资源请求访问令牌。要使用 Microsoft Graph API,我们需要使用“https://graph.microsoft.com” instead of “https://graph.windows.net”指定资源。
另外,如果希望群的mailNickName可以更新,可以尝试提交here的反馈。