lib/util/token-util.js
function getOAuthAccessToken(appId,clientId,imfCert,properties) {
	var deferred = Q.defer();

	var imfServiceUrl = process.env.imfServiceUrl;
	var requestUrl = imfServiceUrl+"/authorization/v1/apps/"+appId+"/token";

	var requestOptions = {url: requestUrl,headers: {'Authorization': 'IMFCert '+imfCert}, form:{'grant_type':'client_credentials','client_id':clientId,'properties':properties}};
	request.post(requestOptions, function(error,response,body){
		if (error || response.statusCode != 200) {
			requestUrl = requestUrl ? requestUrl : "";
			body = body ? body : "";
			var errMsg = error?"["+error+"]":"["+response.statusCode+":"+body+"] Generate IMF Token from '"+requestUrl+"' failed.";

			ibmlogger.getLogger().error(errMsg);
			return deferred.reject({code:Constant.TOKEN_GENERATE_ERROR,message:errMsg});
		}
		else {
			var tokenJson = Util.getJson(body);
			return deferred.resolve(tokenJson);
		}
	});

	return deferred.promise;
}
function getOAuthAccessToken(appId,clientId,imfCert,properties) {
	var deferred = Q.defer();

	var imfServiceUrl = process.env.imfServiceUrl;
	var requestUrl = imfServiceUrl+"/authorization/v1/apps/"+appId+"/token";

	var requestOptions = {url: requestUrl,headers: {'Authorization': 'IMFCert '+imfCert}, form:{'grant_type':'client_credentials','client_id':clientId,'properties':properties}};
	request.post(requestOptions, function(error,response,body){
		if (error || response.statusCode != 200) {
			requestUrl = requestUrl ? requestUrl : "";
			body = body ? body : "";
			var errMsg = error?"["+error+"]":"["+response.statusCode+":"+body+"] Generate IMF Token from '"+requestUrl+"' failed.";

			ibmlogger.getLogger().error(errMsg);
			return deferred.reject({code:Constant.TOKEN_GENERATE_ERROR,message:errMsg});
		}
		else {
			var tokenJson = Util.getJson(body);
			return deferred.resolve(tokenJson);
		}
	});

	return deferred.promise;
}
function getOAuthAccessToken ( appId , clientId , imfCert , properties ) { var deferred = Q . defer ( ) ; var imfServiceUrl = process . env . imfServiceUrl ; var requestUrl = imfServiceUrl + "/authorization/v1/apps/" + appId + "/token" ; var requestOptions = { url : requestUrl , headers : { 'Authorization' : 'IMFCert ' + imfCert } , form : { 'grant_type' : 'client_credentials' , 'client_id' : clientId , 'properties' : properties } } ; request . post ( requestOptions , function ( error , response , body ) { if ( error || response . statusCode != 200 ) { requestUrl = requestUrl ? requestUrl : "" ; body = body ? body : "" ; var errMsg = error ? "[" + error + "]" : "[" + response . statusCode + ":" + body + "] Generate IMF Token from '" + requestUrl + "' failed." ; ibmlogger . getLogger ( ) . error ( errMsg ) ; return deferred . reject ( { code : Constant . TOKEN_GENERATE_ERROR , message : errMsg } ) ; } else { var tokenJson = Util . getJson ( body ) ; return deferred . resolve ( tokenJson ) ; } } ) ; return deferred . promise ; }
Get the OAuth access token from IMF AZ service
@param appId
@param clientId
@param imfCert
@param properties
Get the OAuth access token from IMF AZ service