From fe52e2bf8f13f8ff576fb7e67ef1c689828d45f8 Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Sun, 23 Mar 2025 17:16:35 +0800 Subject: [PATCH] feat: verify token and user --- src/devstar-api.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/devstar-api.ts b/src/devstar-api.ts index 036552b..e72983c 100644 --- a/src/devstar-api.ts +++ b/src/devstar-api.ts @@ -17,6 +17,33 @@ export default class DevstarAPIHandler { } } + public async verifyToken(token: string, username: string): Promise { + return new Promise(async (resolve) => { + fetch(this.devstarDomain + `/api/devcontainer/user`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'token ' + token + } + }) + .then(response => { + response.json().then(async data => { + if (response.ok) { + if (data.username == username) { + resolve('ok') + } else { + utils.showErrorNotification('Token与用户名不符') + console.error('Token: ', token, ' Username: ', username) + } + } else { + utils.showErrorNotification('Token错误') + console.error('Error token: ', token) + } + }) + }) + }) + } + // 上传公钥 public async uploadUserPublicKey(user: User): Promise { return new Promise(async (resolve) => { @@ -55,7 +82,7 @@ export default class DevstarAPIHandler { console.error(error); }); - }) + }) } }