Here's how I decided to include this in my service connections.
First, I tweaked my template to search out one of these files in my paclet or the "ApplicationData"
subdir of $UserBaseDirectory
:
$$serviceconnectionclientsecretsjsonfile=
If[StringQ@#,
FileNameJoin@{
#,
"client_secrets.json"
},
None
]&@
SelectFirst[
{
ParentDirectory@DirectoryName@$InputFileName,
FileNameJoin@{
$UserBaseDirectory,
"ApplicationData",
"ServiceConnections",
"$ServiceConnection"
}
},
FileExistsQ@
FileNameJoin@{
#,
"client_secrets.json"
}&
]
Then I download my client_secrets.json and save it to "$UserBaseDirectory/ApplicationData/ServiceConnections/GoogleDrive/client_secrets.json"
Finally I take my standard service connection template and pass this as the client config:
$clientInfo["OAuth"] =
{
"Client" -> "OAuth",
"ClientID" :> googledrivegetclientdata["ClientID"],
"ClientSecret" :> googledrivegetclientdata["ClientSecret"],
"AuthorizeEndpoint" :>
googledrivegetclientdata[
"AuthURI",
"https://accounts.google.com/o/oauth2/v2/auth"
],
"AccessEndpoint" :>
googledrivegetclientdata[
"TokenURI",
"https://www.googleapis.com/oauth2/v4/token"
],
"RedirectURI" :>
googledrivegetclientdata[
"RedirectURIs",
{Key["access_code"]},
First
],
"AuthorizationScope" :>
googledrivegetclientdata[
"AuthScope",
"https://www.googleapis.com/auth/drive"
],
"AuthorizationResponseType" -> "code",
"Fetch" -> GDRawImport,
"Information" -> $serviceDescription
};
The only interesting thing there is the googledrivegetclientdata
calls. Basically at load time I import from "client_secrets.json"
and then pass those to Mathematica's OAuth flow.
This then works fine. Obviously I can't provide my "client_secrets.json"
in my paclet, but you can install the paclet like so:
PacletInstall[
"ServiceConnection_GoogleDrive",
"Site"->"http://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"
]
And put your own "client_secrets.json"
at ""$UserBaseDirectory/ApplicationData/ServiceConnections/GoogleDrive/client_secrets.json"
And assuming I didn't mess anything up it should work on your machine too.
That paclet itself is a little glitchy and I don't have time now to expand or patch it, but if you look at its innards it should be clear enough what's happening.