2017-02-08 12 views
1

これは情報がない理由はおそらく明らかであるはずですが、それにもかかわらず苦労しています。私はここにブレークポイントを追加し、トークンを表示することができますDelegated Adalトークンにアクセスして使用する方法

private async Task OnAuthorizationCodeReceivedAAD(AuthorizationCodeReceivedNotification notification) 
     { 
      var code = notification.Code; 

      var credential = new ClientCredential(appId, appSecret); 
      var userObjectId = notification.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; 
      var context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext("https://login.microsoftonline.com/tenant.onmicrosoft.com/"); 

      var uri = new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)); 

      var result = await context.AcquireTokenByAuthorizationCodeAsync(code, uri, credential); 
     } 

:私はIsuccessfullyトークンを取得StartUp.Auth.csでADALを使用して、私のAAD-テナントにサインインした後

。私の質問は、他のクラスのコードからこのトークンにアクセスするにはどうすればいいですか?たとえば、APIを呼び出すことができます。トークンを委任する必要があるので、クライアント証明書は機能しません。これは私がドキュメントを見つけることができるすべてです。

答えて

2

AuthenticationContextクラスは、トークンを使用してトークンを取得すると、トークンをデフォルトでキャッシュに保存します。

次に、AcquireTokenSilentAsyncを使用して、リソースとユーザーに基づいてキャッシュからトークンを取得できます。このメソッドは、キャッシュからトークンを取得し、必要に応じてトークンを更新します。参照先の例は次のとおりです。

AuthenticationContext authContext = new AuthenticationContext(authority); 
ClientCredential credential = new ClientCredential(clientId, secret); 
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; 
AuthenticationResult result = await authContext.AcquireTokenSilentAsync(resource,credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId)); 
関連する問題