如何在Mongoatlas GraphQl API中使用JWT标准
我正在尝试配置我的codegen.yml文件,以与mongodb地图集上的GraphQl API进行交互。但是,当我使用授权时:“ evazilp8lgifjivrqdgolsjqbqm8kh5w2ykd4gd1hhr4fq4fq4dbe2i4wtetm21hmpv“
”
当我使用授权时:“携带者EVAZILP8LGIFJIVRQDGOLSJQBQM8KH5W2YKD4GD1HHR4FQ4DBE2BE2I4WTETM21HMPV”
输入/ rel =“ nofollow noreferrer”> https://www.mongodb.com/docs/atlas/app-services/graphql/authenticate/ ,我得到 token包含无效的段数
。我该如何解决?因为我从字面上逐步遵循文档,现在当我完全做它说的事情时,我会遇到错误。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在承载后包含的那个字符串
evaz ...
看起来不像是正确格式化的JWT,它的3个片段分别为时期。您需要使用一个领域SDK或Admin API获取客户端访问令牌。
这里是有关如何使用Web SDK获取访问令牌的文档 -
我认为所有其他领域客户端SDK都应该具有
user.accesstoken
conscotor方法。以及有关如何使用Admin API获取访问令牌的更多一般文档 - https://www.mongodb.com/docs/atlas/atlas/app-services/reference/reference/reference/authenticate/authenticate-http-client-reqlient-request-requests/#std -label-authenticate-http-client-requests
另外,如果您使用的是自定义JWT auth,请求标题不同。从文档中:
在自定义JWT请求标头上进行进一步阅读 - https://www.mongodb.com/docs/atlas/app-services/graphql/authenticate/#custom-jwt
That string which you've included after Bearer
eVaz...
doesn't look like a properly formatted JWT, which has 3 segments separated by periods.You need to get the client access token using one of the Realm SDKs or the Admin API.
Here's docs on how to get the access token with the Web SDK - https://www.mongodb.com/docs/realm/web/graphql-apollo-react/
I think all the other Realm client SDKs should also have a
User.accessToken
accessor method.And more general documentation on how to use the Admin API to get an access token - https://www.mongodb.com/docs/atlas/app-services/reference/authenticate-http-client-requests/#std-label-authenticate-http-client-requests
Alternatively, if you're using Custom JWT auth, the request header is different. From the docs:
Further reading on custom JWT request headers - https://www.mongodb.com/docs/atlas/app-services/graphql/authenticate/#custom-jwt