public async Task <IAdalResult> AcquireTokenAsync( string authorityHostUrl, string resource, string clientId) { if (authorityHostUrl is null) { throw new ArgumentNullException(nameof(authorityHostUrl)); } if (resource is null) { throw new ArgumentNullException(nameof(resource)); } if (clientId is null) { throw new ArgumentNullException(nameof(clientId)); } try { var authenticationContext = new ActiveDirectory.AuthenticationContext(authorityHostUrl, _cache); var userCredential = new ActiveDirectory.UserCredential(); ActiveDirectory.AuthenticationResult result = await AdalExtentions.AcquireTokenAsync(authenticationContext, resource, clientId, userCredential); return(new Result(result)); } catch (ActiveDirectory.AdalException exception) { throw new AuthenticationException(exception); } }
public async Task <IAdalResult> AcquireTokenAsync( string authorityHostUrl, string resource, string clientId) { if (authorityHostUrl is null) { throw new ArgumentNullException(nameof(authorityHostUrl)); } if (resource is null) { throw new ArgumentNullException(nameof(resource)); } if (clientId is null) { throw new ArgumentNullException(nameof(clientId)); } try { var authenticationContext = new ActiveDirectory.AuthenticationContext(authorityHostUrl, _cache); var userCredential = new ActiveDirectory.UserCredential(); ActiveDirectory.AuthenticationResult result = await AdalExtentions.AcquireTokenAsync(authenticationContext, resource, clientId, userCredential); return(new Result(result)); } // We should just be able to catch AdalException here but due to an ADAL bug an HttpRequestException can be leaked: // https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/1285 // Until we update to ADAL 4.x or MSAL, we should just workaround this problem. catch (Exception exception) { throw new AuthenticationException(exception); } }