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

cognitoUser.initiateAuth ignores the authentication flow setting #419

Closed
imjustdavid opened this issue Mar 8, 2018 · 21 comments
Closed
Labels
Auth Related to Auth components/category

Comments

@imjustdavid
Copy link

Do you want to request a feature or report a bug?

Potential bug

What is the current behavior?

The function cognitoUser.initiateAuth() ignores the authentication flow setting. It always sends a request specifying a CUSTOM_AUTH flow. When used to implement a lamba user migration trigger as specified in https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-javascript-sdk-user-migration-lambda.html, it causes the lambda user migration not to be invoked, since Cognito is expecting a USER_PASSWORD_AUTH authentication flow.
This can be circumvented by using cognitoUser.authenticateUser() instead, that configures the request considering the authentication flow setting

@yuntuowang
Copy link
Contributor

Hi @imjustdavid, there was a typo in our README.md user case 30. Now it is correct. Thanks!!

@Jun711
Copy link

Jun711 commented Mar 12, 2018

@yuntuowang
Copy link
Contributor

Hi @Jun711, yes, the default flow type is 'USER_SRP_AUTH'. If you want to use the lambda user migration, you need to set flow type as 'USER_PASSWORD_AUTH'.

@mlabieniec mlabieniec added documentation Related to documentation feature requests Auth Related to Auth components/category labels Mar 12, 2018
@Jun711
Copy link

Jun711 commented Mar 12, 2018

thanks @yuntuowang
Will amplify library support the use of 'USER_PASSWORD_AUTH' flow as well in the near future?

@yuntuowang
Copy link
Contributor

Hi @Jun711, we already supported it in amplify library. Please see the use case 30 in the README.md and use the newest version of SDK(v1.32.0).

@Jun711
Copy link

Jun711 commented Mar 12, 2018

@yuntuowang
Right, it is available via amazon-cognito-identity-js.
What if I use the Auth from Amplify library instead of using amazon-cognito-identity-js within Amplify? If I can do it using Auth, could you please point me to the right documentation?
Auth doesn't seem to expose this function.
https://aws.github.io/aws-amplify/api/classes/authclass.html

@yuntuowang
Copy link
Contributor

I see. Hi @mlabieniec, can you answer this question? @Jun711 wants to use the Auth from Amplify library instead of using amazon-cognito-identity-js within Amplify.

@mlabieniec
Copy link
Contributor

@Jun711 are you using a framework i.e. React, Angular etc. Or similar? Or are you using vanilla javascript? If JavaScript, are you using ES2015+ with a transpiler i.e. Babel etc? Just trying to understand your environment so I can make the right recommendation.

Generally, you can check here which will support any JavaScript environment via APIs.

For React you can also use the HOCs.

@Jun711
Copy link

Jun711 commented Mar 12, 2018

@mlabieniec I am using Angular to use migration trigger, it needs 'USER_PASSWORD_AUTH' flow type in authentication. However, this is not exposed via Auth, I think. What is the way around it?
the authenticateUser method can be modified take optional argument?

btw, @yuntuowang , how to import CognitoUser from amazon-cognito-identity-js within Amplify? Is it like the following?
import { CognitoUser } from 'aws-amplify';

@mlabieniec
Copy link
Contributor

You can get the current user with Auth.currentAuthenticatedUser() method. I will look into exposing the password flow options as well here.

@mlabieniec mlabieniec added enhancement and removed documentation Related to documentation feature requests labels Mar 13, 2018
@Jun711
Copy link

Jun711 commented Mar 13, 2018

I was trying to get the current user but I was trying to use amazon-cognito-identity-js within Amplify.
npm install --save amazon-cognito-identity-js
import { CognitoUserPool, CognitoUserAttribute, CognitoUser } from 'amazon-cognito-identity-js';
I guess I have do the above two things to use amazon-cognito-identity-js, right?

Regarding the password, probably something like and use an argument to decide whether to set USER_PASSWORD_AUTH flow will work ?

var user = new CognitoUser({
    Username: username,
    Pool: this.userPool
});
user.setAuthenticationFlowType('USER_PASSWORD_AUTH');

If it works, lambda user migration should be invoked via Auth.signIn method?

Can I use only Amplify library with its dependencies and be able to use Amazon Cognito? (as in without using amazon-cognito-identity-js)

@imjustdavid
Copy link
Author

Thanks a lot @yuntuowang.
Closing the issue then.

@yuntuowang
Copy link
Contributor

Hi @Jun711, you can import in this way:

import { CognitoUser } from 'aws-amplify/node_modules/amazon-cognito-identity-js/lib/';

About the second question, yes. you can follow Use case 30 in README.md.

@Jun711
Copy link

Jun711 commented Mar 14, 2018

thanks @yuntuowang
I think I gonna do a pull request on amplify since I am using amplify for other function as well, I gonna stick with it instead of using cognito identity js directly. Do u recommend using cognito identity directly?
Yea, thanks for the use case 30.

@yuntuowang
Copy link
Contributor

Hi @Jun711, I think using amplify is better for your use case. Sure, you can post a PR and we can review it. Thanks!

@Jun711
Copy link

Jun711 commented Mar 19, 2018

@yuntuowang I am trying to do a pul request.
I wonder if there is any configuration that I need to do before I can run npm test.
I ran npm install in the root directory level; when I ran npm test, I got this error:

Cannot find module 'eslint-config-airbnb-base'
Referenced from: /Users/Jun/Projects/aws-amplify/packages/amazon-cognito-identity-js/.eslintrc.yaml
Error: Cannot find module 'eslint-config-airbnb-base'
Referenced from: /Users/Jun/Projects/aws-amplify/packages/amazon-cognito-identity-js/.eslintrc.yaml

And, there are 2 lock files. Should I run npm install or yarn? Thanks

@portenez
Copy link

I'm a bit confused about the conclusion of this ticket. Is there any way to tell Amplify to use USER_PASSWORD_AUTH? or the solution is to go back to amazon-cognito-identity-js? I'm trying to do this from within REACT

@brendan-lovepop
Copy link

⬆️ on this issue, it doesn't currently seem possible to direct amplify to use USER_PASSWORD_AUTH, which isn't ideal for users that are migrating away from an old system

@shawnlauzon
Copy link

There is a solution now, at least: you can set the authenticationFlowType in the AWS.Amplify configuration object.

See https://aws-amplify.github.io/amplify-js/api/interfaces/authoptions.html

@jarrettj
Copy link

jarrettj commented Apr 1, 2019

Hi,

Good day.

Took me a while to figure this out. But I'm using angular and to set the flow I did the following in my app.component.ts:

import { Auth } from 'aws-amplify';
Auth.configure({
    authenticationFlowType: 'USER_PASSWORD_AUTH'
});

Hope that helps somebody else out there. (who's a noob like me:)

Regards.
Jarrett

@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 13, 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
Projects
None yet
Development

No branches or pull requests

8 participants