Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access federated user's attribute from user pool #3959

Closed
codeinaire opened this issue Sep 2, 2019 · 4 comments
Closed

Access federated user's attribute from user pool #3959

codeinaire opened this issue Sep 2, 2019 · 4 comments
Labels
Auth Related to Auth components/category Cognito Related to cognito issues question General question

Comments

@codeinaire
Copy link

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

amazon-cognito-identity-js

** What AWS Services are you utilizing? **

AWS Cognito (user pools only), AWS API Gateway, and AWS Lambda.

** Provide additional details e.g. code snippets **

BACKGROUND

I'm using the above mentioned package to create an auth flow only using user pools. I'm using user pools as a user management system AND a way to federate through third party identity providers. I want to do this b/c a user pool will map a third party provider's details to itself once the user has signed-in through the third party.

I've created a custom sign-in button with help from the suggestions from this issue. I'm successfully able to log in with a third party provider, receive the idToken, and invoke the API Gateway with the idToken. This is great and exactly what I want to do.

ISSUE/SQUESTIONS

1. How am I able to access a federated user's attributes from the user pool in which they have been mapped?

I'm able to get a non-federated user's attributes using the getCurrentUser() method. It looks like this is b/c it retrieves a bunch of useful information from local storage put in there by the authenticateUser() method.

But I haven't been able to figure out how to get a federated user's attributes from the user pool. I signed in with my federated user and tried to use the authenticateUser() method, but I just got a null value. I didn't store the two access keys I got from the federated signin into my local storage.

2. Do I need to store the tokens I got from the federate sign-in into local store and then call getCurrentUser()?

In this issue @powerful23 suggested a way to parse the response from a federated sign in, however, it uses the amazon-cognito-auth-js. It is my understanding that amazon-cognito-identity-js is the library to use for more customised auth flow.

3. Do I have to use the amazon-cognito-auth-js library to achieve this? Or can I used the amazon-cognito-identity-js library?

One last question regarding the functionality of mapping federated user's attributes to the user pool.

4. If I cannot access a federated user's attributes why are they even mapped to the user pool??

Thanks in advanced for any help!

@haverchuck haverchuck added Cognito Related to cognito issues Auth Related to Auth components/category question General question labels Sep 3, 2019
@ajhool
Copy link

ajhool commented Nov 27, 2019

@haverchuck Piggybacking on this to point out that the amazon-cognito-auth-js package appears to be no longer supported ( amazon-archives/amazon-cognito-auth-js#214 ) by AWS. When people ask questions about that package, they are redirected to the Amplify team, but the Amplify team has left this question unanswered for 2+ months.

Being that Amplify is built on top of that package, what is the path forward?

Auth + user management is arguably the most important part of any app and it is disappointing to see AWS let the main sdk for a core & critical service go for 9+ months without resolving issues -- without announcement.

@haverchuck
Copy link
Member

haverchuck commented Dec 16, 2019

@codeinaire @ajhool Amplify uses amazon-cognito-identity-js for most functionality related to User Pools. If you don't want to use Amplify, you can still use the amazon-cognito-identity-js sdk for most uses cases with some extra leg work.

To get the user data, try starting with something like this:

import React from 'react';
import { CognitoUserPool } from 'amazon-cognito-identity-js';
import awsconfig from './aws-exports';

const userData = async () => {
  let userpool = new CognitoUserPool({
    UserPoolId: awsconfig.aws_user_pools_id,
    ClientId: awsconfig.aws_user_pools_web_client_id
  });
  const user = await userpool.getCurrentUser();
  console.log('user', user)
}

export default function App() {
  return (
    <div className="App">
      <button onClick={() => userData()}>Get my user data!</button>
    </div>
  )
}

@stale
Copy link

stale bot commented Dec 23, 2019

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

@stale stale bot closed this as completed Dec 23, 2019
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Auth Related to Auth components/category Cognito Related to cognito issues question General question
Projects
None yet
Development

No branches or pull requests

3 participants