Appsync Authentication - AWS Cognito User Pools with AWS Amplify
See original GitHub issueTo pass the jwtToken in auth object https://www.youtube.com/watch?v=vAjf3lyjf8c&feature=youtu.be&t=3410 talks about passing it like:
but Auth.currentSession returns a promise (not sure if above approach is correct) so I followed this approach:
Now jwtToken is successfully generated but client auth object doesn’t wait for credentials to get generated.
What is the right way to generate token on the client side for cognito user pools?
Reference Implementation: https://github.com/serverless/serverless-graphql/pull/227
Amplify.configure({
Auth: {
region: process.env.REACT_APP_AWS_AUTH_REGION, // REQUIRED - Amazon Cognito Region
userPoolId: process.env.REACT_APP_USER_POOL_ID, //OPTIONAL - Amazon Cognito User Pool ID
userPoolWebClientId: process.env.REACT_APP_CLIENT_APP_ID, //User Pool App Client ID
},
});
const getCreds = async () => {
return await Auth.currentSession()
.then(data => {
return data.idToken.jwtToken;
})
.catch(err => console.log(err));
};
const client = new AWSAppSyncClient({
url: process.env.REACT_APP_GRAPHQL_ENDPOINT,
region: process.env.REACT_APP_AWS_CLIENT_REGION,
auth: {
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
jwtToken: getCreds(),
},
});```
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Authorization and authentication - AWS AppSync
This authorization type enforces OIDC tokens provided by Amazon Cognito User Pools. Your application can leverage the users and groups in your user...
Read more >How to connect to AWS AppSync using Cognito Identity Pools ...
I'm using the Amplify GraphQL client to connect to the AppSync server. The image below describes the steps that need to take place...
Read more >API (GraphQL) - Configure authorization modes - Swift
You can configure auth modes for an API using the Amplify CLI or manual ... Amazon Cognito User Pools is most commonly used...
Read more >Accessing AppSync APIs that require Cognito Login outside of ...
One way to protect your AppSync data is to use Cognito Identity Pools. Amplify makes it pretty transparent if you are using Amplify...
Read more >How to use Cognito with AppSync - Advanced Web Machinery
AWS AppSync provides a managed GraphQL API that you can use to implement backend functionality for users. AppSync integrates with Cognito ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @sid88in and @lolcoolkat with the latest aws-amplify and aws-appsync you can do something like this:
Hope that helps
@manueliglesias it should probably be getAccessToken() instead of getAcceessToken() just a small typo