How to check if a cognito access token has expired?

  amazon-cognito, amazon-web-services, c++

The access token is valid for 1 hour.
I know how to use a refresh token to update an access token.
However, I don’t know how to check if the cognito access token has expired.

Pattern1: Measure the time since token authentication by timer thread.
-> Waste of CPU resources…

Pattern2: Record the authentication time & Compare current time.

Pattern3: Check using the AWS SDK.
-> How to use?

Pattern4: other way.

What is the best way?

if ({ m_access_token is expired? })
    Aws::CognitoIdentityProvider::Model::InitiateAuthRequest request;
    request.AddAuthParameters("USERNAME", m_user_name);
    request.AddAuthParameters("REFRESH_TOKEN", m_refresh_token);
    auto outcome = m_cognito_identity_provider_client->InitiateAuth(request);
    if (outcome.IsSuccess())
        m_access_token = outcome.GetResult().GetAuthenticationResult().GetAccessToken();
  • AWS SDK for C++
  • Visual Studio 2017

Source: Windows Questions C++