Skip to main content

Step 2:AuthToken

This is for system's that use auto Login functionality. The request for this need to originate from within the SuperApp as it requires the access_token which is generated from with the SuperApp via function call from the H5. For more information check the demo provided

  • API\service\applyFabricTokenService.js

Create auth token service

Create a file at API\service\authTokenService.js:

API\service\authTokenService.js
const applyFabricToken = require("./applyFabricTokenService");
const tools = require("../utils/tools");
const config = require("../config/config");
const https = require("http");

exports.authToken = async (req, res) => {
let appToken = req.body.authToken;
console.log("token = ", appToken);
let applyFabricTokenResult = await applyFabricToken();
console.log("applyFabricTokenResult", applyFabricTokenResult);
let fabricToken = applyFabricTokenResult.token;
let result = await exports.requestAuthToken(fabricToken, appToken);
res.send(result);
};

exports.requestAuthToken = async (fabricToken, appToken) => {
return new Promise((resolve) => {
let reqObject = createRequestObject(appToken);
var options = {
method: "POST",
url: config.baseUrl + "/payment/v1/auth/authToken",
headers: {
"Content-Type": "application/json",
"X-APP-Key": config.fabricAppId,
Authorization: fabricToken,
},
rejectUnauthorized: false, //add when working with https sites
requestCert: false, //add when working with https sites
agent: false, //add when working with https sites
body: JSON.stringify(reqObject),
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
let result = JSON.parse(response.body);
console.log(result);
resolve(result);
});
});
};

function createRequestObject(appToken) {
let req = {
timestamp: tools.createTimeStamp(),
nonce_str: tools.createNonceStr(),
method: "payment.authtoken",
version: "1.0",
};
let biz = {
access_token: appToken,
trade_type: "InApp",
appid: config.merchantAppId,
resource_type: "OpenId",
};
req.biz_content = biz;
req.sign = tools.signRequestObject(req);
req.sign_type = "SHA256WithRSA";
console.log(req);
return req;
}

// module.exports = authToken;

Request Parameters

HEADER PARAMETERS

ParameterData TypeM/ODescription
X-APP-KeyStringMFabric App ID, provided by fabric portal of Ethio telecom
AuthorizationStringMApp Token for authentication

REQUEST BODY SCHEMA

ParameterData TypeM/ODescription
timestampstringM<= 13 characters ^[0-9][1-9][0-9]$
Time when a request is sent. UTC timestamp. The unit is second.
methodstringM
Value: "payment.applyh5token"
nonce_strstringM<= 32 characters \S+
Random character string containing a maximum of 32 characters, including uppercase letters, lowercase letters, digits, but not special characters.
sign_typestringMValue = "SHA256WithRSA"
Signature type.
signStringM<= 512 characters \S+
This signature is the sign of all the request parameters except the sign and sign_type. First ordered in alphabetical order and joined in a key=value format and joined together with '&' and are signed with the SHA256RSA algorithm.
versionStringM<= 4 characters \S+
Interface version number. Only support 1.0 now
biz_contentobject 
object (CreateOrderBizContent)
appidStringM<= 32 characters ^[A-Za-z0-9]+$
Application ID allocated to a merchant by Mobile Payment system. Is also known as Merchant app id.
access_tokenStringMA token that allow the merchant to access the user information. This is provided from the interface of the superApp.
string <= 256 characters [\w-:]+
trade_typeStringM
Value: "InApp"
resource_typeStringMValue: "OpenId"

Response Parameters

ParameterData TypeDescription
resultStringSUCCESS or FAIL. When this field is FAIL, the code field is a specific business error code.
codeStringReturn code. 0 is successful, the rest is the business error code
msgStringReturn information, simple error description.
signstring <= 512 characters
stringResponse signature.
nonce_strstring
sign_typestringSignature type. Currently, only SHA256RSA is supported.
biz_contentobject (AuthToken
ResponseBizContent)
open_idstring
identityIdstringConsumer id in mobile payment system
identityTypestringOrganization or Customer
walletIdentityIdstringWallet identity id
identifierstringmsisdn or shortcode. Only authorized partner will get this param returned
nickNamestringnickName is the first name of the user.
Only authorized partner will get this param returned
statusstringstatus. Only authorized partner will get this param returned
shortcodestringshortCode. Only authorized partner will get this param returned
walletOrgOperatorstringwalletOrgOperatorIdentityId. Only authorized partner will get this param returned
IdentityId