title: Google Drive API .NET. How to configure the OAuth2Authenticator object to work through a proxy?
body: <p>I have a desktop application in .net to upload files to Google Drive. The program run correctly, but if the PC have a proxy configurated the program fails to execute the method <code>Upload()</code> {<code>FilesResource.InsertMediaUpload.Upload()</code>}. The message error is: </p>
  
  <blockquote>
    <p>DotNetOpenAuth.Messaging.ProtocolException: {"Web request to 'https://accounts.google.com/o/oauth2/token' failed."}</p>
    
    <p>Remote server error: (407) Proxy Authentication Required.</p>
  </blockquote>
  
  <p>I think that the problem is in the request to authenticate; so that is necessary configure the OAuth2Authenticator object to use a proxy.</p>
  
  <p>This is the code:</p>
  
  <pre><code>Public Function getAuthenticator() As OAuth2Authenticator(Of AssertionFlowClient)
        Dim SERVICE_ACCOUNT_EMAIL As String = &lt;email&gt;
        Dim SERVICE_ACCOUNT_PKCS12_FILE_PATH As String = &lt;pathFile&gt;
        Dim certificate As X509Certificate2 = New X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, &lt;secret&gt;, X509KeyStorageFlags.Exportable)
        Dim provider = New AssertionFlowClient(GoogleAuthenticationServer.Description, certificate) With {.ServiceAccountId = SERVICE_ACCOUNT_EMAIL, .Scope = DriveService.Scopes.Drive.GetStringValue}
        Dim auth = New OAuth2Authenticator(Of AssertionFlowClient)(provider, AddressOf AssertionFlowClient.GetState)
  
        Return auth
  End Function
  
  Public Function getService() As DriveService
      Return New DriveService(getAuthenticator())
  End Function
  
  Public Function upload(pathFile As String, fileName As String) As File
      Dim service = getService(False)
      Dim fichero As File = New File()
      Dim byteArray As Byte() = System.IO.File.ReadAllBytes(pathFile)
      Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream(byteArray)
  
      fichero.Title = fileName
      Dim request As FilesResource.InsertMediaUpload = service.Files.Insert(fichero, stream, "*/*")
  
      request.Upload()   'ERROR with proxy
  
      Dim fileUpload As File = request.ResponseBody
  
      Return fileUpload
  End Function
  </code></pre>
  
  <p>Thanks. </p>