Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Using the acquired token to call a protected Web API

Santiago Gonzalez edited this page Apr 18, 2018 · 5 revisions
Using the token

Getting a token is not a goal per se. It's a necessary step to call a protected API. The token needs then to be used to access a Web API. The way to do it, is by setting the Authorization header to be "Bearer", followed by a space, followed by the access token.

Using the access token to call a protected Web API

Note that the code below shows how to call directly the web API with an HttpURLConnection. You can also use libraries which will only require the access token (DocumentDb for instance) and will take care of the headers details. In practice the code might change depending on the libraries you want to call

Using the token:

HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Bearer " + accessToken);

To see an example of using the access token to call the Microsoft Graph, see Java console application sample or the Java web application sample