Lewati ke isi

Referensi API

OAuth2

Penerbitan dan pencabutan access token (client credentials). Tanpa token; autentikasi klien.

OpenAPI 3.1 · versi 1.1.0 · 127 operasi · 30 event webhook

Basis URLhttps://api.medivana.cloud/api/v1

Terbitkan access token (client credentials)

Kredensial dikirim lewat Authorization: Basic base64(client_id:client_secret) (disarankan) atau field client_id/client_secret di body. Body application/x-www-form-urlencoded (JSON juga diterima). scope opsional: subset scope klien dipisah spasi; default semua scope klien. Token opaque, berlaku 3600 detik, tidak ada refresh token. Batas laju 60 permintaan/menit/IP.

Scope
Autentikasi klien (Basic)

Body permintaan application/x-www-form-urlencoded

Body permintaan POST /oauth/token
NamaTipeKeterangan
grant_typewajib"client_credentials"
scopestringSubset scope dipisah spasi; default semua scope klien.
client_idstringAlternatif Basic auth
client_secretstringAlternatif Basic auth
grant_type=client_credentials&scope=patients%3Aread+encounters%3Aread

Contoh kode

Bahasa contoh kode
curl -X POST "https://api.medivana.cloud/api/v1/oauth/token" \
  -u "$MEDIVANA_CLIENT_ID:$MEDIVANA_CLIENT_SECRET" \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode 'scope=patients:read encounters:read'
const basic = Buffer.from(`${process.env.MEDIVANA_CLIENT_ID}:${process.env.MEDIVANA_CLIENT_SECRET}`).toString("base64");
const res = await fetch("https://api.medivana.cloud/api/v1/oauth/token", {
  method: "POST",
  headers: { Authorization: `Basic ${basic}` },
  body: new URLSearchParams({
    grant_type: "client_credentials",
    scope: "patients:read encounters:read",
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
import os
import requests

resp = requests.post(
    "https://api.medivana.cloud/api/v1/oauth/token",
    auth=(os.environ["MEDIVANA_CLIENT_ID"], os.environ["MEDIVANA_CLIENT_SECRET"]),
    data={
        "grant_type": "client_credentials",
        "scope": "patients:read encounters:read",
    },
    timeout=30,
)
resp.raise_for_status()
data = resp.json()

Respons

200Token terbitapplication/json

{
  "access_token": "mdn_at_Q2xpZW50Q3JlZGVudGlhbHNDb250b2g",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "patients:read encounters:read"
}
Skema 200
Skema 200
NamaTipeKeterangan
access_tokenwajibstring
token_typewajib"Bearer"
expires_inwajibintegerDetik
scopewajibstringScope yang diberikan, dipisah spasi
Galat
  • 400invalid_request, unsupported_grant_type, invalid_scope (scope tidak diberikan ke klien), atau unauthorized_client (modul API tidak aktif di paket)
  • 401invalid_client: client_id tidak dikenal, secret salah, atau klien dicabut
  • 429rate-limited60 permintaan per menit per IP terlampaui

Cabut access token (RFC 7009)

Selalu 200 walau token tidak dikenal atau milik klien lain (tidak membocorkan keberadaan token). Butuh autentikasi klien seperti /oauth/token.

Scope
Autentikasi klien (Basic)

Body permintaan application/x-www-form-urlencoded

Body permintaan POST /oauth/revoke
NamaTipeKeterangan
tokenwajibstringAccess token yang dicabut
client_idstringAlternatif Basic auth
client_secretstringAlternatif Basic auth
token=mdn_at_Q2xpZW50Q3JlZGVudGlhbHNDb250b2g

Contoh kode

Bahasa contoh kode
curl -X POST "https://api.medivana.cloud/api/v1/oauth/revoke" \
  -u "$MEDIVANA_CLIENT_ID:$MEDIVANA_CLIENT_SECRET" \
  --data-urlencode 'token=mdn_at_Q2xpZW50Q3JlZGVudGlhbHNDb250b2g'
const basic = Buffer.from(`${process.env.MEDIVANA_CLIENT_ID}:${process.env.MEDIVANA_CLIENT_SECRET}`).toString("base64");
const res = await fetch("https://api.medivana.cloud/api/v1/oauth/revoke", {
  method: "POST",
  headers: { Authorization: `Basic ${basic}` },
  body: new URLSearchParams({
    token: "mdn_at_Q2xpZW50Q3JlZGVudGlhbHNDb250b2g",
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
import os
import requests

resp = requests.post(
    "https://api.medivana.cloud/api/v1/oauth/revoke",
    auth=(os.environ["MEDIVANA_CLIENT_ID"], os.environ["MEDIVANA_CLIENT_SECRET"]),
    data={
        "token": "mdn_at_Q2xpZW50Q3JlZGVudGlhbHNDb250b2g",
    },
    timeout=30,
)
resp.raise_for_status()
data = resp.json()

Respons

200Token dicabut (atau memang tidak berlaku)application/json

{
  "status": "revoked"
}
Skema 200
Skema 200
NamaTipeKeterangan
statuswajib"revoked"
Galat
  • 400invalid_request
  • 401invalid_client
  • 429rate-limited60 permintaan per menit per IP terlampaui