how handle refresh token service in AWS amplify-js

前端 未结 5 1476
终归单人心
终归单人心 2021-01-03 16:14

In my react project I am using AWS Cognito user pool for user management, for user authentication, I am using AWS Cognito idToken. after 90min the session will expire, then

5条回答
  •  攒了一身酷
    2021-01-03 16:40

    This will hand you back an AccessToken and a idToken.

    fetch("https://cognito-idp..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: "",
            AuthFlow: 'REFRESH_TOKEN_AUTH',
            AuthParameters: {
                REFRESH_TOKEN: "",
                //SECRET_HASH: "your_secret", // In case you have configured client secret
            }
        }),
    }).then((res) => {
        return res.json(); // this will give jwt id and access tokens
    });
    
    

提交回复
热议问题