Closed DeniferSantiago closed 3 years ago
Found out how to access attributes when using Oauth to login:
const user = await Auth.currentAuthenticatedUser();
const attributes = user.signInUserSession?.idToken?.payload;
I noticed this adds some extra properties but it does what I need.
I will not close this issue as I consider that amplify should fill the "attributes" property internally to ensure similar behavior in any type of login.
Hi @DeniferSantiago 👋 That's strange that attributes is not included in the response.
This is what I get when calling Auth.currentAuthenticatedUser
logged in through google OAuth
code
const getUser = async () => {
const { attributes } = await Auth.currentAuthenticatedUser();
console.log(attributes);
};
console log
However, I am using @aws-amplify/auth
, not amazon-cognito-identity-js
. Maybe try with the Auth import from aws-amplify
instead? I think we recommend just using that for Auth now.
I am using the module:
import { Auth } from "aws-amplify";
I am getting:
{
"Session": null,
"authenticationFlowType": "USER_SRP_AUTH",
"client": {
"endpoint": "https://cognito-idp.us-east-1.amazonaws.com/",
"fetchOptions": [Object]
},
"keyPrefix": "CognitoIdentityServiceProvider.vifuv747v73gj48v",
"pool": {
"advancedSecurityDataCollectionFlag": true,
"client": [Client],
"clientId": "vifuv747v73gj48v",
"storage": [Function MemoryStorage],
"userPoolId": "us-east-1_gkfke8e",
"wrapRefreshSessionCallback": [Function anonymous]
},
"signInUserSession": {
"accessToken": [CognitoAccessToken],
"clockDrift": 0,
"idToken": [CognitoIdToken],
"refreshToken": [CognitoRefreshToken]
},
"storage": [Function MemoryStorage],
"userDataKey": "CognitoIdentityServiceProvider.sdfj656fs5efsdf45es.Google_0000000000000000000000.userData",
"username": "Google_0000000000000000000000"
}
I work in React Native.
@DeniferSantiago could you try adding aws.cognito.signin.user.admin
to your scopes in aws-exports
? You should be able to do so from the cli as well if you run amplify update auth
"scope": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
],
The scopes are already added
The scopes are already added
you have the aws.cognito.signin.user.admin
scope specifically as well?
It's missing in the aws-exports
file you shared.
If so, did it make any difference in the return for Auth.currentAuthenticatedUser
?
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.
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication, GraphQL API, Storage
Amplify Categories
auth, storage, api
Environment information
Describe the bug
I need to get attributes of a user when they log in with oauth. Currently Hub.listen returns me some user data like this:
Also I can't access them with:
currentAuthenticatedUser()
Expected behavior
Being able to get the attributes with the auth class.
Reproduction steps
Follow the instructions of: https://docs.amplify.aws/lib/auth/social/q/platform/js try to get user attributes:
const { attributes } = await Auth.currentAuthenticatedUser()
;Code Snippet
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response