Xác thực
API Vietnix Cloud dùng xác thực bằng token để đảm bảo truy cập an toàn vào các service. Quá trình xác thực gồm việc lấy token bằng thông tin đăng nhập hợp lệ, sau đó dùng token này trong các request API tiếp theo để cấp quyền truy cập.
Lấy token xác thực
Để lấy token xác thực, bạn cần gửi request POST đến endpoint xác thực kèm thông tin đăng nhập. Request cần có các thông tin sau:
- Username: Tên đăng nhập tài khoản Vietnix Cloud của bạn.
- Password: Mật khẩu tài khoản Vietnix Cloud của bạn.
- Project Name: Project bạn muốn truy cập (nếu có).
- Domain ID: Domain gắn với tài khoản của bạn (nếu có). Dưới đây là ví dụ request lấy token xác thực:
Request mẫu
Dùng curl
curl -ksD - -o /dev/null -H 'Content-Type: application/json' -d '
{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "user-1234",
"domain": {
"id": "921940ee9d6c465daa555fcc3e3764a2"
},
"password": "password1234"
}
}
},
"scope": {
"project": {
"name": "project-1234",
"domain": {
"id": "921940ee9d6c465daa555fcc3e3764a2"
}
}
}
}
}' https://api.vietnix.cloud/v3/auth/tokens
HTTP request
POST https://api.vietnix.cloud/v3/auth/tokens
với body:
JSON body
{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "user-1234",
"domain": {
"id": "921940ee9d6c465daa555fcc3e3764a2"
},
"password": "password1234"
}
}
},
"scope": {
"project": {
"name": "project-1234",1
"domain": {
"id": "921940ee9d6c465daa555fcc3e3764a2"
}
}
}
}
}
Response mẫu
Response thành công sẽ trả về token xác thực trong header X-Subject-Token và body JSON chứa thông tin về user đã xác thực cùng các role của user đó.
HTTP/1.1 201 CREATED
Server: nginx
Date: Fri, 24 Jan 2020 12:42:01 GMT
Content-Type: application/json
Content-Length: 7947
Connection: keep-alive
X-Subject-Token: gAAAAA<...>
Vary: X-Auth-Token
x-openstack-request-id: req-f732464d-62b4-44fd-92fa-ea368efc9a36