Graphql-playground: Use Graphql-playground with aws appsync Amazon Cognito User Pool

Created on 17 Apr 2019  路  11Comments  路  Source: graphql/graphql-playground

How can i use aws appsync graphql url with Amazon Cognito User Pool authorization in graphql playground

arereadme kinquestion

Most helpful comment

Seems you want to use either the authorization header for AMAZON_COGNITO_USER_POOLS auth type, or x-api-key for the API_KEY auth type, but not both at the same time. Set the authorization header to your jwtToken, or x-api-key to the appsync api key.

This is exactly the problem I had. If the default authentication is Cognito, x-api-key will be ignored, and the header mentioned above works. But if there are additional authentication modes with Cognito default, this header doesn't work. I believe the correct way is as @sevees said, only use this header
{
"authorization": "userToken"
}

All 11 comments

Add this to HTTP headers in the playground.

{ 
  "x-api-key": "apikey", 
  "authorization": "userToken"
}

You can find the x-api-key in your appsync console, and the userToken you can find when inspecting the network request graphql is doing when you are logged in.

Hi jarandmi
thanks for reply but i am using cognito user poll for authentication instead of apikey. How can i use Graphql playground with cognito user poll

The x-api-key is for AppSync, not cognito. Goto AppSync in your AWS console, and under settings you find your API ID.

@jarandmi and do you know how can it be used without app sync but still with cognito and api gateway methods auth'd with AWS_IAM? Not sure if cognito matters here because what I'd like to do is use my accessKeyId and secretAccessKey to do the authentication somehow.
Getting a signed request to get the correct headers didn't work out for me.

Btw, with insomnia I was able to make calls because they explicitly have a auth method for AWS IAM v4.

Api gateway is the same as Appsync (plus some more stuff).

{ "x-api-key": "apikey", "authorization": "userToken" }

apiKey

  1. Go to https://eu-west-1.console.aws.amazon.com/appsync/
  2. Find your project
  3. Click on Settings
  4. Copy the API ID, and us it as the apiKey

authorization
Get your user token (log into your app, and look at the header request. There you will find the authorization token. Use this as the authorization key.

Not really using api keys at the moment and not event sure if I can when using AWS_IAM auth but will try.
Thanks

Hi jarandmi
But api key use to expire in 7 days so i have to change it again and again. I would like to use cognito user pool instead of api key

to add to @jarandmi:
one can just go to AppSync console Queries, where it is possible to login with cognito user pool credentials (next to play button). Then any query executed there will have authorization header in inspected request in Network in Chrome devtools.

Seems you want to use either the authorization header for AMAZON_COGNITO_USER_POOLS auth type, or x-api-key for the API_KEY auth type, but not both at the same time. Set the authorization header to your jwtToken, or x-api-key to the appsync api key.

Seems you want to use either the authorization header for AMAZON_COGNITO_USER_POOLS auth type, or x-api-key for the API_KEY auth type, but not both at the same time. Set the authorization header to your jwtToken, or x-api-key to the appsync api key.

This is exactly the problem I had. If the default authentication is Cognito, x-api-key will be ignored, and the header mentioned above works. But if there are additional authentication modes with Cognito default, this header doesn't work. I believe the correct way is as @sevees said, only use this header
{
"authorization": "userToken"
}

I noticed the same behavior. You can't use both headers at once.

Was this page helpful?
0 / 5 - 0 ratings