# Sync DiscourseConnect user data with the sync\_sso route \[JavaScript\]

**URL:** https://meta.discourse.org/t/sync-discourseconnect-user-data-with-the-sync-sso-route-javascript/260841
**Category:** Administrators
**Tags:** sso, rest-api, tutorial
**Created:** [April 6, 2023, 2:21pm UTC](https://meta.discourse.org/t/sync-discourseconnect-user-data-with-the-sync-sso-route-javascript/260841 "2023-04-06T14:21:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![GregorSondermeier](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gregorsondermeier/32/299039_2.png) [@GregorSondermeier](https://meta.discourse.org/u/GregorSondermeier)
#### Post date: [April 6, 2023, 2:21pm UTC](https://meta.discourse.org/t/sync-discourseconnect-user-data-with-the-sync-sso-route-javascript/260841/1 "2023-04-06T14:21:51Z")

</div>

Hello,

for my company I needed to make use of this feature from our Node.js backend, so here is a reference implementation in JavaScript using Node.js’s [cypto](https://nodejs.org/api/crypto.html) and [Buffer](https://nodejs.org/api/buffer.html) if anyone is interested:

Note:  
For consistency I’m using the same variable values as in the [PHP implementation](https://meta.discourse.org/t/sync-discourseconnect-user-data-with-the-sync-sso-route/84398).

### Setup your API credentials and SSO secret key

```js
const apiKey = '4fe83002bb5fba8c9a61a65e5b4b0a3cf8233b0e4ccafc85ebd6607abab4651a';
const apiUser = 'system';
const connectSecret = 'jdhb19*Xh3!nu(#k';

```

### Setup the sso parameters

```js
const ssoRecord = new URLSearchParams({
  external_id: 1,
  email: 'bob@example.com',
  username: 'bob',
  add_groups: 'eurorack',
  require_activation: true,
}).toString();

const ssoPayload = Buffer.from(ssoRecord, 'utf8').toString('base64');
const signature = crypto.createHmac('sha256', connectSecret).update(ssoPayload).digest('hex');

```

### Send the POST request

```js
const updatedUser = await fetch({ // or axios
  method: 'POST',
  url: 'https://forum.example.com/admin/users/sync_sso',
  headers: {
    'Api-Key': apiKey,
    'Api-Username': apiUser,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    sso: ssoPayload,
    sig: signature,
  })
}).then((response) => response.json());

```
