Issue
I cannot get Dropbox's /oauth2/token to work within Microsoft Access VBA.
Downloading dropbox files is easily done using the following code in a vba sub.
Dim xmlhttp As Object
Dim myurl As String
Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
myurl = ";
Dim argumentString As String
argumentString = "{" & Chr(34) & "path" & Chr(34) & ":" & Chr(34) & "/testfile.txt" & Chr(34) & "}"
'argumentString will form like {"path":"/testfile.txt"}
xmlhttp.Open "POST", myurl, False
xmlhttp.SetRequestHeader "Authorization", "Bearer TemporaryGeneratedAccessToken"
xmlhttp.SetRequestHeader "Dropbox-API-Arg", argumentString
xmlhttp.send
MsgBox (xmlhttp.ResponseText)
If xmlhttp.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write xmlhttp.responseBody
oStream.SaveToFile MyPCPathToWriteTo, 2
oStream.Close
End If
This uses a temporary generated access token, which I manually generated from the developer back-end of my API. It works; however, these access tokens are very temporary and cannot be used in the application. So, I'm trying to implement Dopbox's OAuth, especially the OAuth 2.0 with offline access.
The process of implementing this is comprehensively listed here. I've walked through the following steps
- Created a DropBox API with the necessary permissions
- Used
;response_type=code&token_access_type=offline
to generate an authorization code for my application. This is done
The next step would be to use this authorization code in vba to generate an access code and a short-lived access token. The access code can be used to connect to Dropbox and the short-lived access token can be used to generate a new access code. I cannot get this to work.
Examples of code that I have tried.
Dim xmlhttp As Object
Dim myurl As String
Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
myurl = ";
'myurl = ";
xmlhttp.Open "POST", myurl, False
xmlhttp.SetRequestHeader "code", "MY AUTHORIZATION CODE"
xmlhttp.SetRequestHeader "grant_type", "authorization_code"
xmlhttp.SetRequestHeader "client_id", "MyAppKey"
xmlhttp.SetRequestHeader "client_secret", "MySECRETAppKey"
xmlhttp.send argumentString
MsgBox (xmlhttp.ResponseText)
In the linked example above, I also found that other programming languages first encoded the key and secret key, so I've also tried doing that following this method here.
Dim xmlhttp As Object
Dim myurl As String
Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
myurl = ";
Dim argumentString As String
xmlhttp.Open "POST", myurl, False
xmlhttp.SetRequestHeader "code", "MyAuthorizationCode"
xmlhttp.SetRequestHeader "grant_type", "authorization_code"
Dim ClientID As String
Dim ClientSec As String
ClientID = EncodeBase64(StrConv("AppID", vbFromUnicode))
ClientSec = EncodeBase64(StrConv("AppSecretID", vbFromUnicode))
xmlhttp.SetRequestHeader "client_id", ClientID
xmlhttp.SetRequestHeader "client_secret", ClientSec
xmlhttp.send argumentString
MsgBox (xmlhttp.ResponseText)
Both these examples give the same error code: "Invalid_request. The Request parameters do not match any of the supported authorization flows. Please refer to the API documentation for the correct parameters." I've been fiddling around using the argumentString to also supply the parameters but I'm always getting the same message.
Does someone have a clue what I am missing or doing wrong?
Problem background
I'm working on an access application that sometimes needs to update the front-end on different PCs. This updating is already automated and each instance of the access application can ask for updates. This was done by uploading new versions to OneDrive and generating direct download links. However, these links have suddenly been removed, possibly through updates in their API. It seems like Microsoft has adjusted how these URLs are generated and thus opening everything in a web-browser instead of a direct download. Here you can view a work-around which won't work anymore, and more users reporting this issue. Instead, I've tried to work with dropbox API to generate (in a more secure way) direct download links. Those work, but I need to generate codes to get to the dropbox files.