2017-10-05 12 views
1

Azure 계정에 Node.js로 작성된 Cortana 봇을 배포했습니다. 봇은 "연결 서비스"가 켜져있는 Cortana 채널을 사용합니다 (그래서 Azure Active Directory의 계정을 사용하여 봇에 로그인 할 수 있습니다). 로그인 잘 작동합니다.MS Bot Framework에서 Azure Active Directory 사용자에 대한 데이터 가져 오기

내 문제는 이제 내 봇의 로그인 한 사용자 (예 : 이메일 주소)에 대한 정보를 얻는 방법을 모르겠다는 것입니다.

세션 데이터에서 토큰을 가져와 Azure에 사용자 데이터를 요청하는 API 요청을 보내야 할 것으로 추측하고 있습니다.

Node.js의 경우이 botauth 예제가 있지만 실행 지침이 오래되었습니다.

+0

node.js에 대한 예를 들어,이 예에서 구식 인 내용을 명확히 할 수 있습니까? –

+0

Azure AD에서이 기능을 사용할 수 있습니까? 좋은. Connected Service 화면의 오른쪽 상자에 내용을 채울 수없는 것 같습니다. Azure AD 앱 등록의 설정이 Cortana Connected의 어느 위치에 있었는지와 함께 blured 스크린 샷이나 그와 비슷한 것을 게시 할 수있는 기회입니다. 서비스 화면? –

답변

0

노드에서이 작업을 수행하는 방법에 대한 샘플이 없지만 C#의 솔루션이 도움이 될까요?

이렇게하는 방법은 Activity 개체에서 컨트롤러로 들어오는 entities 컬렉션을 검사하는 것입니다. 이 부분은 일 때마다 봇에게 요청하므로 언제든지이 작업을 수행 할 수 있습니다.

entities 컬렉션 안에는 Cortana가 authorization 항목에 연결된 서비스의 인증 흐름에서 발생한 토큰을 넣습니다. 연결된 서비스를 사용하여 Microsoft 서비스 (라이브, 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이 좋은 방법입니다.