雖然我沒有關於如何使用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服務屏幕? –