Google Drive API. How do I configure the OAuth2Authenticator object to work through a proxy?
I have a desktop application in .net for uploading files to google drive. The program works correctly, but if a proxy server is installed on the PC, the program will not be able to execute method Upload()
{ FilesResource.InsertMediaUpload.Upload()
}. Error message:
DotNetOpenAuth.Messaging.ProtocolException: {"Web request for" https://accounts.google.com/o/oauth2/token "failed." }
Remote Server Error: (407) Proxy Authentication Required.
I think the problem is with the authentication request; so you need to configure the OAuth2Authenticator object to use a proxy.
This is the code:
Public Function getAuthenticator() As OAuth2Authenticator(Of AssertionFlowClient)
Dim SERVICE_ACCOUNT_EMAIL As String = <email>
Dim SERVICE_ACCOUNT_PKCS12_FILE_PATH As String = <pathFile>
Dim certificate As X509Certificate2 = New X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, <secret>, 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
Thank.
+3
source to share
No one has answered this question yet
Check out similar questions: