虽然我没有关于如何使用Node做到这一点的示例,也许C#中的解决方案将有所帮助?
您这样做的方式是检查Activity
对象到达控制器的entities
集合。由于这是的一部分,每请求bot,您可以随时做到这一点。
在entities
集合中,Cortana放入authorization
条目,其中包含由连接服务的身份验证流程产生的令牌。如果您使用连接服务来访问Microsoft服务(即登录到Live,MSA等),则可以绕过此令牌并从Microsoft Graph请求关于该用户的信息。
在C#中,它看起来像这样:
// auth token from cortana's connected service stored as Entity object of type 'authorization' with child property 'token' holding the actual value
var token = activity.Entities.Single(e => e.Type == @"authorization").Properties.Value<string>(@"token");
using (var client = new HttpClient())
{
// The token can be used to query the Graph, but only because we know that it is from MS Identity. We couldn't query the Graph like this if we were using our own Identity provider (eg: Contoso Identity)
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(@"Bearer", token);
try
{
var response = await client.GetAsync(@"https://graph.microsoft.com/v1.0/me").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
var resultString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
/* Response from /me looks like:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
"givenName": "Brandon",
"surname": "H",
"displayName": "Brandon H",
"id": "<unique user id!>",
"userPrincipalName": "<E-MAIL ADDRESS!!>",
"businessPhones": [],
"jobTitle": null,
"mail": null,
"mobilePhone": null,
"officeLocation": null,
"preferredLanguage": null
}
*/
}
}
catch { }
}
希望帮助!如果你想玩你从图表的各个租户得到的回报,Graph Explorer是一个很好的方法来做到这一点。
关于node.js的例子,你能澄清一下在这个例子中过时了吗? –
您是否与Azure AD一起工作?尼斯。我似乎无法找到正确的东西来填充连接服务屏幕的正确框中 - 任何机会,你可以张贴blured截图或类似的东西,从Azure AD应用程序注册的哪些设置去了Cortana Connected服务屏幕? –