Basic authentication
The basic authentication is defined in RFC 7617 and transmits credentials as a username and password pair, encoded using Base64. The credentials are included in the Authorization
header in the following format:
Authorization: Basic "username:password".toBase64Str()
Basic authentication transmits credentials as plaintext. It is strongly recommended to use HTTPS/TLS to protect sensitive or valuable information.
The main advantage of basic authentication is its simplicity, so it is suitable for testing, quick integrations, or internal applications. However, it is not recommended for production applications due to security limitations and the need to handle user credentials directly.
Authentication request examples
- Node.js
- Python
- C#
- cURL
const axios = require("axios");
const username = "yourusername";
const password = "yourpassword";
const token = Buffer.from(`${username}:${password}`).toString("base64");
const headers = {
"Authorization": `Basic ${token}`
};
axios.get("https://yourportal.onlyoffice.com/api/2.0/people/@self", { headers })
.then(res => console.log(res.data))
.catch(err => console.error(err.response?.data || err.message));
import requests
from base64 import b64encode
username = "yourusername"
password = "yourpassword"
credentials = f"{username}:{password}"
token = b64encode(credentials.encode()).decode()
headers = {
"Authorization": f"Basic {token}"
}
response = requests.get("https://yourportal.onlyoffice.com/api/2.0/people/@self", headers=headers)
print(response.status_code)
print(response.json())
var username = "yourusername";
var password = "yourpassword";
var credentials = $"{username}:{password}";
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64);
var response = await client.GetAsync("https://yourportal.onlyoffice.com/api/2.0/people/@self");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {response.StatusCode}");
Console.WriteLine(content);
curl -u yourusername:yourpassword https://yourportal.onlyoffice.com/api/2.0/people/@self
Or using the Authorization
header:
curl -H "Authorization: Basic $(echo -n "yourusername:yourpassword" | base64)" https://yourportal.onlyoffice.com/api/2.0/people/@self
Please note, that you have to enter your own portal address, username and password instead of yourportal.onlyoffice.com, yourusername and yourpassword respectively.