public async Task <IBookFastFilesAPI> CreateApiClientAsync(Uri baseUri) { var accessToken = await accessTokenProvider.AcquireTokenAsync(apiOptions.ServiceApiResource); var credentials = string.IsNullOrEmpty(accessToken) ? (ServiceClientCredentials) new EmptyCredentials() : new TokenCredentials(accessToken); return(new BookFastFilesAPI(baseUri, credentials)); }
protected override Task <CommunicationClient <IBookFastFilesAPI> > CreateClientAsync(string endpoint, CancellationToken cancellationToken) { // clients that maintain persistent connections to a service should // create that connection here. // an HTTP client doesn't maintain a persistent connection. var client = new CommunicationClient <IBookFastFilesAPI>(async() => { var accessToken = await accessTokenProvider.AcquireTokenAsync(apiOptions.ServiceApiResource); var credentials = string.IsNullOrEmpty(accessToken) ? (ServiceClientCredentials) new EmptyCredentials() : new TokenCredentials(accessToken); return(new BookFastFilesAPI(new Uri(endpoint), credentials)); }); return(Task.FromResult(client)); }