我有一个 Koa.JS 网络应用程序,它使用 Passport.JS 进行 oAuth2 身份验证。这个网络应用程序是用打字稿编写的。这是验证码:
import { deserializeUser, serializeUser, use } from 'koa-passport';
import { Strategy, VerifyCallback } from 'passport-oauth2';
import config from 'config';
import { Authenticator } from 'passport';
const OAuth2Strategy = Strategy;
use(
new OAuth2Strategy(
config.get('oauth2'),
(accessToken: string, refreshToken: string, profile: any, done: VerifyCallback): void =>
{
if (accessToken && refreshToken) {
const tokens = { access_token: accessToken, refresh_token: refreshToken };
done(null, tokens);
} else {
done(undefined, undefined, { message: 'An error occurred!' });
}
}
)
);
serializeUser<Authenticator, Authenticator>(
(user: Authenticator, done: (err: any, id?: Authenticator | undefined) => void): void => {
done(null, user);
}
);
Web 应用程序可以使用 @types/passport 1.0.4 正常编译,但是当我将 @types/passport 的版本升级到 1.0.5 时会生成新错误。
Type 'Authenticator<Handler, any, any, AuthenticateOptions>' does not satisfy the constraint 'IncomingMessage'.
Type 'Authenticator<Handler, any, any, AuthenticateOptions>' is missing the following properties from type 'IncomingMessage': aborted, httpVersion, httpVersionMajor, httpVersionMinor, and 45 more.
serializeUser<Authenticator, Authenticator>
有没有人经历过这个?