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;
I believe there is some confusion.
AppID is an IBM Cloud service and you can manage the service as a user of IBM Cloud. This requires that you are logged in or have an API key or access token.
Then, AppID is able to manage users and access. For that, there are self-service actions as well as access token for working with an app or other resources.
It seems to me that you generated a token for 2), but performing the user profile access which requires an IAM token.