/// <summary>
 /// Add the Basic Authentication Header to each outgoing request
 /// </summary>
 /// <param name="request">The outgoing request</param>
 /// <param name="cancellationToken">A token to cancel the operation</param>
 /// <returns></returns>
 public override Task ProcessHttpRequestAsync(HttpRequestMessage request,
                                              CancellationToken cancellationToken)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     // Add username and password to "Basic" header of each request.
     request.Headers.Authorization = new AuthenticationHeaderValue("Basic",
                                                                   Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format(
                                                                                                                     CultureInfo.InvariantCulture,
                                                                                                                     "{0}:{1}",
                                                                                                                     UserName,
                                                                                                                     Password).ToCharArray())));
     return(PlatformTask.FromResult(null));
 }
Esempio n. 2
0
 /// <summary>
 /// Apply the credentials to the HTTP request.
 /// </summary>
 /// <param name="request">The HTTP request message.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <returns>
 /// Task that will complete when processing has finished.
 /// </returns>
 public virtual Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     // Return an empty task by default
     return(PlatformTask.FromResult(null));
 }
Esempio n. 3
0
 /// <summary>
 /// Returns the static access token.
 /// </summary>
 /// <param name="cancellationToken">The cancellation token for this action.
 /// This will not be used since the returned token is static.</param>
 /// <returns>The access token.</returns>
 public Task <AuthenticationHeaderValue> GetAuthenticationHeaderAsync(CancellationToken cancellationToken)
 {
     return(PlatformTask.FromResult(new AuthenticationHeaderValue(_type, _accessToken)));
 }