I'm trying to configure my codegen.yml file to interact with my GraphQL API on the MongoDB Atlas. But when I use Authorization: "eVaziLp8LgiFJivRQDgoLsjqbqm8KH5W2ykd4GD1hhR4FQ4DbE2I4wtEtM21hmpv"
, I receive the error 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
. How can I solve this? Because I'm literally following the documentation step by step, and now when I do exactly what it says, I get an error.

- 1
- 1
1 Answers
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:
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}"}'
})
Further reading on custom JWT request headers - https://www.mongodb.com/docs/atlas/app-services/graphql/authenticate/#custom-jwt

- 111
- 2
- 4