Saiyam Jain
Saiyam Jain

Reputation: 41

Get AWS temp token from aws cognito federated identity after client login with firebase google

I'm new to AWS, so please don't mind my stupid question

I m working on a project where I have a ionic react frontend where the user can signin with google as provider using firebase, after that I want to get a temporary aws token so the clinet can access aws services. I'm using aws cognito federated identity to do so. I have added google as Authenticated identity sources while creating my identity pool. Now the issue I m facing is that I m getting this error

NotAuthorizedException: Invalid login token. Issuer doesn't match providerName

Here is my access token that I'm getting from the client

eyJhbGciOiJSUzI1NiIsImtpZCI6ImYwOGU2ZTNmNzg4ZDYwMTk0MDA1ZGJiYzE5NDc0YmY5Mjg5ZDM5ZWEiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiUGxlYXNlIElnbm9yZSIsInBpY3R1cmUiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS9BQ2c4b2NKU0ItZFNBS0loY2VGc2Z1OXdlUTgzWVdKZC12aUp6a0tHNDVKTEJPNTNlZVNYVEpRPXM5Ni1jIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL2lieXRlc3QwMSIsImF1ZCI6ImlieXRlc3QwMSIsImF1dGhfdGltZSI6MTcxOTU5Mzg4MiwidXNlcl9pZCI6InIySVlFUFJPWnNhZDB5ZERQT0prN0ZyVW50ajEiLCJzdWIiOiJyMklZRVBST1pzYWQweWREUE9KazdGclVudGoxIiwiaWF0IjoxNzE5NTkzOTEwLCJleHAiOjE3MTk1OTc1MTAsImVtYWlsIjoieW95bzI5MjA2QGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7Imdvb2dsZS5jb20iOlsiMTEyNjIxOTY4ODI3MTYzMTA2MzU2Il0sImVtYWlsIjpbInlveW8yOTIwNkBnbWFpbC5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJnb29nbGUuY29tIn19.OxrJvKCGi_cEuKjJEUhCwHqLx13Wq2lmKxqC1vvmORhhcPBnknukLVbjNpzjkozfow6j0zKtx07ydD1RRdD79dJ113DDtJeJjsrdKAACfe8m40ymF7Ytlk-oMHI-dltnkSIg6Gv3ZTcYmCTkAe5e6d86T49aSIysoYKRNjrl72L-UjufW_Ozf7lTXOd6d5i4uNdEvcBCui78IY8CpQ3LTKgtSteR1xtEH0hP1TlFJwdrC3u0bY0j2sj2PZYYFlOpeVK3IzEgIIfx6GjXyx77aFHFJtSPiBxXcC1qyUncysIj9ZeNIM4Qc2431OOhpg7-3VkH5p8Lmz0U324I5QAxWQ

And here is the code in my nodejs, express backend that I'm using currently

I have only added relevant code here

const AWS = require("aws-sdk");

AWS.config.update({
  region: "ap-southeast-2",
  accessKeyId: process.env.accessKeyId,
  secretAccessKey: process.env.secretAccessKey,
});

  const { idToken } = req.body;

    const params = {
      IdentityPoolId: "ap-southeast-2:xxxx-xxxx-xxxx-xxxx-xxxx",
      Logins: {
        "accounts.google.com": idToken,
      },
    };

    await new Promise((resolve, reject) => {
      AWS.config.region = "ap-southeast-2";
      AWS.config.credentials = new AWS.CognitoIdentityCredentials(params);

      AWS.config.credentials.refresh((err) => {
        if (err) {
          console.log("err", err);
          reject(err);
        } else {
          console.log("credentials", AWS.config.credentials);
          resolve(AWS.config.credentials);
        }
      });
    });

    res.json({
      AccessKeyId: credentials.accessKeyId,
      SecretAccessKey: credentials.secretAccessKey,
      SessionToken: credentials.sessionToken,
      Expiration: credentials.expiration,
    });

So can anyone help me fix this problem or ask relevant questions so that I can fix this, Please 😢😢

Upvotes: 0

Views: 66

Answers (0)

Related Questions