Skip to content

Instantly share code, notes, and snippets.

@koladilip
Last active August 22, 2023 20:13
Show Gist options
  • Save koladilip/7d3ca1e0d060ed42965eb41744d12333 to your computer and use it in GitHub Desktop.
Save koladilip/7d3ca1e0d060ed42965eb41744d12333 to your computer and use it in GitHub Desktop.
Code for refreshing AWS Cognito user pool tokens using refresh token from browser.
fetch("https://cognito-idp.<cognito-user-pool-region>.amazonaws.com/", {
headers: {
"X-Amz-Target": "AWSCognitoIdentityProviderService.InitiateAuth",
"Content-Type": "application/x-amz-json-1.1",
},
mode: 'cors',
cache: 'no-cache',
method: 'POST',
body: JSON.stringify({
ClientId: "<cognito-user-pool-client-id>",
AuthFlow: 'REFRESH_TOKEN_AUTH',
AuthParameters: {
REFRESH_TOKEN: "<cognito-refresh-toke>",
//SECRET_HASH: "your_secret", // In case you have configured client secret
}
}),
}).then((res) => {
return res.json(); // this will give jwt id and access tokens
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment