Accessing JWT variables within @custom mutations

According to example given in https://graphql.dgraph.io/doc/authorization/mutations I can access JWT variables within @auth() queries.
Can I use those JWT variables within @custom() mutations, so https://graphql.dgraph.io/doc/custom/mutation example could be rewritten as:

type Mutation {
    newPost(title: String!, text: String, $USER: String!): Post @custom(http:{
        url: "https://my.api.com/addPost"
        method: "POST",
        body: "{ postText: $text, postTitle: $title, author: $USER }"
        forwardHeaders: ["AuthHdr"]
    })
}

I know I can forward Auth headers and extract the USER at the API endpoint, but accessing JWT variables at @custom() mutation definition could be easier.

2 Likes

A use case for this would be defining the url based upon the JWT.

1 Like

We don’t allow accessing JWT variables inside custom mutations as of now. We will try to discuss that internally and see if we can have them soon.

@miko

We have discussed this internally and have come up with a couple of ways to achieve this.

  1. It should be possible for you to forward the JWT header to the custom endpoint and extract the variables there.
  2. This would also become possible when we introduce pre and post Javascript hooks where the JWT variables would be available to you under the context.
1 Like