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); }); - }) + }) } }