Skip to main content

UserInfo API

The UserInfo endpoint returns profile information about the authenticated user. To access this endpoint, you must use an access token obtained through an IDP or Hosted UI flow.

Endpoint: GET https://api.chainit.online/oauth/userinfo


Request Requirements

  • Method: GET
  • Header: Authorization: Bearer {access_token}
  • Required Scopes: The token must have at least one of the following scopes: openid, profile, email, or phone.

Response Schema

The response returns standard OIDC claims based on the scopes granted during authentication.

{
"sub": "user_uuid_12345",
"name": "John Doe",
"given_name": "John",
"family_name": "Doe",
"email": "john.doe@example.com",
"email_verified": true,
"phone_number": "+1234567890",
"phone_number_verified": true,
"picture": "https://api.chainit.online/static/avatars/user_123.png"
}

Claim Descriptions

ClaimDescriptionScope Required
subUnique subject identifier for the user.openid
nameFull display name.profile
given_nameFirst name.profile
family_nameLast name.profile
emailUser's email address.email
email_verifiedWhether the email has been verified.email
phone_numberUser's phone number.phone
phone_number_verifiedWhether the phone has been verified.phone
pictureURL to the user's profile picture.profile

Implementation Example (Node.js)

async function getUserProfile(accessToken) {
const response = await fetch('https://api.chainit.online/oauth/userinfo', {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});

if (!response.ok) {
throw new Error('Failed to fetch user info');
}

const profile = await response.json();
console.log('User Profile:', profile);
return profile;
}

SDK Convenience Method (Browser)

If you are using the ChainIT Hosted UI SDK ({HOSTED_AUTH_PKG_NAME}), it provides a built-in fetchUserInfo() that uses its own axios interceptor to attach the bearer token automatically. No token parameter or manual fetch is needed.

React

import { useUserInfo } from "@chainitservices/hosted-ui";

function Profile() {
const { data: userInfo, isLoading, error } = useUserInfo();
if (isLoading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return <p>Hello, {userInfo?.name ?? userInfo?.email}</p>;
}

JavaScript / UMD

<script src="https://unpkg.com/@chainitservices/hosted-ui@latest/dist/sdk/chainit-auth.umd.js"></script>
<script>
const info = await HostedAuth.fetchUserInfo();
console.log(info.name, info.email);
</script>

Call fetchUserInfo() only after the user has completed the auth flow (the SDK stores the access token internally).