Using Verified Permissions with Cognito access token

164 Views Asked by At

I am looking to use Verified Permissions as a tool for authentication and authorization.

I am using the function isAuthorizedWithToken(params = {}, callback) ⇒ AWS.Request.

Verified Permissions requires a Schema for authorization while using a Cognito token as a principal.

How can I create a Schema and what are the criteria? How do I send an authorization request with the required parameters?

import { VerifiedPermissions } from "@aws-sdk/client-verifiedpermissions";


const autherizeWithToken = async () => {
  let accessToken =
    "eyJraWQiOiI0SXhG06UbA9GVV2rLwK4Xjw6iT2-3Leo8ZqSTyVbV6]OrJv46oxdWZms3w1c1Qv_4WgR5AY8hght1lW7I7ffnf4rZVIwP2KmuCoxx_Tfm5MCp0vSp8Suw";

  const idToken =
"eyJraWQiOiZSIsImVtYWlsIjoic2hhZmVlZWVxdWVAZ21haWwuY29tIn0.JZrNjTjDhgIF7NP-AJpF44-SvIUOG7QP0uuXxvSpktQ1pZRNgw";
  try {
    var params = {
      accessToken: accessToken,
      // identityToken: idToken,
      action: {
        actionId: "read" ,
        actionType: "Action" ,
      },
      resource: {
        entityId: "mis",
        entityType: "Module",
      },
    };
    var verifiedpermissions = await new VerifiedPermissions();
    const isAuthorizedWithToken =
      await verifiedpermissions.isAuthorizedWithToken(
        params,
      );
    return isAuthorizedWithToken;
  } catch (error) {
    console.log(error);
  }
};
0

There are 0 best solutions below