laravel - AWS Cognito PHP SDK - Unable to verify secret hash for client
Get the solution ↓↓↓So far I created user pool, app client and marked Generate client secret box. I am able to register, login, logout. But I'm unable to refresh token using REFRESH_TOKEN_AUTH flow.
private function refreshConf($refreshToken, $hash)
{
return [
'AuthFlow' => 'REFRESH_TOKEN_AUTH',
'ClientId' => $this->client_id,
'UserPoolId' => $this->userpool_id,
'AuthParameters' => [
'REFRESH_TOKEN' => $refreshToken,
'SECRET_HASH' => $hash
]
];
}
public function refreshToken(string $refreshToken, string $hash)
{
try {
$conf = $this->refreshConf($refreshToken, $hash);
$result = $this->client->InitiateAuth($conf);
$result = $result->toArray();
logger($result);
if (isset($result['AuthenticationResult'])) {
return [
'error' => false,
'message' => 'SUCCESS',
'data' => $result
];
}
} catch (\Exception $e) {
logger(get_class($e));
return [
'error' => true,
'message' => $e->getAwsErrorMessage()
];
}
}
And my function to generate secret hash:
public function cognitoSecretHash($username)
{
$hash = hash_hmac('sha256', $username . $this->client_id, $this->client_secret, true);
return base64_encode($hash);
}
Secret hash is stored in User model during registration so I can send it when I want to refresh the token. But every timeAws\CognitoIdentityProvider\Exception\CognitoIdentityProviderException
is thrown. And I get the responseUnable to verify secret hash for client d***************9
.
So far I've spent hours trying too google the solution. There seems to be a problem with javascript SDK, but no mentions of PHP. I've gone through AWS documentation and can't find what am I doing wrong. I would appreciate any help. Thanks.
Answer
Solution:
if the client hasclient_secret
generated, then you have to replace:
'SECRET_HASH' => $hash
with
'SECRET_HASH' => $this->client_secret
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: fastcgi sent in stderr: "primary script unknown" while reading response header from upstream
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.