@Pramod Valavala Thanks for replying. To be honest, it's quite confusing reading the docs for MSAL. I tried using below code. but no luck with error message: Uncaught (in promise) ClientAuthError: User login is required.
function getStsToken() {
let config = {
auth: {
clientId: "67568467-a9c0-4249-8854-2***********3",
authority: "https://login.microsoftonline.com/4************-a9d7-433d-ab8f-cbc6d3a41ee4/"
},
cache: {
cacheLocation: "sessionStorage"
}
};
let graphConfig = {
graphEndPoint: "https://graph.microsoft.com/v1.0/me"
};
let requestPermissionScope = {
scopes: ["api://67568467-a9c0-4249-8854-2**************3/***********_APIM"]
};
const myMSALObj = new Msal.UserAgentApplication(config);
myMSALObj.acquireTokenSilent(requestPermissionScope).then(function(result) {
if (result != undefined) {
var headers = new Headers();
var bearer = "Bearer " + result.accessToken;
headers.append("Authorization", bearer);
var options = {
method: "GET",
headers: headers
};
fetch(graphConfig.graphEndPoint, options)
.then(function(response) {
//do something with response
if (response.status == 200) {
var data = response.json();
data.then(function(userinfo) {
var printResponse = JSON.stringify(userinfo)
//Print the JSON string
console.log(printResponse)
})
}
});
}
}).catch(
e => { console.log(e) }
);
}