简体   繁体   中英

How to use AWS Cognito with Nodejs UI app and Oauth 2.0 flow using passport js?

I am stuck at finding values of authorizationURL:,tokenURL: for aws cognito passportjs auth flow.It would be helpful if I get such snippet.Trying to fetch the profile, phone and other details from aws cognito ui in the backend application.

passport.use(new OAuth2Strategy({
    authorizationURL: 'https://www.example.com/oauth2/authorize',
    tokenURL: 'https://www.example.com/oauth2/token',
    clientID: EXAMPLE_CLIENT_ID,
    clientSecret: EXAMPLE_CLIENT_SECRET,
    callbackURL: "http://localhost:3000/auth/example/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

The values for the tokenURL and authorizationURL are found in the Cognito settings in the AWS Console User Pool and Cognito documentation.

You can obtain the domain name from the Cognito config in the AWS Console under Cognito->User Pools->App Integration->Domain Name and tack on the endpoints from the documentation as follows. For example:

authorizationURL: 'https://your-domain-prefix.auth.us-east-1.amazoncognito.com/oauth2/authorize',

tokenURL: 'https://your-domain-prefix.auth.us-east-1.amazoncognito.com/oauth2/token',

Amazon AWS Documentation for Cognito Endpoints https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-userpools-server-contract-reference.html

Passport Documentation: http://www.passportjs.org/docs/oauth/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM