Access token authentication
- Last Updated: February 4, 2021
- 1 minute read
- DataDirect Connectors
- ODBC
- Microsoft SQL Server 8.0
- Documentation
The driver supports the use of a pre-connection attribute that allows authentication with an access token obtained from a third-party application. The access token authentication method is available programmatically only.
To use the pre-connection
SQL_COPT_SS_ACCESS_TOKEN attribute, set it to the ACCESSTOKEN pointer as
follows:typedef struct AccessToken
{
SQLUINTEGER size;
SQLCHAR data[];
} ACCESSTOKEN;
...The access token comprises length of the token followed by bytes of opaque
data. The token must be expanded with a
0 padding byte after
each byte of data. The token must be in LittleEndian format and must not contain any NULL
terminator. If an access token value is specified, then it will take precedence over other
available authentication methods.Note: Access tokens have a specified validity after generation. This can be configured on the
server. If connected successfully, the session is maintained. If disconnected after the
configured validity, then a new token is required to reconnect.
The following example uses the DSN-less format and includes the options for connecting with the access token flow.
#define SQL_COPT_SS_ACCESS_TOKEN 1256
...
SQLCHAR connString[]="Driver=DataDirect 8.0 SQL Server Wire Protocol;
HostName=myserver.database.windows.net;PortNumber=1234;Database=testdb";
SQLCHAR AccessToken="ey0jx12cd34efg5klm6543no32pqr10";
SQLUINTEGER dataSize=2*strlen(accessToken);
AccessToken*pAccToken=malloc(sizeof(ACCESSTOKEN)+dataSize);
pAccToken->size=dataSize;
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);