title: How to SSO in another domain using express server/react client and redirect to another domain?
body: <p>Problem is to create a web app that has a form that sends it to my <strong>express</strong> server, generates a token from external endpoint post with form value, uses token from external domain to make a post to external endpoint to then get <strong>authenticated into external domain</strong>.</p>
  
  <p>I am able to generate token on my express server, make the second post with token to external endpoint and able to login and see the response on express server.</p>
  
  <p>However, when I try to redirect my react client to the external domain, it shows a timeout message.</p>
  
  <p>I've tried making the 2nd post from client with Axios and Fetch and then redirect to external domain, but it gives me CORS errors, until I turn on CORS chrome plugin, then it still gives me the same timeout message.</p>
  
  <p>I've tried adding different headers to my post call to allow redirects, but no success.</p>
  
  <pre class="lang-js prettyprint-override"><code>const router = require('express').Router();
  const xml2js = require('xml2js');
  const parseString = require('xml2js').parseString;
  const request2 = require('request');
  // const axios = require('axios')
  var setCookie = require('set-cookie-parser')
  var Cookies = require('js-cookie')
  require('dotenv').config();
  
  router.post('/sso', (req, response, next)=&gt;{
  
    // SETTING UP XML BODY FOR TOKEN GENERATOR
  
    // USING TEMPLATE TO BUILD XML BODY FOR TOKEN GENERATOR
  
    // SETTING UP POST TO TOKEN GENERATOR WITH XML TEMPLATE
  
    // DECLARING TOKEN TO PASS TO SSO POST
  
    // PROMISE FOR RESPONSE POST TO TOKEN GENERATOR
    return new Promise((resolve)=&gt;{
  
      // ERROR CATCH BLOCK FOR POST TO TOKEN GENERATOR
      try {
  
        // POST TO TOKEN GENERATOR USING XML TEMPLATE
        request2(TokenGenerator,
          (err, res, body)=&gt;{
            // PARSE TOKEN GENERATOR BODY RESPONSE
  
                // CONVERTING TO STRING SOAP BODY
  
                // PARSING STRING INTO JSON TO TARGET TOKEN
  
                // DECLARING TOKEN RESPONSE IN RES WITH TOKEN VALUE FROM POST TO TOKEN GENERATOR
  
                // ASSIGNING IT TO GLOBAL VARIABLE
  
              })
  
            // TRYING POST FROM CLIENT HAS BEEN COMMENTED OUT
            // // response.send(token)
            // // next()
  
            // SETTING UP POST TO PARTICIPANT SSO WITH TOKEN VALUE
            const secondPostToSSO = {
              method: 'POST',
              url: 'externaldomain.com/sso.aspx',
              followAllRedirects: true,
              jar: true,
              headers: {
                'Content-Type': 'text/html'
              },
              form: {
                'TOKEN': token
              }
            }
  
            // POST TO PARTICIPANT SSO WITH TOKEN
            request2.post(secondPostToSSO,(err, response2, body2)=&gt;{
                 console.log(response2.request)
  
                 var cookies = setCookie.parse(response2, {
                   decodeValues: true,
                   map: true
                 })
  
                 console.log(cookies)      
  
  
  
  
                 next()
               })
  
            })
  
      } catch (e) {
        console.error(`[FATAL ERROR] - KAPUT - ${e}`)
        return res.redirect('/')
      }
  
    })
  
  })
  
  module.exports = router
  </code></pre>
  
  <p>I expect the output of the server post to then redirect the client to the externaldomain.com where I'm getting the token, and making post with token to authenticate client. The outcome should be that the client has been logged from my web app to the external domain.</p>