-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Cognito Hosted UI documentation (and components) improvements #705
Comments
@OlivierPT thanks for the feedback. Do you have any suggestions on what might make it more clear for us to add? Once the hosted UI returns back, the JWT tokens (if using token grant) get injected into the Cognito session and things continue as usual (just as if you logged in using or simlar. There is also a react component: The button really only constructs a link with the configuration parameters. React native requires a native module and we haven't gotten to supporting this yet in aws-amplify-react-native. As far as the interface, we are trying to keep this generic (not so cognito specific) because we plan on supporting other authentication providers in the future, so we tried to follow OAuth nomenclature and specifications when defining the parameters. Please let us know your suggestions in the meantime or feel free to submit a PR. |
Hi @mlabieniec With the Authenticator component, there is a state that manage the display of the different authentication components when needed and the app when authentication ok. I am pretty sure this kind of precision will be helpful for many developper to save time and use the Amplify lib in the best way possible :) Thank you |
@OlivierPT do you have a federated identity pool to provide credentials? |
Hi @powerful23, On the AWS side, I have:
Signin and signup to the User Pool with Amplify Authenticator is working well and since I would like to also allow authentication with Google, I am trying to use the Oauth component. Thanks, |
@OlivierPT can you open the debug mode and search for 'Cognito Hosted authentication result' which would happen if your callback url is parsed correctly? Or there will be a message saying 'Error in cognito hosted auth response' |
Hi @powerful23, I had a deeper check with debug mode (actually console logs with "window.LOG_LEVEL = 'DEBUG' activated, right?) At the end of the authentication process, I can't find any log with 'Cognito Hosted authentication result' or 'Error in cognito hosted auth response'. Maybe I should give more details about my configuration to help to understand the issue. package.json:
I encapsulated my App component in the following AppWithAuth component: Oauth configuration: From the authentication screen, there is a "Sign with AWS" button that I can use to open the Cognito Hosted UI. From there, I can do the sign-in with Google. So, this is looking pretty well with the example in the documentation except that I use the Authenticator component to hide the application when the user is not logged in (and also to continue to login while the hosted UI is not working). After the login process with Google, the user is added in the Cognito UserPool with all the mapped attributes but I am redirected to the Application sign-in screen without be logged in. The result is the same if I login with the Cognito UserPool user. So I hope it will you to understand the issue. |
@OlivierPT I doubt the format of callback url you got might not be valid. The reason why I want to see the debug info mentioned above is because when parsing the callback url, it should trigger either a success callback or a failure callback. Since you are not seeing any of those, maybe it is caused by this line which will end silently if the callback url is neither in code type or in token type. So could you paste the callback url here? |
Hi, Here is the callback url I get :
|
@OlivierPT the url looks fine to me. Can you check the followings:
Thanks |
Hi,
Can you tell me which component is in charge of calling the parsing of the URL and the token? It is like something is missing and it is not done on the client side. Thanks |
Maybe you can try reinstall aws-amplify and see if |
Hi @powerful23, I did reinstall full aws-amplify and aws-amplify and now the authentication is working with OAuth! It seems like it was only an installation/dependency issue at the end. Sorry to have bothered you guys and thank you for you support. The Thank you again! |
Cool, will add that. |
Thank god I found this thread. Was very confused about how to process the response from oauth. However, I'm still concerned that it's an automagic process that happens on its own time. I think you'll find that most people want to run the parsing and config init themselves, as we then direct our apps to respond to the init event. If we don't have a callback for that, then our app just sits there stupid, not knowing if/when the login was successful. Or have I missed something? E.g., In about a tenth of a second it processes the hash ( |
@jamesoflol good point. We have a So you can listen on |
Oh rad, thanks Zhuo! I've just now seen it in the "subscribing to events" section - my bad. |
@powerful23 When using the /login endpoint and "token" grant the Access and ID tokens are both returned on the URL after logging in. However, only the accessToken is automatically written to localStorage which causes an error with Auth.configure: "Error: Local storage is missing an ID Token, Please authenticate". Is this a bug? |
@sbrickner can you provide some code snippets about how are u using the feature? Also you can open the debug mode to find more logging info. |
@powerful23 I am using the GET /login endpoint with the appended fields it needs. I paste the link in the broswer and it brings up the hosted UI. I log in and then it redirects to my app. The code is just the auth.configure() with the correct config values. The idToken and accessToken are on the URL but only the accessToken gets written to localStorage on it's own which causes the error below. Below is the console log. |
@sbrickner can you check the parsing result object which is appended after this message: 'Cognito Hosted authentication result' |
@powerful23 The issue I'm experiencing is that there is no object. I only get the error you see there at the bottom of the logs. If I take the id_token from the response url and manually write it to the .idToken localStorage key and refresh then it finds a user and returns the object but the session property is always null. I have tried listening to the various events with the Hub class but unless I dispatch the event myself the onHubCapsule is never triggered. Is there an example somewhere that is using the Hosted UI with the implicit token flow? Additional Notes:
|
@powerful23 Basically the documentation provided regarding ReactJS and hosted UI is partially "crap"! Sorry to say this, but it is full of errors and misleading information. Try creating a new ReacJS app, that uses the hosted UI with the |
@jonasao sorry to hear this is been so challenging. I was able to just spin one up with the hosted ui and did notice one issue with the config code snippet that seemed to cause some issues. I fixed that in the docs, and everything seems to be working for me right now. Can you provide some feedback on how you suggest we improve the doc so we can make the changes/updates that caused you issues? |
Please reopen this and provide better documentation on angular implementation of amplify auth. |
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 |
Do you want to request a feature or report a bug?
Feature request for documentation improvements and more complete Amplify components
What is the current behavior?
The existing documentation for the Cognito Hosted UI/Oauth is not complete enough in order to be easily used. It only explains how to launch the Cognito Hosted UI but not how to manage user credentials within the application via Amplify.
What is the expected behavior?
It would be highly valuable to have a more complete documentation which provides the full process to authenticate and manage credentials.
Then, it would also be great to have Amplify components to fully work with Cognito Hosted UI/Oauth for React, React native, Angular...
Thanks
The text was updated successfully, but these errors were encountered: