Hi There,
My graphQL end point uses AMAZON_COGNITO_USER_POOLS. I had a look everywhere and cannot find the configuration for it w/ ApolloClient on amplify API, AWS or apollo.
I've successfully initialized my app with AWSAppSyncClient:
import awsmobile from '../aws-exports';
const client = new AWSAppSyncClient({
url: awsmobile.aws_appsync_graphqlEndpoint,
region: awsmobile.aws_appsync_region,
auth: {
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
jwtToken: async () =>
(await Auth.currentSession()).getIdToken().getJwtToken(),
},
});
This is what I've tried for ApolloClient:
import awsmobile from '../aws-exports';
const client = new ApolloClient({
uri: awsmobile.aws_appsync_graphqlEndpoint,
header: {
auth: {
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
jwtToken: async () =>
(await Auth.currentSession()).getIdToken().getJwtToken(),
}
}
});
But getting an error saying the header isn't correct.
Any doc/suggestion on how to config it?
Thanks
Hi @rfdc
The AWSAppSyncClient initialization looks correct to me. What is the exact error message you are getting? Can you successfully query your API from the AppSync console (after login in)?
For apollo client, please take a look at their docs for header-based auth. The header you need to add is "Authorization" with the token as the value.
Duplicate of awslabs/aws-mobile-appsync-sdk-js#306
@manueliglesias maybe it's different using the AppSync SDK, but I just discovered that using Axios with user pool authorization, prepending "Bearer " to the access token results in a 401 unauthorized response from the AppSync endpoint. Once I removed that prepend out of frustration I started getting 200s back from AppSync.
Just FYI.
@jkeys-ecg-nmsu thank you! I spent a few hours on this, if not for this note of yours. I would still be clueless. It works now.