正如 calendly 演示应用程序链接所示,是否有任何方式仅在服务器端创建访问令牌和刷新令牌,因为根据他们的文档,它没有在任何地方列出。
我想实现类似的东西。
演示应用代码:
const OAuth2Strategy = require('passport-oauth2').Strategy;
const strategy = new OAuth2Strategy(
{
authorizationURL: CALENDLY_AUTH_BASE_URL + '/oauth/authorize',
tokenURL: CALENDLY_AUTH_BASE_URL + '/oauth/token',
clientID: CLIENT_ID,
clientSecret: CLIENT_SECRET,
callbackURL: REDIRECT_URI
},
async (accessToken, refreshToken, _profile, cb) => {
const calendlyService = new CalendlyService(accessToken, refreshToken);
const userInfo = await calendlyService.getUserInfo();
try {
const result = await User.findOrCreate({
accessToken,
refreshToken,
calendlyUid: userInfo.resource.uri
});
cb(null, { id: result.id });
} catch (e) {
console.error(e);
cb();
}
}
);
我的实现:
const OAuth2Strategy = require('passport-oauth2').Strategy;
const strategy = new OAuth2Strategy(
{
authorizationURL: CALENDLY_AUTH_BASE_URL + '/oauth/authorize',
tokenURL: CALENDLY_AUTH_BASE_URL + '/oauth/token',
clientID: CLIENT_ID ,
clientSecret: CLIENT_SECRET,
callbackURL: REDIRECT_URI,
},
async (accessToken, refreshToken, _profile, cb) => {
// console.log(IArguments)
console.log('async func called');
console.log(accessToken, refreshToken);
try {
cb(null,this.getRequestConfiguration(accessToken, refreshToken));
} catch (e) {
console.error(e);
cb();
}
}
);
在响应中,我未定义 accessToken,refreshToken。