As we know to connect to CDS WEB API from C# application we first need to acquire access token and validity of that is 1 hour. While performing small number of requests this will be sufficient. However when we want to run long running process we will get HTTP 400 error when token expires.
To overcome this issue, The recommended approach is to implement a class derived from DelegatingHandler which will be passed to the constructor of the HttpClient. This handler will allow you to override the HttpClient.SendAsync method so that ADAL will call the AcquireToken method with each request sent by the http client.
Step – 1
Create new class in your project and add below code.
/// <summary> ///Custom HTTP message handler that uses OAuth authentication through ADAL. /// </summary> class OAuthMessageHandler : DelegatingHandler { private UserCredential _credential; private AuthenticationContext _authContext = new AuthenticationContext("https://login.microsoftonline.com/common", false); private string _clientId…
View original post 394 more words