Authentication
The API uses two tokens: a short-lived access token in the Authorization header and a refresh token in a cookie, used to renew the session.
- The access token (JWT) is valid for 15 minutes. Add it to every request:
Authorization: Bearer <accessToken>. - The refresh token is valid for 30 days and comes only in the
usocial_refreshcookie (HttpOnly,Secure,SameSite=Strict, path/auth). It is not in the response body. Each refresh invalidates the old refresh token and issues a new one.
Sign-in response fields
accessTokenstring- JWT for the
Authorizationheader. tokenTypestring- Always
Bearer. expiresInSecondsnumber- Access token lifetime in seconds (900).
curl https://api.usocials.com/projects \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9…"Sign up
POST/auth/registerNo sign-in needed
Creates an account on the Free plan, signs in straight away and sets the refresh token cookie. We store the version of the accepted Terms and the date of acceptance.
Request body
emailstringrequired- E-mail address, up to 255 characters.
passwordstringrequired- Password, 8 to 100 characters.
termsAcceptedbooleanrequired- Must be
true: acceptance of the Terms of Service and the Privacy Policy.
Possible errors
- 400
termsAccepted: must be accepted - The Terms were not accepted or another field is invalid.
- 409
Email already in use - An account with this address already exists.
curl -X POST https://api.usocials.com/auth/register \
-H "Content-Type: application/json" \
-c cookies.txt \
-d '{"email": "john@company.com", "password": "your-password", "termsAccepted": true}'{
"Response": {
"status": {
"code": "201",
"msg": "Created",
"total": "0",
"page": "0",
"pagesize": "0"
},
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9…",
"tokenType": "Bearer",
"expiresInSeconds": 900
}
}
}Sign in
POST/auth/loginNo sign-in needed
Request body
emailstringrequired- E-mail address, up to 255 characters.
passwordstringrequired- Password, 8 to 100 characters.
Possible errors
- 401
Invalid email or password - Wrong e-mail or password. For security reasons we do not say which one.
curl -X POST https://api.usocials.com/auth/login \
-H "Content-Type: application/json" \
-c cookies.txt \
-d '{"email": "john@company.com", "password": "your-password"}'{
"Response": {
"status": {
"code": "200",
"msg": "OK",
"total": "0",
"page": "0",
"pagesize": "0"
},
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9…",
"tokenType": "Bearer",
"expiresInSeconds": 900
}
}
}Refresh the session
POST/auth/refreshNo sign-in needed
Issues a new access token based on the usocial_refresh cookie and replaces the cookie with a new one. No request body. Call it when the API returns 401 or when the access token is about to expire (expiresInSeconds).
Possible errors
- 401
Session expired - The cookie is missing, or the refresh token has expired or has already been used. The cookie is then removed and you need to sign in again.
curl -X POST https://api.usocials.com/auth/refresh \
-b cookies.txt -c cookies.txt{
"Response": {
"status": {
"code": "200",
"msg": "OK",
"total": "0",
"page": "0",
"pagesize": "0"
},
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiJ9…",
"tokenType": "Bearer",
"expiresInSeconds": 900
}
}
}Sign out
POST/auth/logoutNo sign-in needed
Invalidates the refresh token from the cookie and removes the cookie. Always responds with 204 No Content. The access token expires on its own within 15 minutes, so also delete it on the client side.
curl -X POST https://api.usocials.com/auth/logout \
-b cookies.txt -c cookies.txt(no body)