Search code examples
authenticationgraphqljwtauth0hasura

Why do I get error message "Error: GraphQL error: claims key: 'https://hasura.io/jwt/claims' not found"?


I'm using Auth0 for authentication and authorization in my app and I've specified a rule for jwt-tokens. But I get this error message in the console, "Error: GraphQL error: claims key: 'https://hasura.io/jwt/claims' not found". Why? What could I possibly have missed?


Solution

  • It's because your JWT token is not formatted correctly. Your JWT token must be formatted according to Hasura's spec described here:

    https://hasura.io/docs/1.0/graphql/manual/auth/authentication/jwt.html#the-spec

    Here is an example:

    {
      "sub": "1234567890",
      "name": "John Doe",
      "admin": true,
      "iat": 1516239022,
      "https://hasura.io/jwt/claims": {
        "x-hasura-allowed-roles": ["editor","user", "mod"],
        "x-hasura-default-role": "user",
        "x-hasura-user-id": "1234567890",
        "x-hasura-org-id": "123",
        "x-hasura-custom": "custom-value"
      }
    }