DataFlex
DataFlex
Explicitly set the OAuth2 Access Token
This example shows how to set the AuthToken property using a previously obtained access token.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoJson
Handle hoHttp
String sTemp1
Move False To iSuccess
// Assume we previously obtained JSON containing the access token such as this:
// {
// "access_token": "ya39.Ci-XA_C5bGgRDC3UaD-h0_NeL-DVIQnI2gHtBBBHkZzrwlARkwX6R3O0PCDEzRlfaQ",
// "token_type": "Bearer",
// "expires_in": 3600,
// "refresh_token": "1/r_2c_7jddspcdfesrrfKqfXtqo08D6Q-gUU0DsdfVMsx0c"
// }
//
// Load the JSON and use the access_token to authenticate an HTTP request.
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComLoadFile Of hoJson "c:/someDir/tokens/myToken.json" To iSuccess
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// After setting this property, all HTTP requests sent using this object instance
// will include the request header: Authorization: Bearer <access_token>
Get ComStringOf Of hoJson "access_token" To sTemp1
Set ComAuthToken Of hoHttp To sTemp1
// ...
// ..
End_Procedure