question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to retrieve information about roles attached to user?

See original GitHub issue

** Which Category is your question related to? ** Auth

** What AWS Services are you utilizing? ** AppSync, Cognito

** Provide additional details e.g. code snippets ** In out application we want authentication with AWS Cognito identity pool with Google provider. We also using role rules claims to map roles to users by their emails.

The frontend code to login look like this:

export function logIn() {
  const ga = window.gapi.auth2.getAuthInstance();
  return new Promise((resolve, reject) => {
    ga.signIn().then(
      async (googleUser) => {
        console.log({googleUser});
        const gaResp = googleUser.getAuthResponse();
        console.log({gaResp});
        const { id_token, expires_at } = gaResp;
        const user = {
          email: 'asdasdasd',
          name: 'ssssssssssssss',
        };
        const credentials = await Auth.federatedSignIn(
          'google',
          { token: id_token, expires_at },
          user,
        );
        resolve();
        console.log({credentials});
      },
      (error) => {
        console.log(error);
      },
    );
  });
}

This will popup a google window asking what account user what to use for authentication and will back with token_id which is then used to Auth.federatedSignIn to get credentials needed for appSync client.

How now client can get information about roles attached to him using identity pool role rules claims? Client should know his role to be able to render only relevant part on interface.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
rawarscommented, Mar 9, 2021

Auth.currentAuthenticatedUser() .then((userData) => { console.log(userData.signInUserSession.accessToken.payload[“cognito:groups”]); }) .catch(() => console.log(“Not signed in”));

0reactions
pedromagalhaescommented, Jan 2, 2022

Also works

Auth?.user?.signInUserSession?.accessToken?.payload["cognito:groups"]

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Check User Roles in SQL Server - Netwrix
Listing SQL Server roles for a user. Start Microsoft SQL Server Management Studio (MSSMS). On the File menu, click Connect Object Explorer.
Read more >
View Roles Assigned to Users - Auth0
Go to Dashboard > User Management > Users and click the name of the user to view. Auth0 Dashboard List of Users ·...
Read more >
List Azure AD role assignments for a user - Microsoft Learn
Sign in to the Azure portal or Azure AD admin center. · Select Azure Active Directory > Users > user name > Assigned...
Read more >
How to Show All Oracle Database Privileges for a User - Chartio
Retrieving all user privileges within Oracle can range from a simple task using a ... GRANTEE is the name, role, or user that...
Read more >
Retrieve User assigned Roles with user information...
Retrieve User assigned Roles with user information using Query Expression , C# in Dynamics 365. ... Sometimes we may need to retrieve login...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found