Last active
August 22, 2023 20:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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