AppWorks Authentication for Visual Studio Code
特性
用法
获取用户信息
import * as vscode from 'vscode';
(async function() {
const userInfo = await vscode.authentication.getSession('AppWorks', [], { createIfNone: true });
console.log(userInfo);
})()
通过 Command 进行登录
import * as vscode from 'vscode';
vscode.commands.executeCommand('appworks-authentication.login');
通过 Command 退出登录
import * as vscode from 'vscode';
vscode.commands.executeCommand('appworks-authentication.logout');
监听登录、登出的状态
import * as vscode from 'vscode';
function registerSessionChangeEvent() {
const appworksAuthExt = vscode.extensions.getExtension('iceworks-team.appworks-authentication')!;
const importedApi = appworksAuthExt.exports;
importedApi.getOnDidChangeSessionEvent()((event: vscode.AuthenticationProviderAuthenticationSessionsChangeEvent) => {
console.log('session change', event);
});
}
获取 SSO_TICKET
SSO_TICKET 是用于免登的临时凭证,有效时间是一分钟,并且使用后就失效了。因此需要每次发起请求前,先获取 SSO_TICKET,然后在请求 query 中带上
import * as vscode from 'vscode';
const appworksAuthExt = vscode.extensions.getExtension('iceworks-team.appworks-authentication')!;
const importedApi = appworksAuthExt.exports;
importedApi.getOneTimeSSOTicket().then((SSO_TICKET: string) => {
console.log(SSO_TICKET);
}).catch((error: any) => {
console.error(error);
})
| |