Getting [Error: Credential is missing] using @aws-sdk/client-verifiedpermissions with AWS Cognito for getting Permissions

29 views Asked by At

I am using the IsAuthorizedWithTokenCommand Command from @aws-sdk/client-verifiedpermissions to get authorization using the identity token generated by cognito, but i am getting the error: IsAuthorizedWithToken error: Error: Credential is missing. What can i do? I already read the documentation, but i'm still lost. This is my code:

export function getUserPermission(user: AmplifyUser): boolean | null {
  if (!user) return null;

  const verifiedPermissionsClient = new VerifiedPermissionsClient({
    region: import.meta.env.VITE_POLICYSTOREREGION
  });

  const idToken = user.getSignInUserSession()?.getIdToken().getJwtToken();

  const input: IsAuthorizedWithTokenCommandInput = {
    identityToken: idToken,
    policyStoreId: import.meta.env.VITE_POLICYSTOREID,
  };
  const command = new IsAuthorizedWithTokenCommand(input);

  verifiedPermissionsClient.send(command)
    .then((response) => {
      console.log("IsAuthorizedWithToken response: ", response);
    })
    .catch((error) => {
      console.error("IsAuthorizedWithToken error: ", error);
    });

  return null;
}

I already tried to pass the acessToken as parameter of IsAuthorizedWithTokenCommandInput, but doesn't work either.

0

There are 0 answers