S'authentifier
Obtenir un jeton, ou utiliser la clé API d'un utilisateur.
Chaque appel à l'API agit au nom d'un utilisateur de Docage, avec ses droits. Il le prouve de deux façons : par un jeton, obtenu avec son email et son mot de passe, ou par sa clé API.
Par un jeton
Demandez un jeton avec l'email et le mot de passe de l'utilisateur :
POST https://staging-api.docage.com/Account/CreateToken
Content-Type: application/json
{
"Email": "prenom.nom@example.com",
"Password": "votre-mot-de-passe"
}curl -X POST "https://staging-api.docage.com/Account/CreateToken" \
-H "Content-Type: application/json" \
-d '{
"Email": "prenom.nom@example.com",
"Password": "votre-mot-de-passe"
}'using HttpClient client = new();
using HttpRequestMessage request = new(HttpMethod.Post, "https://staging-api.docage.com/Account/CreateToken");
request.Content = new StringContent("""
{
"Email": "prenom.nom@example.com",
"Password": "votre-mot-de-passe"
}
""", Encoding.UTF8, "application/json");
using HttpResponseMessage response = await client.SendAsync(request);
string result = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
throw new HttpRequestException(result);const response = await fetch("https://staging-api.docage.com/Account/CreateToken", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"Email": "prenom.nom@example.com",
"Password": "votre-mot-de-passe"
})
});
const text = await response.text();
if (!response.ok) throw new Error(text);
const result = text ? JSON.parse(text) : null;La réponse porte le jeton dans JWToken, avec la fiche de l'utilisateur connecté. Envoyez-le ensuite dans l'en-tête
Authorization de chaque appel :
GET https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9…curl "https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9…"using HttpClient client = new();
using HttpRequestMessage request = new(HttpMethod.Get, "https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
using HttpResponseMessage response = await client.SendAsync(request);
string result = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
throw new HttpRequestException(result);const response = await fetch("https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301", {
headers: {
Authorization: `Bearer ${token}`
}
});
const text = await response.text();
if (!response.ok) throw new Error(text);
const result = text ? JSON.parse(text) : null;Un email ou un mot de passe erroné répond 400, sans plus de détail. Après plusieurs mots de passe erronés, le compte est
momentanément verrouillé.
La durée d'un jeton
Un jeton vaut 24 heures. Pour le prolonger, demandez-en un nouveau avec le jeton en cours : le nouveau remplace l'ancien, qui cesse d'être accepté.
POST https://staging-api.docage.com/Account/refreshtoken
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9…curl -X POST "https://staging-api.docage.com/Account/refreshtoken" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9…"using HttpClient client = new();
using HttpRequestMessage request = new(HttpMethod.Post, "https://staging-api.docage.com/Account/refreshtoken");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
using HttpResponseMessage response = await client.SendAsync(request);
string result = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
throw new HttpRequestException(result);const response = await fetch("https://staging-api.docage.com/Account/refreshtoken", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`
}
});
const text = await response.text();
if (!response.ok) throw new Error(text);
const result = text ? JSON.parse(text) : null;Pour mettre fin à une session, POST https://staging-api.docage.com/Account/Logout avec le jeton : il n'est plus accepté.
Les connexions simultanées
Une licence d'utilisateur comprend une connexion par type d'application : l'application de bureau, l'application mobile et l'API. Un jeton demandé comme ci-dessus est une connexion de l'API. Une connexion de plus du même type, utilisée dans la même minute qu'une autre, est facturée à l'heure, selon les conditions de votre organisation : prolongez un jeton plutôt que d'en demander un nouveau.
Par la clé API
La clé API d'un utilisateur se génère dans sa fiche, onglet Clé API. Elle s'envoie avec son email, en authentification
Basic : email:clé encodé en Base64.
GET https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301
Authorization: Basic cHJlbm9tLm5vbUBleGFtcGxlLmNvbTp2b3RyZS1jbGUtYXBpcurl "https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301" \
-H "Authorization: Basic cHJlbm9tLm5vbUBleGFtcGxlLmNvbTp2b3RyZS1jbGUtYXBp"using HttpClient client = new();
using HttpRequestMessage request = new(HttpMethod.Get, "https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301");
request.Headers.TryAddWithoutValidation("Authorization", "Basic cHJlbm9tLm5vbUBleGFtcGxlLmNvbTp2b3RyZS1jbGUtYXBp");
using HttpResponseMessage response = await client.SendAsync(request);
string result = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
throw new HttpRequestException(result);const response = await fetch("https://staging-api.docage.com/Contacts/3f2504e0-4f89-11d3-9a0c-0305e82c3301", {
headers: {
Authorization: "Basic cHJlbm9tLm5vbUBleGFtcGxlLmNvbTp2b3RyZS1jbGUtYXBp"
}
});
const text = await response.text();
if (!response.ok) throw new Error(text);
const result = text ? JSON.parse(text) : null;Attention
La clé API donne tous les droits de l'utilisateur : gardez-la comme un mot de passe, et générez-en une nouvelle si elle a pu être lue par un tiers.