KeystoneJS graphql身份验证护照不起作用

问题描述

如果我通过使用googleAuthStrategy创建keystone.createAuthStrategy()来启用Google身份验证,keystonejs将创建以下 graphql 端点:

authenticateUserWithGoogle(
  itemId: ID!
  accesstoken: String!
): authenticateUserOutput

通过

调用
{
  itemId: '-1' /*needed to be set but not used*/,accesstoken: <code returned from https://accounts.google.com/o/oauth2/auth?response_type=code&[...]>
}

调用 listAuth.js 中的函数_authenticateMutation(),该函数将始终调用auth策略的validate()方法

问题在于,只有auth-password策略具有validate()方法,而auth-passport类没有方法

我试图在keystonejs服务器上添加初始化validate()方法,但是它不起作用:

googleAuthStrategy.validate = async (args) => {
  console.log("args",args); // {itemId,accesstoken}
  const serviceProfile = await googleAuthStrategy._validateWithService(googleAuthStrategy._passportStrategy,args.accesstoken);
  console.log("serviceProfile",serviceProfile); // won't be reached
}

因为_validateWithService()引发异常,

message: "Invalid Credentials"
name: "UserInfoError"
stacktrace: ["UserInfoError: Invalid Credentials",…]
0: "UserInfoError: Invalid Credentials"
1: "    at PROJECT_ROOT/node_modules/passport-google-oauth20/lib/strategy.js:97:21"
2: "    at passBackControl (PROJECT_ROOT/node_modules/oauth/lib/oauth2.js:132:9)"
3: "    at IncomingMessage.<anonymous> (PROJECT_ROOT/node_modules/oauth/lib/oauth2.js:157:7)"
4: "    at IncomingMessage.emit (events.js:327:22)"
5: "    at endReadableNT (_stream_readable.js:1327:12)"
6: "    at processticksAndRejections (internal/process/task_queues.js:80:21)"

我如何使它工作?到处都说keystonejs的身份验证适用于GraphQL应用程序,因此,也许我做错了。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)