React Native
React Native
citi Developer OAuth2 Client Credentials Grant
See more OAuth2 Examples
Get access token for your application credentials. You can use this for citi APIs which do not require customer credential verification and consent (e.g. Onboarding).Chilkat React Native Downloads
import { Http, HttpRequest, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
// Implements the following CURL command:
// curl --request POST \
// --url https://sandbox.apihub.citi.com/gcb/api/clientCredentials/oauth2/token/us/gcb \
// --header 'accept: application/json' \
// --user client-id:client-secret \
// --header 'content-type: application/x-www-form-urlencoded' \
// --data 'grant_type=client_credentials&scope=%2Fapi'
http.login = 'client-id';
http.password = 'client-secret';
const req = new HttpRequest();
req.httpVerb = 'POST';
req.path = '/gcb/api/clientCredentials/oauth2/token/us/gcb';
req.contentType = 'application/x-www-form-urlencoded';
req.addParam('grant_type', 'client_credentials');
req.addParam('scope', '/api');
req.addHeader('accept', 'application/json');
const resp = new HttpResponse();
try {
await http.httpReqAsync('https://sandbox.apihub.citi.com/gcb/api/clientCredentials/oauth2/token/us/gcb', req, resp);
} catch {
console.log(http.lastErrorText);
return;
}
const sbResponseBody = new StringBuilder();
resp.getBodySb(sbResponseBody);
const jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
console.log('Response Body:');
console.log(jResp.emit());
const respStatusCode = resp.statusCode;
console.log(`Response Status Code = ${respStatusCode}`);
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(resp.header);
console.log('Failed.');
return;
}
try {
jResp.writeFile('qa_data/tokens/citi_client_credentials.json');
} catch {
console.log('Failed to save JSON access token file.');
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "token_type": "bearer",
// "access_token": "AAIkMjdh ... 3fsWb7zJ0s",
// "expires_in": 1800,
// "consented_on": 1584817860,
// "scope": "/api"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
const tokenType = jResp.stringOf('token_type');
const accessToken = jResp.stringOf('access_token');
const expiresIn = jResp.intOf('expires_in');
const consentedOn = jResp.intOf('consented_on');
const scope = jResp.stringOf('scope');
}