如何在服务器上对身份验证服务进行本地呼叫?

问题描述 投票:0回答:1

我有一个工作的FeathersJS服务器使用身份验证服务。

我可以从客户端(浏览器)发出这样的POST:

http://localhost:3030/authentication/

POST BODY:

{“strategy”:“local”,“email”:“myEmail”,“password”:“myPassword”}

这工作,它返回验证的accessToken。

我正在尝试实现GraphQL(Apollo服务器v.2)。我设法让它工作,我可以从GraphQL解析器调用任何Feathers服务。

问题是 - 我需要从服务器端的代码而不是客户端调用身份验证服务。

当然,我可以继续自己编写所有内容 - 向用户查询并验证。但由于身份验证服务已经到位 - 我可以重新使用它吗?

我可以得到服务对象:

const authService = app.service('authentication');

我可以调用一些函数来获取经过验证的accessToken,例如:

return authService.someFunction({“strategy”:“local”,“email”:“[email protected]”,“password”:“password”});

只有两种方法可供选择

创建和删除。

Create不验证 - 它只是根据参数生成JWT。

有人可以给我一个帮助或任何想法吗?感谢任何帮助。

authentication graphql feathersjs
1个回答
1
投票

使用的方法是标准的Feathers服务create method

return authService.create({
  "strategy": "local",
  "email": "[email protected]",
  "password": "password"
});

您可以在basics guide中了解有关Feathers服务的更多信息以及authentication server API documentation中的身份验证服务。

© www.soinside.com 2019 - 2024. All rights reserved.