Skip to content

Commit

Permalink
fix: auth feishu platform not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Leizhenpeng committed Jan 15, 2024
1 parent eea915b commit bd40ed6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ export async function handler(argv: any) {
async function reauthorizeDingTalk() {
redIt('DingTalk is not supported yet')
}

async function reauthorizeFeishu() {
const spinner = ora('Reauthorizing Feishu').start()
const config = FeishuConfigManager.getInstance()
const newCookie = await getFeishuCookies() as any
// console.log(newCookie);
config.setFeishuConfig(newCookie)
spinner.succeed('Reauthorized Feishu')
return newCookie
await config.updateNickname()
spinner.succeed(`🚀Successfully reauthorized Feishu! Welcome, ${config.nickname}!`)
spinner.stop()
process.exit(0)
// return newCookie;
}

async function resetAllAuth() {
Expand Down
14 changes: 12 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ export class FeishuConfigManager {
this.setFeishuConfig({ ...feishuConfig, ...config })
}

updateNickname(nickname: string) {
async updateNickname() {
const feishuConfig = this.getFeishuConfig()
const aConfig = new Configuration({
session: feishuConfig.session as string,
lark_oapi_csrf_token: feishuConfig.lark_oapi_csrf_token as string,
})
const nickname = await aConfig.getNickname() as string
this.updateFeishuConfig({ nickname })
}

get nickname() {
const feishuConfig = this.getFeishuConfig()
return feishuConfig.nickname
}

async isAuth() {
const feishuConfig = this.getFeishuConfig()
// todo 真实校验
const aConfig = new Configuration({
session: feishuConfig.session as string,
lark_oapi_csrf_token: feishuConfig.lark_oapi_csrf_token as string,
Expand Down
7 changes: 4 additions & 3 deletions src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ async function checkFeishuAuth(detial = false) {
spinner.info('checking auth status')
const success = await config.isAuth()
if (detial) {
console.log('飞书配置信息:')
console.log('feishu detail config :')
console.log(config.getFeishuConfig())
}
if (success)
spinner.succeed('飞书已经授权')
// 用英文
spinner.succeed(`Hello ${config.nickname}, you have been granted authorization in Feishu.`)
else
spinner.fail('飞书未授权')
spinner.fail('You are not authorized in feishu')
}

0 comments on commit bd40ed6

Please sign in to comment.