title: How to use AWS Cognito as a provider in Passport?
body: <p>I have a Javascript backend (NestJS with Express + Passport).</p>
  <p>I would like to outsource the complexity of authentication (e.g. social auth) to Cognito but avoid getting locked in. I was wondering if I can use Cognito as a provider in Passport, similar to social providers (Google, Facebook, etc). That way, I could integrate many providers with the effort of integrating just one. I would still manage user data, authorization, etc in my own app, therefore, if I wanted to in the future, I could implement Google, Facebook, etc. social auth in my own app and get rid of Cognito.</p>
  <p>If I understand it correctly <a href="https://github.com/auth0/passport-auth0" rel="nofollow noreferrer">this is possible with Auth0</a>.</p>
  <p>Ideally, I would like to implement an OAuth flow where the user is redirected to a simple &quot;sign up / log in&quot; Cognito app, logs in, gets redirected to a callback URL in my app where I receive user data. If AWS doesn't host a solution for this, I can also use their UI elements to build &amp; host this app.</p>
  <p>If implemented as a provider / strategy, this could be as simple as:</p>
  <pre class="lang-js prettyprint-override"><code>passport.use(new CognitoStrategy({
      key: KEY,
      secret: SECRET,
      callbackURL: &quot;http://www.example.com/auth/cognito/callback&quot;
    },
    function(token, tokenSecret, profile, done) {
        User.findOrCreate({ uuid: profile.id }, function (err, user) {
          return done(err, user);
        });
    }
  ));
  
  app.get('/auth/cognito', passport.authenticate('cognito'));
  app.get('/auth/cognito/callback', 
    passport.authenticate('cognito', { failureRedirect: '/auth/cognito' }),
    function(req, res) {
      res.redirect('/');
    });
  </code></pre>
  <p>Is there a solution for this? Does this make sense in principle? Am I missing any complexity in the many-for-one idea?</p>
  <p>Related resources:</p>
  <ul>
  <li><a href="https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js" rel="nofollow noreferrer">https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js</a></li>
  <li><a href="https://brightinventions.pl/blog/using-cognito-with-nest-js" rel="nofollow noreferrer">https://brightinventions.pl/blog/using-cognito-with-nest-js</a></li>
  <li><a href="https://stackoverflow.com/questions/61507434/nestjs-angular-cognito-flow">NestJs/Angular/Cognito flow</a></li>
  </ul>