# GraphQL subscription authentication

**URL:** <https://community.postman.com/t/graphql-subscription-authentication/52744>\
**Category:** Help Hub\
**Tags:** authentication, graphql\
**Created:** [October 3, 2023, 11:49am UTC](https://community.postman.com/t/graphql-subscription-authentication/52744 "2023-10-03T11:49:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleks78](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@aleks78](https://community.postman.com/u/aleks78)\
**Post date:** [October 3, 2023, 11:49am UTC](https://community.postman.com/t/graphql-subscription-authentication/52744/1 "2023-10-03T11:49:23Z")

</div>

### How to authenticate graphql subscription

Hi everyone,

I have a problem testing graphql subscriptions. Our APIs are protected (https/wss) and on the connection start the initial message must have JWT token, otherwise the server rejects the subscription request.

With a graphql-ws protocol a client has the possibility to send an initial message with an arbitrary payload. How this kind of operation could be done with Postman?

I’ll add [official apollo react documentation](https://www.apollographql.com/docs/react/data/subscriptions/#5-authenticate-over-websocket-optional) as support to what I need to do.

Any suggestion is welcome.

Thanks

---

<div class="post-metadata">

**Author:** ![meenakshi.dhanani](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/meenakshi.dhanani/32/5980_2.png) [@meenakshi.dhanani](https://community.postman.com/u/meenakshi.dhanani)\
**Post date:** [October 5, 2023, 1:21am UTC](https://community.postman.com/t/graphql-subscription-authentication/52744/2 "2023-10-05T01:21:03Z")

</div>

Welcome 👋 @aleks78

I just did a little POC to test that in Postman. It is certainly possible to provide auth info for a GraphQL subscription request.

tldr;

 ![Screenshot 2023-10-05 at 6.42.04 AM](https://us1.discourse-cdn.com/getpostman/original/3X/8/9/89ccdd112471f1590299e143ad60b97409da14e2.png)

**Details**  
I created a GraphQL server instance that checks onSubscribe if the user is authenticated and returns an error. I used the graphql-ws library and used a GraphQL Yoga server. I can add authorization details to the Authorization tab, which receives the web socket request. Referred to [this](https://the-guild.dev/graphql/ws/recipes#server-usage-with-ws-and-custom-auth-handling) guide.

An older version of the GraphQL Postman client (v1) allowed you to use the same interface and send the payload by setting the request body type as GraphQL - [Manage GraphQL queries using the Postman HTTP request interface | Postman Learning Center](https://learning.postman.com/docs/sending-requests/graphql/graphql-client-interface/#understanding-parts-of-the-request-interface)

There is, however, a newer version of the client, which is more customized to the requirements of GraphQL users. I’d suggest trying this one out - [Manage GraphQL queries using the Postman HTTP request interface | Postman Learning Center](https://learning.postman.com/docs/sending-requests/graphql/graphql-client-interface/). In case, you find other bugs or issues with the client, the team would your feedback via an issue on this repository - [GitHub - postmanlabs/postman-app-support: Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.](https://github.com/postmanlabs/postman-app-support)

I’m happy to help, in case this solution doesn’t work out for you! Let me know 🙂

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 4, 2023, 1:21am UTC](https://community.postman.com/t/graphql-subscription-authentication/52744/3 "2023-11-04T01:21:24Z")

</div>

Closed on November 4, 2023, 1:21am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
