I am playing around with the Appid implementation using the NodeJs SDK and I am currently trying to fetch ApplicationIdentityToken
via the TokenManager
. And below is my code snippet.
The tokenManager.getApplicationIdentityToken()
gives you a valid token, but the problem I am facing is that whenever I pass this token to the userProfileManager.getUserInfo(token)
it gives me a UnauthorizedException
.
I have stripped down the entire code and created a small function just to test the fetching of token and verifying it with the userProfileManager.getUserInfo
function.
Note: Please ignore the antipattern it is just for providing the code snippet.
const userProfileManager = require('ibmcloud-appid').UserProfileManager;
userProfileManager.init({
oauthServerUrl: process.env.APPID_URL,
profilesUrl: process.env.APPID_PROFILES_URL,
});
const config = {
tenantId: process.env.TENANT_ID,
clientId: process.env.CLIENT_ID,
secret: process.env.CLIENT_SECRET,
oauthServerUrl: process.env.APPID_URL,
profilesUrl: process.env.APPID_PROFILES_URL,
};
let token = '';
const { TokenManager } = require('ibmcloud-appid');
const tokenManager = new TokenManager(config);
const getAppIdentityToken = async () => {
tokenManager
.getApplicationIdentityToken()
.then((appIdAuthContext) => {
console.log(` Access tokens from SDK : ${JSON.stringify(appIdAuthContext)}`);
token = appIdAuthContext.accessToken;
})
.then(async () => {
const data = await userProfileManager.getUserInfo(token);
console.log(data);
})
.catch((err) => {
console.error(err);
});
};
exports.getAppIdentityToken = getAppIdentityToken;