amazon-cognito-auth-js icon indicating copy to clipboard operation
amazon-cognito-auth-js copied to clipboard

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

Open FabioDominio opened this issue 7 years ago • 6 comments

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.

FabioDominio avatar May 08 '18 21:05 FabioDominio

I have the same problem!

Elayaraja-Dhanapal avatar May 17 '18 18:05 Elayaraja-Dhanapal

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

chjalmar avatar Sep 28 '18 15:09 chjalmar

I have the same issue

askaliuk avatar Nov 02 '18 21:11 askaliuk

+1

ronnyroeller avatar Jan 18 '19 16:01 ronnyroeller

+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!

jgubo avatar Feb 15 '19 08:02 jgubo

+1

rochar avatar Jun 25 '19 09:06 rochar