Skip to content

UserInfo Endpoint

SSO provides an endpoint to retrieve, in a simplified way, some user information. These are email, full name, and ID.

URLs

MethodURLActionDescription
GET/api/userinfoViewRetrieves basic user information (email, full name, and ID)

Production:

{security-producao}/api/userinfo

Staging:

{security-homologacao}/api/userinfo

Authentication

The call header must include the user's access token obtained in the process from chapter 6, in Bearer format.

Authorization: Bearer <access_token>

Request Example

javascript
const response = await fetch('{security-producao}/api/userinfo', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${accessToken}`
  }
});

const userInfo = await response.json();

Response

The obtained response will be in the following format:

json
{
  "user_email": "string",
  "user_id": "string",
  "user_name": "string"
}

Response Fields

FieldTypeDescription
user_emailstringUser's email
user_idstringUnique user ID in the system
user_namestringUser's full name

Error Handling

In case of error, the API will return an appropriate HTTP status code (401, 403, etc.) and an error message in the response body.

Complete Example

javascript
async function getUserInfo(accessToken) {
  try {
    const response = await fetch('{security-producao}/api/userinfo', {
      method: 'GET',
      headers: {
        'Authorization': `Bearer ${accessToken}`
      }
    });

    if (!response.ok) {
      throw new Error(`Error ${response.status}: ${response.statusText}`);
    }

    const userInfo = await response.json();
    return userInfo;
  } catch (error) {
    console.error('Error getting user information:', error);
    throw error;
  }
}

Fanbase API Documentation