-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
cloudtower-api-doc/docs/learning-api/authorization/_category_.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"label": "鉴权", | ||
"position": 31, | ||
"collapsible": true | ||
} |
49 changes: 49 additions & 0 deletions
49
cloudtower-api-doc/docs/learning-api/authorization/apikey.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: API Key 鉴权 | ||
--- | ||
|
||
在默认环境中,使用用户名,密码登录后即可换回 token,可以正常使用 token 进行鉴权,但是在开启了双因子认证后,无法单纯通过用户名,密码换回 token,会需要一个额外的第二因子验证,而在 API 的业务场景中,执行是无交互的,无法进行第二因子验证。 | ||
|
||
为了在此类环境下可以使用 CloudTower API,CloudTower 引入了 API Key ,以代替 token 进行鉴权。 | ||
|
||
### 签发 API Key | ||
|
||
API Key 的签发依旧需要依赖 token 鉴权,需要手动登录后获取 token 以后进行创建。 | ||
|
||
```bash | ||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: $TOKEN" \ | ||
--data-raw '{"query": "mutation createApiKey($name: String!) { createApiKey(data: { name: $name }) { id key roles { id preset }}}", "variables": {"name": "$NAME"}}' \ | ||
http://$CLOUDTOWER_DOMAIN/api/ | jq -r '.data.createApiKey.key' | ||
|
||
``` | ||
|
||
执行后将会创建一个权限等同于当前用户的 API Key,返回体中会包含 `key` 字段,即是生成的 API Key 的值。 | ||
|
||
### 使用 API Key | ||
|
||
API Key 的使用方式和 token 一致,将其放入 `Authorization` header 中即可。 | ||
|
||
```bash | ||
curl \ | ||
-X POST \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: $KEY" \ | ||
--data-raw '{"where":{}}' \ | ||
http://$CLOUDTOWER_DOMAIN/v2/api/get-vms | jq ".[]" | ||
``` | ||
|
||
### 删除 API Key | ||
|
||
API Key 相比于 token 的优势在于可以随时释放。token 指代的是一个用户,只要用户存在,对应的 token 就一直有效。而 API Key 可以通过 API 进行删除。 | ||
|
||
```bash | ||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: $TOKEN" \ | ||
--data-raw '{"query": "mutation deleteApiKey($key: String!) { deleteApiKey(where: { key: $key }) { id } }", "variables": { "key": "$KEY" }}' \ | ||
http://$CLOUDTOWER_DOMAIN/api/ | ||
``` | ||
|
||
执行后将会删除对应 key 的 API Key。 |
7 changes: 3 additions & 4 deletions
7
...pi-doc/docs/learning-api/authorization.md → .../docs/learning-api/authorization/basic.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ sidebar_position: 222 | |
|
||
```json | ||
{ | ||
"orderBy": "VcpuDesc" | ||
"orderBy": "vcpu_DESC" | ||
} | ||
``` | ||
|
||
|
5212177
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for cloudtower-api-doc ready!
✅ Preview
https://cloudtower-api-oft1vtfe2-xiaojunwengs-projects.vercel.app
Built with commit 5212177.
This pull request is being automatically deployed with vercel-action