Sync SSO node.js implementation

Here is example with NodeJS if anyone needs it:

'use strict';

const axios = require('axios');
const crypto = require('crypto');
const qs = require('querystring');
const config = require('./config');

function getHash(data, secret) {
  return crypto.createHmac('sha256', secret)

function syncSso() {
  const endpoint = `${config.discourse.url}/admin/users/sync_sso`;
  const params = {
    external_id: 1,
    email: '',
    username: 'bob',
    add_groups: 'eurorack',
    require_activation: true
  const headers = {
    'Api-Key': config.discourse.apiKey,
    'Api-Username':  config.discourse.apiUsername,
    'Content-Type': 'multipart/form-data'
  const sso = Buffer.from(qs.stringify(params)).toString('base64');
  const sig = getHash(sso, config.discourse.ssoSecret);
  return, qs.stringify({ sso, sig }), { headers })
    .then(({ data }) => data)
    .catch(err => err);

Hi, I tried the above piece of code in my node application and it was working fine about on redirect to http://localhost:4200/?sso=bm9uY2U9OTRiNzM1ODU1NDUxOTBmNTE3YWE1NzM0YjA5MDFiODQmcmV0dXJuX3Nzb191cmw9aHR0cCUzQSUyRiUyRmxvY2FsaG9zdCUzQTMwMDAlMkZzZXNzaW9uJTJGc3NvX2xvZ2lu&sig=9fdb6d9f8bd91005d3612c476c91c2acbb650b5532feb9eb131405e2bbe0c0c2

Its give me timeout sometime and sometime I am getting “You’re all caught up!”.

After few tried now I am unable to even access the admin panel at my localhost:4200 it keep redirecting to above URL.

I already clear the cache, and cookies of my browser.

Please help.

Every time I am getting this only. Event I am not able to access my admin panel on click on login button it redirection to SSO redirect URL.