2017-10-24 1 views
2

Ich habe meine Anwendung bei der Azure AD App-Registrierung registriert.AcquireToken async Rückgabe des gleichen Tokens vor Ablauf der Zeit

In meinem Szenario verwende ich Azure Adal AquireTokenAsync-Methode mit Client-Anmeldeinformationen, die immer das gleiche Token zurückgibt.

Ich brauche ein neues Token für jede Benutzersitzung.

zu Testzwecken habe ich eine Konsolenanwendung erstellt, um das Verhalten zu testen.

string authority = String.Format(CultureInfo.InvariantCulture, 
     ConfigurationManager.AppSettings["ida:AADInstance"], 
     ConfigurationManager.AppSettings["ida:Tenant"]); 

     AuthenticationContext authContext = new AuthenticationContext(authority, false); 
     ClientCredential clientCredential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientId"], ConfigurationManager.AppSettings["ida:AppKey"]); 
     AuthenticationResult result = null; 
     int retryCount = 0; 
     bool retry = false; 
     retry = false; 
     try 
     { 
      result = await authContext.AcquireTokenAsync(ConfigurationManager.AppSettings["ida:ResourceId"], clientCredential); 
      result = await authContext.AcquireTokenAsync(ConfigurationManager.AppSettings["ida:ResourceId"], clientCredential); 
     } 
     catch (AdalException ex) 
     { 

     } 
     finally 
     { 
      authContext = null; 
     } 

In beiden Aufrufen gibt es das gleiche Token zurück.

jedoch für jede neue Ausführung gibt es neue Token zurück.

Antwort

0

ADAL Kontext Cache halten token.If Sie es brauchen, um aktualisiert bitte löschen Sie den Cache mit

authContext.TokenCache.Clear(); 

wird es den Cache löschen.

1

Es ist, weil AuthenticationContextTokenCacheid_token Cache ist. Also, wenn Sie möchten, dass neue Token ruft jedes Mal AcquireTokenAsync haben, setzen TokenCache null ist, wenn AuthenticationContext Objekt erstellt:

AuthenticationContext authContext = new AuthenticationContext(authority, false, null); 

Bitte bevorzugen the link

Verwandte Themen