# Sync SSO node.js implementation

**URL:** https://meta.discourse.org/t/sync-sso-node-js-implementation/168333
**Category:** SSO
**Created:** [October 26, 2020, 11:26am UTC](https://meta.discourse.org/t/sync-sso-node-js-implementation/168333 "2020-10-26T11:26:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zcuric](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zcuric/32/292837_2.png) [@zcuric](https://meta.discourse.org/u/zcuric)
#### Post date: [October 26, 2020, 11:26am UTC](https://meta.discourse.org/t/sync-sso-node-js-implementation/168333/1 "2020-10-26T11:26:57Z")

</div>

Here is example with **NodeJS** if anyone needs it:

```js
'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);
}

```

---

<div class="post-metadata">

### Author: ![mathew-exad](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@mathew-exad](https://meta.discourse.org/u/mathew-exad)
#### Post date: [November 10, 2022, 3:16pm UTC](https://meta.discourse.org/t/sync-sso-node-js-implementation/168333/2 "2022-11-10T15:16:43Z")

</div>

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](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.

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/c/c/dcc73c49ab7302b8c58a586e65873c6e5f943b9d.png)
