New in 2.4: Test runs you can trust See what's new →

Return the profile of the user behind an access token

GEThttps://api.testingapis.com/api/auth/oauth/userinfo

Header: Authorization: Bearer <access_token>. The email is only included when the token has the email scope.

OAuth2 access token (password or authorization-code grant); or Bearer token — {{oauthAccessToken}}

Responses

200
User profile.
401
Token missing, invalid, revoked or expired.
403
client_credentials tokens have no user.

Example

Request
curl -X GET "https://api.testingapis.com/api/auth/oauth/userinfo" \
  -H "Authorization: Bearer {{oauthAccessToken}}"
Run in Studio
Response200 OK
{
  "sub": "apibee",
  "name": "TestingAPIs Tester",
  "preferred_username": "apibee",
  "email": null,
  "email_verified": null
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/auth/oauth/userinfo", {
  headers: {
    "Authorization": "Bearer {{oauthAccessToken}}",
  },
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "GET",
    "https://api.testingapis.com/api/auth/oauth/userinfo",
    headers={
        "Authorization": "Bearer {{oauthAccessToken}}",
    },
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/auth/oauth/userinfo"))
            .header("Authorization", "Bearer {{oauthAccessToken}}")
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}