2017-03-05 17 views
0

以下のコードを淡色のアクティブディレクトリ認証に使用しました。このメソッドが存在しないことを示すauthContext.AcquireTokenByAuthorizationCodeで失敗します。私がそれを確認しようとしたとき、バージョン3.1のdllでそれを示しています。 authContext.AcquireTokenByAuthorizationCodeAsyncメソッドがあります。このコードを変更して起動時と同じように非同期にすることはできません。この問題を非同期に変換するための提案authContext.AcquireTokenByAuthorizationCodeは最新のSystem.IdentityModel.Clients.ActiveDirectoryと連携していません

public partial class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
      ConfigureAuth(app); 
     } 
    } 


public void ConfigureAuth(IAppBuilder app) 
     { 
      ApplicationDbContext db = new ApplicationDbContext(); 

      app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 

      app.UseCookieAuthentication(new CookieAuthenticationOptions()); 

      app.UseOpenIdConnectAuthentication(
       new OpenIdConnectAuthenticationOptions 
       { 
        ClientId = clientId, 
        Authority = Authority, 
        PostLogoutRedirectUri = postLogoutRedirectUri, 

        Notifications = new OpenIdConnectAuthenticationNotifications() 
        { 
         //If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away. 
         AuthorizationCodeReceived = (context) => 
         { 
          var code = context.Code; 
          ClientCredential credential = new ClientCredential(clientId, appKey); 
          string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value; 
          AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID)); 
          AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
          code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId); 

          return Task.FromResult(0); 
         } 
        } 
       }); 
     } 
+1

[ADAL .NET Ref Doc](https://docs.microsoft.com/en-us/active-directory/adal/microsoft.identitymodel.clients.activedirectory)を参考にしてください。 –

答えて

1

ADAL v2からADAL v3にはいくつかの大きな変更がありました。おそらくあなたの最も簡単な解決策は、Nuget hereからダウンロードできる古いバージョンのADALを使用することです。

そうでなければ、ADAL v3 hereに移行した既存のサンプルを見ることができます。

+0

情報ありがとうございます。私は古いバージョンを使用することができますが、私はhttps://github.com/Azure-Samples/active-directory-dotnet-graphapi-consoleのgraphapiも使用しています。これはすべての非同期メソッドで最新バージョンを使用しています。いかなる提案もお願いします。 – Kurkula

+1

私はここであなたの質問を理解しているかどうか確かではありません。 adal v3を使用するサンプルを使用している場合は、単純にサンプルコードを使用して認証してください。私はADALの異なるバージョンからコードを混ぜ合わせてマッシュしようとは勧めません。 –

+0

VS2017 Update 3がv3をサポートしていないのはなぜですか?これは、最新かつ最高のものを設定して新しいプロジェクトをしようとすると騒がしくなります。 – Matty

関連する問題