Open kafisatz opened 1 year ago
I'm having the same problem. Other than @kafisatz I'm actually able to retrieve a valid token without Python via AzSessions.jl
using AzSessions
cid="foo"
cse="bar"
tenant="baz"
session = AzSession(;protocol=AzClientCredentials, client_id=cid, client_secret=cse)
t = token(session)
Concerning this issue:
There seems to be no obvious way to set the correct pre connection attribute. I gues this would need extension of src/API.jl or maybe we can use SQLSetEnvAttr directly somehwere?
Maybe @quinnj can chime in and point us towards the solution? I have a feeling it's not to big of a change but I'm honestly a little bit overwhelmed by the complexity of these whole DB driver things.
According to the MS docs, in C++ it can be done like this:
SQLCHAR connString[] = "Driver={ODBC Driver 18 for SQL Server};Server={server};Encrypt=yes;"
SQLCHAR accessToken[] = "eyJ0eXAiOi..."; // In the format extracted from an OAuth JSON response
...
DWORD dataSize = 2 * strlen(accessToken);
ACCESSTOKEN *pAccToken = malloc(sizeof(ACCESSTOKEN) + dataSize);
pAccToken->dataSize = dataSize;
// Expand access token with padding bytes
for(int i = 0, j = 0; i < dataSize; i += 2, j++) {
pAccToken->data[i] = accessToken[j];
pAccToken->data[i+1] = 0;
}
...
SQLSetConnectAttr(hDbc, SQL_COPT_SS_ACCESS_TOKEN, (SQLPOINTER)pAccToken, SQL_IS_POINTER);
SQLDriverConnect(hDbc, NULL, connString, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
...
free(pAccToken);
Would it be possible to support a token_struct (SQL_COPT_SS_ACCESS_TOKEN) for Azure authentication? See the snippet below
I note that I am happy to use PyCall to get the value of the token. (I am aware of Azure.jl, but the below functionality is probably not in there yet)
My question for the ODBC.jl developers is only whether ODBC.Connection could support a token similar to the python snippet below. I tried using "Authentication=ActiveDirectoryIntegrated", but this does not work for me. "ActiveDirectoryInteractive" works, but it is cumbersome to enter the pw every time in the age of SSO.
python snippet using a token