Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to verify secret hash for client #2736

Closed
siddiquebagwan-gslab opened this issue Jan 23, 2021 · 13 comments
Closed

Unable to verify secret hash for client #2736

siddiquebagwan-gslab opened this issue Jan 23, 2021 · 13 comments
Labels
closed-for-staleness guidance Question that needs advice or information. response-requested Waiting on additional information or feedback.

Comments

@siddiquebagwan-gslab
Copy link

Hi Boto3 Team

We are trying to refresh IdToken using Refresh Token with the help boto3 API. Below is the python piece code:
client = boto3.client('cognito-idp')
client.initiate_auth(
ClientId=client_id,
AuthFlow='REFRESH_TOKEN_AUTH',
AuthParameters={
'REFRESH_TOKEN': refresh_token,
'SECRET_HASH': get_secret_hash(username)
}

get_secret_hash(username, client_id, client_secret) is defined as below:
message = username + client_id
dig = hmac.new(bytearray(client_secret, "utf-8"), msg=message.encode('UTF-8'),
digestmod=hashlib.sha256).digest()
return base64.b64encode(dig).decode()

We get below error when we call client.initiate_auth method defined above:
botocore.errorfactory.NotAuthorizedException: An error occurred (NotAuthorizedException) when calling the InitiateAuth operation: Unable to verify secret hash for client 2cbjb*******

Note: We are using the same function get_secret_hash to generate secret_hash for signup method in boto3 and that works fine.
Boto3 version - 1.16.58
Botocore version - 1.19.58

Please let us know if we are missing something for generating IDToken from refresh token

@siddiquebagwan-gslab siddiquebagwan-gslab added the needs-triage This issue or PR still needs to be triaged. label Jan 23, 2021
@swetashre swetashre self-assigned this Jan 26, 2021
@swetashre
Copy link
Contributor

@Mohd-gslab - Thank you for your post. I think the most likely issues are incorrect client id or secret. The refresh token could also be expired.
As you have already mentioned that you are not getting error with sign up method then can you please check if your refresh token is expired ?

@swetashre swetashre added guidance Question that needs advice or information. response-requested Waiting on additional information or feedback. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 26, 2021
@siddiquebagwan-gslab
Copy link
Author

siddiquebagwan-gslab commented Jan 27, 2021 via email

@github-actions github-actions bot removed the response-requested Waiting on additional information or feedback. label Jan 27, 2021
@swetashre
Copy link
Contributor

@Mohd-gslab - I tried but i am not able to reproduce the issue. Could you verify from the debug logs that whenever we are making api call all the parameters are correctly set ? You can enable log by adding boto3.set_stream_logger('') to your code.

@swetashre swetashre added the response-requested Waiting on additional information or feedback. label Jan 27, 2021
@github-actions
Copy link

github-actions bot commented Feb 3, 2021

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Feb 3, 2021
@MaximZemskov
Copy link

Hi. We are have the same issue. Signup works fine, but when we are trying to renew token it fails. We are using pycognito wich generates secret hash with this method

@staticmethod
def get_secret_hash(username, client_id, client_secret):
    message = bytearray(username + client_id, "utf-8")
    hmac_obj = hmac.new(bytearray(client_secret, "utf-8"), message, hashlib.sha256)
    return base64.standard_b64encode(hmac_obj.digest()).decode("utf-8")

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional information or feedback. labels Feb 5, 2021
@MaximZemskov
Copy link

Looks like refresh_token returned by respond_to_auth_challenge is broken. Currently investigating where is a problem.
2021-02-05 17 05 51

@swetashre
Copy link
Contributor

Can anyone provide detailed steps so that we can try reproduce the issue ? It would be helpful if anyone could provide debug logs. You can enable log by adding boto3.set_stream_logger('') to your code.

@swetashre swetashre added the response-requested Waiting on additional information or feedback. label Mar 24, 2021
@swetashre swetashre removed their assignment Mar 24, 2021
@SheryarButt
Copy link

Hello @MaximZemskov. Was this issue resolved or not?
I'm facing the same issue as above.

@github-actions github-actions bot removed the response-requested Waiting on additional information or feedback. label Mar 31, 2021
@MaximZemskov
Copy link

@SheryarButt Hey. Yes it was resolved, but not by me. For other person problem was using email instead the uuid for username.

@kdaily
Copy link
Member

kdaily commented Apr 26, 2021

Hi @Mohd-gslab or @SheryarButt,

To assist further we will need to see complete debug logs as previously requested. You can enable log by adding boto3.set_stream_logger('') to your code. Thank you!

@kdaily kdaily added the response-requested Waiting on additional information or feedback. label Apr 26, 2021
@github-actions
Copy link

github-actions bot commented May 3, 2021

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels May 3, 2021
@github-actions github-actions bot closed this as completed May 7, 2021
@antarsaha9
Copy link

Those who are still getting the issue can check out this answer:

https://stackoverflow.com/a/54508553

@khordoo
Copy link

khordoo commented Mar 25, 2023

If you use email as your username, use the Cognito-assigned UUID username when calculating the secret hash not the email address.
The UUID can be decoded from the IdToken that you received after the login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness guidance Question that needs advice or information. response-requested Waiting on additional information or feedback.
Projects
None yet
Development

No branches or pull requests

7 participants