UserInfo Endpoint
SSO provides an endpoint to retrieve, in a simplified way, some user information. These are email, full name, and ID.
URLs
| Method | URL | Action | Description |
|---|---|---|---|
| GET | /api/userinfo | View | Retrieves basic user information (email, full name, and ID) |
Production:
{security-producao}/api/userinfoStaging:
{security-homologacao}/api/userinfoAuthentication
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
| Field | Type | Description |
|---|---|---|
user_email | string | User's email |
user_id | string | Unique user ID in the system |
user_name | string | User'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;
}
}