Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设置的自定义请求头不起作用 #25

Closed
tzz-v opened this issue Jan 16, 2023 · 1 comment
Closed

设置的自定义请求头不起作用 #25

tzz-v opened this issue Jan 16, 2023 · 1 comment
Labels
question Further information is requested

Comments

@tzz-v
Copy link

tzz-v commented Jan 16, 2023

版本:^1.8.1
设置的自定义请求头不起作用

import { data } from '../../../env';
import * as lark from '@larksuiteoapi/node-sdk';

const client = new lark.Client({
  appId: data.appId,
  appSecret: data.appSecret,
});

class Feishu {
  public accessToken = 't-g1041gdxODD4F2FX5VTFKDXFNG3DO24Z5MDPLBBF';
  public getChatIdByRobotId() {
    return client.im.chat.list(undefined, {
      headers: {
        Authorization: `Bearer ${this.accessToken}`,
      },
    }
    // lark.withTenantToken(`Bearer ${this.accessToken}`)
  );
  }
}
const service =  new Feishu();
service.getChatIdByRobotId();

image

@mazhe-nerd
Copy link
Collaborator

mazhe-nerd commented Jan 16, 2023

自己传token的话,需要在构造Client的参数中传递disableTokenCache: true禁用SDK获取token行为:

const client = new lark.Client({
  appId: data.appId,
  appSecret: data.appSecret,
  disableTokenCache: true
});
class Feishu {
  public accessToken = 't-g1041gdxODD4F2FX5VTFKDXFNG3DO24Z5MDPLBBF';
  public getChatIdByRobotId() {
    return client.im.chat.list({}, lark.withTenantToken(`Bearer ${this.accessToken}`));
  }
}

或者也可以使用lark.withUserAccessToken()来传递自定义token:

const client = new lark.Client({
  appId: data.appId,
  appSecret: data.appSecret
});
class Feishu {
  public accessToken = 't-g1041gdxODD4F2FX5VTFKDXFNG3DO24Z5MDPLBBF';
  public getChatIdByRobotId() {
    return client.im.chat.list({}, lark.withUserAccessToken(`Bearer ${this.accessToken}`));
  }
}

@mazhe-nerd mazhe-nerd added the question Further information is requested label Jan 16, 2023
@mazhe-nerd mazhe-nerd pinned this issue Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants