Sync SSO node.js implementation

AI-generated summary

The discussion is about implementing Sync SSO in a Node.js application. zcuric provided an example code in Node.js that uses Axios and crypto to create a HMAC SHA-256 signature, which is then sent in a POST request to the Discourse admin API.

However, mathew-exad is experiencing issues with the code. Sometimes, it times out, and sometimes it redirects to a URL with an SSO parameter, displaying the message “You’re all caught up!”. After multiple attempts, the user is now unable to access the admin panel, as it keeps redirecting to the SSO redirect URL, even after clearing browser cache and cookies. The user is seeking help to resolve this issue.

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)
    .update(data)
    .digest('hex');
}

function syncSso() {
  const endpoint = `${config.discourse.url}/admin/users/sync_sso`;
  const params = {
    external_id: 1,
    email: 'bob@example.com',
    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 axios.post(endpoint, 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.