# /admin/users/sync\_sso ... Route not found

**URL:** https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819
**Category:** SSO
**Created:** [April 20, 2018, 5:26pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819 "2018-04-20T17:26:35Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Nopsled](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nopsled/32/120092_2.png) [@Nopsled](https://meta.discourse.org/u/Nopsled)
#### Post date: [April 20, 2018, 5:26pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/1 "2018-04-20T17:26:36Z")

</div>

Any idea why I’m getting this when trying to issue a POST request?

ActionController::RoutingError (No route matches [POST] “/admin/users/sync\_sso”)

Thanks!

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [April 20, 2018, 5:34pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/2 "2018-04-20T17:34:19Z")

</div>

Well the route is that one.

Are you passing `api_username` and `api_key` as query params too?

---

<div class="post-metadata">

### Author: ![Nopsled](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nopsled/32/120092_2.png) [@Nopsled](https://meta.discourse.org/u/Nopsled)
#### Post date: [April 20, 2018, 5:40pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/3 "2018-04-20T17:40:06Z")

</div>

I am. Here is the code block. This is the exact say thing I’m doing in my SSO login route. Only difference is obviously the URI.

```plaintext
     const sso = new DiscourseSSO(SSOKey);
            const nonce = 'dummy data';
            const userparams = {
              nonce,
              external_id: user._id.toString(),
              email: user.email,
              username: user.username.replace(/\s/g, ''),
            };
            console.log(userparams);
            const q = sso.buildLoginString(userparams);
            fetch('https://community.testsite.com/admin/users/sync_sso', { method: 'POST', body: q })
              .then(res => res.json())
              .then(json => console.log(json));

```

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [April 20, 2018, 5:42pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/4 "2018-04-20T17:42:28Z")

</div>

You aren’t passing `api_username` and `api_key`.

You need those as query params.

You can check our #howto in the topic here: [Sync DiscourseConnect user data with the sync\_sso route](https://meta.discourse.org/t/sync-sso-user-data-with-the-sync-sso-route/84398)

---

<div class="post-metadata">

### Author: ![Nopsled](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nopsled/32/120092_2.png) [@Nopsled](https://meta.discourse.org/u/Nopsled)
#### Post date: [April 20, 2018, 5:44pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/6 "2018-04-20T17:44:54Z")

</div>

sso.buildLoginString is doing that.

```
discourse_sso.prototype.buildLoginString = function(params) {
	if(!("external_id" in params)) {
		throw new Exception("Missing required parameter 'external_id'");
	}
	if(!("nonce" in params)) {
		throw new Exception("Missing required parameter 'nonce'");
	}
	if(!("email" in params)) {
		throw new Exception("Missing required parameter 'email'");
	}
	
	var payload = new Buffer( querystring.stringify(params) , 'utf8').toString("base64");
	var hmac = this.getHmac();
	hmac.update(payload);
	
	return querystring.stringify({
		'sso': payload,
		'sig': hmac.digest('hex')
	});

```

Using this node package for SSO login. Which works perfectly. Trying to repurpose that for this …

[https://github.com/ArmedGuy/discourse\_sso\_node](https://github.com/ArmedGuy/discourse_sso_node)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [April 20, 2018, 5:47pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/7 "2018-04-20T17:47:45Z")

</div>

> [@Nopsled](#):
>
> sso.buildLoginString is doing that.

Where? I don’t see `api_username` and `api_key` anywhere.

---

<div class="post-metadata">

### Author: ![Nopsled](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nopsled/32/120092_2.png) [@Nopsled](https://meta.discourse.org/u/Nopsled)
#### Post date: [April 20, 2018, 5:53pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/8 "2018-04-20T17:53:19Z")

</div>

Right. I was adding in as form data before. Here is the updated. Still getting the Route Not Found error in the rails logs though.

```
 const userparams = {
          nonce,
          api_username: someusername,
          api_key: somekey,
          external_id: user._id.toString(),
          email: user.email,
          username: user.username.replace(/\s/g, ''),
        };

```

---

<div class="post-metadata">

### Author: ![Nopsled](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nopsled/32/120092_2.png) [@Nopsled](https://meta.discourse.org/u/Nopsled)
#### Post date: [April 20, 2018, 10:35pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/9 "2018-04-20T22:35:42Z")

</div>

**Code that produces the bottom query:**

```
const userparams = {
      external_id: user._id.toString(),
      email: user.email,
      username: user.username.replace(/\s/g, ''),
    };
    const payload = new Buffer(querystring.stringify(userparams), 'utf8').toString('base64');
    const hmac = crypto.createHmac('sha256', DiscourseSSOKey);
    hmac.update(payload);
    const query = querystring.stringify({
      sso: payload,
      sig: hmac.digest('hex'),
      api_username: UserName,
      api_key: API Key,
    });
    console.log(query);
    fetch('https://community.somesite.com/admin/users/sync_sso', {
      method: 'POST',
      body: query,
    })
      .then(res => res.json())
      .then(json => console.log(json));    

```

**Here’s the query that gets generated and passed as the body on the POST route:**

sso=somelongSSOgenerated.&sig=somelongsignature&api\_username=someusername&api\_key=someAPIKey

This all still gives me a Route Not Found error in the rails logs.

---

<div class="post-metadata">

### Author: ![Nopsled](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nopsled/32/120092_2.png) [@Nopsled](https://meta.discourse.org/u/Nopsled)
#### Post date: [April 21, 2018, 2:23pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/10 "2018-04-21T14:23:06Z")

</div>

Any thoughts on the above? Does that look right?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [April 23, 2018, 6:24am UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/11 "2018-04-23T06:24:54Z")

</div>

You’re delivering the wrong Content-Type. Try providing the object directly as the body to fetch, without `querystring.stringify`.

also, hang on a sec, i’m going to let you finish, but URLSearchParams is the best browser api of 2016

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [April 23, 2018, 10:02pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/12 "2018-04-23T22:02:30Z")

</div>

> [@Falco](#):
>
> You need those as query params.

> [@Nopsled](#):
>
> Here’s the query that gets generated and passed as the body on the POST route:
> 
> sso=somelongSSOgenerated.&sig=somelongsignature&api\_username=someusername&api\_key=someAPIKey

The api\_\* parameters need to be in the query parameters, **not** the POST body.

So you need something like:

```plaintext
fetch('https://community.testsite.com/admin/users/sync_sso?api_username=USERNAME&api_key=KITTENS', { method: 'POST', body: body })

```

---

<div class="post-metadata">

### Author: ![Nopsled](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nopsled/32/120092_2.png) [@Nopsled](https://meta.discourse.org/u/Nopsled)
#### Post date: [April 24, 2018, 8:41pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/13 "2018-04-24T20:41:30Z")

</div>

Ah understood. So the api\_username and api\_key in the query parameters and the rest in the post body.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [April 24, 2018, 9:46pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/14 "2018-04-24T21:46:15Z")

</div>

> [@supermathie](#):
>
> The api\_\* parameters need to be in the query parameters, not the POST body.

> [@Nopsled](#):
>
> So the api\_username and api\_key in the query parameters and the rest in the post body.

They can also be in the body

All my Postman requests have them in the body:

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/4/b4cca0652314d7df98d70684eb5bb4d31d219d30.png)

Unless this route is special?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [April 24, 2018, 9:59pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/15 "2018-04-24T21:59:06Z")

</div>

> [@blake](#):
>
> Unless this route is special?

It’s not. The WordPress plugin sends the api parameters for the `sync_sso` route in the body of the request: [wp-discourse/lib/sso-provider/discourse-sso.php at main · discourse/wp-discourse · GitHub](https://github.com/discourse/wp-discourse/blob/master/lib/sso-provider/discourse-sso.php#L329)

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [April 24, 2018, 9:59pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/16 "2018-04-24T21:59:51Z")

</div>

That’s correct, the problem was sending the wrong body type so the api\_username/api\_key couldn’t be parsed out.

---

<div class="post-metadata">

### Author: ![shahidmir](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@shahidmir](https://meta.discourse.org/u/shahidmir)
#### Post date: [May 24, 2018, 11:46am UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/17 "2018-05-24T11:46:12Z")

</div>

Hi

I am attemping the SSO sync but getting the no route found error. Im trying via postman.  
I have tried adding the key and username both in the body and as request params, but same result.

 ![40](https://global.discourse-cdn.com/meta/original/3X/5/a/5a4519d537257298bd65872a3a8d0a16b9fa478d.png) ![57](https://global.discourse-cdn.com/meta/original/3X/1/a/1a1f7e2379df2f8497cd69ab0a965319c725d01e.png)

any ideas?

---

<div class="post-metadata">

### Author: ![shahidmir](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@shahidmir](https://meta.discourse.org/u/shahidmir)
#### Post date: [May 24, 2018, 2:16pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/18 "2018-05-24T14:16:32Z")

</div>

hi,  
could you elaborate on this… if using postman, what headers/values need to be set?

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [May 24, 2018, 3:43pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/19 "2018-05-24T15:43:04Z")

</div>

> [@shahidmir](#):
>
> what headers/values need to be set?

The Content-Type should be “multipart/form-data”, but I don’t think you have to set that in the header if the Body is already set to “form-data” (my Headers in Postman are all blank).

---

<div class="post-metadata">

### Author: ![shahidmir](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@shahidmir](https://meta.discourse.org/u/shahidmir)
#### Post date: [May 24, 2018, 3:46pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/20 "2018-05-24T15:46:08Z")

</div>

hmmm, theres not much in the logs to highlight where the issue is…  
failing that, is it most likely the payload and sig thats the problem?

---

<div class="post-metadata">

### Author: ![shahidmir](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@shahidmir](https://meta.discourse.org/u/shahidmir)
#### Post date: [May 24, 2018, 3:51pm UTC](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819/21 "2018-05-24T15:51:27Z")

</div>

For testing this, im doing the following:

1. taking the following payload string:  
[email=discourse-sso2@gmail.com](mailto:email=discourse-sso2@gmail.com)&external\_id=auth0|111111111111233444&require\_activation=false

2. Generating the base64 encoded payload via:  
[https://www.base64encode.org/](https://www.base64encode.org/)

3. Taking that payload and generating the hmac-Sha256 encryped payload via:  
[Free Online HMAC Generator / Checker Tool (MD5, SHA-256, SHA-512) - FreeFormatter.com](https://www.freeformatter.com/hmac-generator.html)

4. Then sticking them both in postman, sso=payload, sig=encrypted payload

5. I have generated an API key for user ‘system’ and passing that in with the body.

Error i get in discourse logs:

Started POST “/discussion/admin/users/sync\_sso” for 123.157.28.69 at 2018-05-24 15:45:08 +0000

ActionController::RoutingError (No route matches [POST] “/admin/users/sync\_sso”)

/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.4/lib/action\_dispatch/middleware/debug\_exceptions.rb:63:in `call’

Rendering text template

[Next page](https://meta.discourse.org/t/admin-users-sync-sso-route-not-found/85819.md?page=2)
