[英]How to use the JWT standard in MongoAtlas GraphQL API
我正在嘗試配置我的 codegen.yml 文件以與 MongoDB Atlas 上的 GraphQL API 交互。 但是,當我使用Authorization: "eVaziLp8LgiFJivRQDgoLsjqbqm8KH5W2ykd4GD1hhR4FQ4DbE2I4wtEtM21hmpv"
時,我收到錯誤expected Authorization header with JWT (Bearer schema)
.
And when I use Authorization: "Bearer eVaziLp8LgiFJivRQDgoLsjqbqm8KH5W2ykd4GD1hhR4FQ4DbE2I4wtEtM21hmpv"
as the docs suggest: https://www.mongodb.com/docs/atlas/app-services/graphql/authenticate/ , I get token contains an invalid number of segments
. 我該如何解決這個問題? 因為我實際上是在一步一步地遵循文檔,現在當我完全按照它所說的去做時,我得到了一個錯誤。
您在 Bearer eVaz...
之后包含的那個字符串看起來不像是格式正確的 JWT,它有 3 個由句點分隔的段。
您需要使用 Realm SDK 或管理員 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/
我認為所有其他 Realm 客戶端 SDK 也應該有一個User.accessToken
訪問器方法。
還有更多關於如何使用管理員 API 獲取訪問令牌的一般文檔 - https://www.mongodb.com/#docs/atlas/app-client-servicesrequestreference/#docs/atlas/app-client-servicesrequestreference/驗證-http-client-requests
或者,如果您使用自定義 JWT 身份驗證,則請求 header 是不同的。 從文檔:
http.post({
"url": "https://realm.mongodb.com/api/client/v2.0/app/<yourappid-abcde>/graphql",
"headers": {
"jwtTokenString": "<User's JWT Token>"
},
"body": '{"query":"query AllMovies {\n movies {\n title\n year\n }\n}"}'
})
進一步閱讀自定義 JWT 請求標頭 - https://www.mongodb.com/docs/atlas/app-services/graphql/authenticate#/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.