Send an authenticated request

In the previous section, we achieved how to retrieve the access token from the server by passing username and password. Now, with the help of the access token that is received, let's send the authenticated request. The authenticated request will have an Authorization header in the request. We send the request via Fiddler. The request and response is given in the following screenshot:

Send an authenticated request

Fig 16 – Sending Authorized request with bearer token

We can also send a Bearer token in the header using HttpClient in C# code, as follows:

using (var client = new HttpClient()) { var token = "access_token"; client.DefaultRequestHeaders.Add("Authorization", ...

Get ASP.NET Web API Security Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.