Single-page application: Call a web API
We recommend that you call the acquireTokenSilent
method to acquire or renew an access token before calling a web API. After you have a token, you can call a protected web API.
Call a web API
Use the acquired access token as a bearer in an HTTP request to call any web API, such as Microsoft Graph API. For example:
var headers = new Headers();
var bearer = "Bearer " + access_token;
headers.append("Authorization", bearer);
var options = {
method: "GET",
headers: headers
};
var graphEndpoint = "https://microsoftgraph.chinacloudapi.cn/v1.0/me";
fetch(graphEndpoint, options)
.then(function (response) {
//do something with response
})
Next steps
Learn more by building a React Single-page application (SPA) that signs in users in the following multi-part tutorial series.
Explore Microsoft identity platform single-page application code samples