amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
424 stars 232 forks source link

amazon-cognito-auth-js breaks amazon-cognito-identity-js import #131

Open FabioDominio opened 6 years ago

FabioDominio commented 6 years ago

Good evening,

I am integrating Cognito into my company platform for authentication and authorization. Currently I have a web app in html5+css+javascript acting as a frontend for a REST server (resource server) offering APIs protected by Cognito web tokens.

Since the platform in the near future will host several micro services, and I need to specifiy custom scopes during the authentication phase, I read that amazon-cognito-auth-js must be used instead of amazon-cognito-identity-js, which I used for the first tests without specifying scopes.

I was able to integrate the authentication by AmazonCognitoIdentity.CognitoAuth, retrieving a valid session if existing or forcing a new login on the Cognito hosted web page otherwise.

The problem is that after a successful authentication I also need to import amazon-cognito-identity-js to set and retrieve user data, but amazon-cognito-identity-js and amazon-cognito-auth-js don't seem they can "live" together as both of them define the AmazonCognitoIdentity and if I import amazon-cognito-auth-js after amazon-cognito-identity-js CognitoUserPool and other classes are no longer defined. The same problem if I invert the imports.

Is it possible to import both libraries without making them break each other? I thought that aws-amplify would solve the problem, but I couldn't find helpful documentation to make it work browser side as it seems it only works with React or maybe Angular.

Thanks.

Elayaraja-Dhanapal commented 6 years ago

I have the same problem!

chjalmar commented 5 years ago

Hi! I have the same problem. Arrived at the same point as @FabioDominio and can make these two libraries in a browser javascript app.

1.- If I include amazon-cognito-auth-js after amazon-cognito-identity: I can process the login at callback from the Hosted UI with AmazonCognitoIdentity.CognitoAuth.parseCognitoWebResponse, so the Sign in is successful; but then I can't access AmazonCognitoIdentity.CognitoUserPool(), so getCurrentUser always returns null;

2.- If I include amazon-cognito-identity after amazon-cognito-auth-js (or don include auth at all): 2.1. If I had already signed in using what's described in 1, I can use AmazonCognitoIdentity.CognitoUserPool to getCurrentUser, and it works, so I suppose I could get user attributes afterwards; but 2.2. If I had not signed in before, the callback from the hosted UI does not process the token or creates any session.

Is there another version of these libraries that I am not aware of, that would allow me to implement Cognito Identity with a Hosted UI in a javascript/web site?

What am I missing?

Thanks in advance... cc. @yuntuowang

askaliuk commented 5 years ago

I have the same issue

ronnyroeller commented 5 years ago

+1

jgubo commented 5 years ago

+1 Anybody already has a solution to this? I also really need to be able using the Auth SDK but in the same application/page have to get access to the UserPool User and his Attributes.

Thanks a lot!

rochar commented 5 years ago

+1