BCA API - OAuth & Signature - V0.1.4
BCA API - OAuth & Signature - V0.1.4
1
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
Strictly Confidential
Document Version
Doc
Date Description PIC
Version
25 January 2018 0.1.4 - Update HMAC-SHA256 Result for Scenario 4 on Page 10 BIL
28 September
0.1.3 - Move port 443 to description column BIL
2017
19 September
0.1.2 - Update port for endpoint UAT to 443 BIL
2017
09 August 2017 0.1.1 - Update port for endpoint production to 443 ABE
20 April 2017 0.1.0 - Create this document as separate file from API Service ABE
Tech. Doc.
- Add notes for HexEncode usage (page 6)
- Add notes about how to handle comma characters
when creating signature (page 7)
- Add section “Signature How To” (page 10)
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
2
Strictly Confidential
Contents
Introduction .................................................................................................................................................. 4
Authorization ................................................................................................................................................ 4
Access Token Request ........................................................................................................................... 4
Headers ......................................................................................................................................................... 5
Signature ....................................................................................................................................................... 6
Generate Signature ............................................................................................................................... 6
Signature How to ........................................................................................................................................ 10
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
3
Strictly Confidential
Introduction
Overview of BCA Corporate Banking API:
URL Usage
Authorization
The BCA Corporate Banking API is using OAuth 2 as the authorization framework. To access all
the services you’ll need the access token with grant_type=client_credentials. To get the access
token, you need to be authorized by client_id and client_secret. To learn more about the
OAuth 2 authorization framework you can read the rfc6749 documentation
(https://tools.ietf.org/html/rfc6749).
Access Token Request
POST /api/oauth/token HTTP/1.1
Host: server.example.com
Authorization: Basic Base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
Sample Request:
curl https://api.klikbca.com/api/oauth/token \
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
4
Strictly Confidential
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic
jk5ZTkyYzgtYzAzNC00YmNhLWE0OTAtYWM4NGI0YTZiMjQxOjNmYWIwNGI1LWM4ODctNGZmM
i05OGNkLTE1YjJmYTcyNzA1NA==" \
-d "grant_type=client_credentials"
Sample Response:
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"bearer",
"expires_in":3600,
"scope":"resource.WRITE resource.READ"
}
Headers
To successfully communicate with BCA Banking API, you must provide the following headers in
every API request :
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
5
Strictly Confidential
Signature
Signature is used by BCA to verify that your request is not altered by attackers.
The outline of the HMAC validation process is as follows:
1. Retrieve Timestamp from HTTP Header (X-BCA-Timestamp)
2. Retrieve the API Key form HTTP Header (X-BCA-Key)
3. Lookup the API Secret corresponding to the received key in internal store
4. Retrieve client HMAC from HTTP Header lowercase hexadecimal format (X-BCA-Signature)
5. Calculate HMAC using the API Secret as the HMAC secret key
6. Compare client HMAC with calculated HMAC
If HMAC hash comparison is invalid API Gateway will return a HTTP 400 error code together
with the following error message on JSON format:
{
"ErrorCode" : "...",
"ErrorMessage" : {
"Indonesian": "HMAC tidak cocok",
"English": "HMAC mismatch"
}
}
If the HMAC calculation is successful and the calculated value matches the value received from
the client, the signature is considered valid.
Generate Signature
SHA-256 HMAC is used to generate the signature with your API secret as the key.
The StringToSign will be a colon-separated list derived from some request data as below :
StringToSign = HTTPMethod+":"+RelativeUrl+":"+AccessToken+":"+
Lowercase(HexEncode(SHA-256(RequestBody)))+":"+Timestamp
HexEncode are optional to use, use it if the SHA-256 returns a binary stream.
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
6
Strictly Confidential
Details about the data used to derived The StringToSign is explained in the next sections.
HTTP Method
HTTP Method is HTTP Method such as GET, POST, PUT, PATCH, DELETE.
HTTP method must be given in upper case.
Relative URL
Relative URL is the URL after the hostname & port number.
Relative URL also includes the query string and must begin with a slash character.
Example :
https://example.com/api/v2/sample?param1=value1 /api/v2/sample?param1=value1&par
¶m2=value2 am2=value2
https://example.com /
or https://example.com/
4. Percent-encode all other characters not meeting the above conditions using the format:
%XY, where X and Y are hexadecimal characters (0-9 and uppercase A-F).
For example, the space character must be encoded as %20 (not using '+', as some
encoding schemes do) and extended UTF-8 characters must be in the form %XY%ZA%BC.
The query string parameters must be re-ordered according to the following rules:
1. Sorted by parameter name lexicographically
2. If there are two or more parameters with the same name, sort them by parameter values.
Example :
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
7
Strictly Confidential
/api/v2/sample?A-param=value1&Z- /api/v2/sample?A-param=value1&B-
param=value2&B-param=value3 param=value3&Z-param=value2
AccessToken
AccessToken is an OAuth 2 access token retrieved from the HTTP “Authorization” header.
RequestBody
RequestBody need to be hashed with SHA-256.
If the RequestBody is empty, set it to empty string.
RequestBody should be canonicalized before computing the SHA-256 hash.
The canonicalization of the request body is performed according to the following rules:
1. All carriage return characters, “\r”, are stripped
2. All line feed characters, “\n”, are stripped
3. All tab characters, “\t”, are stripped
4. All whitespace characters, “ ”, are stripped
An example request JSON body like below:
{
"Test1": "strVal",
"Test2": 1
}
{"Test1":"strVal","Test2":1}
Timestamp
The timestamp must be presented in ISO8601 format (YYYY-MM-DDThh:mm:ss.sssTZD)
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
8
Strictly Confidential
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
9
Signature How to
Scenario 1 Scenario 2 Scenario 3 Scenario 4
No. Parameter
(Simple request) (Path param value contains comma ",") (JSON body request with white space) (Multiple query param)
10
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
Strictly Confidential
Examine Header
Authorization Bearer G Bearer G Bearer G Bearer G
X-BCA-Key E E E E
Q
X-BCA-Signature O O O O
X-BCA-Timestamp H H H H
Examine Body Body empty empty { empty
"CorporateID" : "H2HAUTO009",
"SourceAccountNumber" : "0611104625",
"TransactionID" : "00177914",
"TransactionDate" : "2017-03-17",
"ReferenceID" : "1234567890098765",
"CurrencyCode" : "IDR",
"Amount" : "175000000",
R "BeneficiaryAccountNumber" : "0613106704",
"Remark1" : "Pencairan Kredit",
"Remark2" : "1234567890098765"
}
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.
11
12
Tech. Doc. BCA API OAuth & Signature v0.1.4| PT. Bank Central Asia, Tbk.