var outlookServicesClient = await AuthenticationHelper.EnsureOutlookServicesClientCreatedAsync("Calendar");
internal static async Task<OutlookServicesClient> EnsureOutlookServicesClientCreatedAsync(string capabilityName)
{
var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.Authority, new ADALTokenCache(signInUserId));
try
{
DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,
async() =>
{
var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId, new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret),
new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));
return authResult.AccessToken;
});
var dcr = await discClient.DiscoverCapabilityAsync(capabilityName);
return new OutlookServicesClient(dcr.ServiceEndpointUri,
async() =>
{
var authResult = await authContext.AcquireTokenSilentAsync(dcr.ServiceResourceId,
new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret),
new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));
return authResult.AccessToken;
});
}
catch (AdalException exception)
{
//Handle token acquisition failure
if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently)
{
authContext.TokenCache.Clear();
throw exception;
}
return null;
}
public ADALTokenCache(string user)
{
// associate the cache to the current user of the web app
User = user;
this.AfterAccess = AfterAccessNotification;
this.BeforeAccess = BeforeAccessNotification;
this.BeforeWrite = BeforeWriteNotification;
// look up the entry in the DB
Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == User);
// place the entry in memory
this.Deserialize((Cache == null) ? null : Cache.cacheBits);
}
Ich verwende diesen Code für die ADAL-Authentifizierung. Dies funktioniert auf meinem lokalen IIS-Server einwandfrei. Wenn ich das selbe auf AZURE VM gehostet habe, dann einen Fehler wieFehler bei der ADAL-Authentifizierung
"Konnte Token stillschweigend erhalten. Call-Methode AcquireToken". Kann mir jemand helfen, diesen Fehler zu beheben?
Einstellungen Hilfscode wie folgt. Im öffentlichen ADALTokenCache (string user) bekommen wir userid fein, bekommen aber einen leeren Cache ... Was wird der Grund sein ??
AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.Authority, new ADALTokenCache(signInUserId));
try
{
DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,
async() =>
{
var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId,
new ClientCredential(SettingsHelper.ClientId,
SettingsHelper.ClientSecret),
new UserIdentifier(userObjectId,
UserIdentifierType.UniqueId));
return authResult.AccessToken;
});
Ich habe unter URL geprüft, aber keine Lösung. Also können Sie irgendeine Lösung dafür vorschlagen? https: //social.msdn.microsoft.com/Forums/en-US/92438173-df6e-47ec-92f4-3cadf61b067a/azure-ad-failed-to-acquire-token- stillly? forum = WindowsAzureAD – user3463733
hast du das schon geprüft https://github.com/OfficeDev/O365-ASPNETMVC-Start/issues/28 – Aravind
Keine Lösung in diesem Link. Im lokalen Gerät funktioniert es perfekt, aber wenn ich in azurblauen VM gehostet Problem. Token ist nicht erfrischend, denke ich. – user3463733