# Error using discourse-oauth2-basic plugin with NeonCRM

**URL:** https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596
**Category:** SSO
**Tags:** oauth2
**Created:** [November 5, 2019, 12:18am UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596 "2019-11-05T00:18:43Z")
**Posts on this page:** 9
**Page:** 2

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [November 21, 2019, 5:12pm UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/26 "2019-11-21T17:12:20Z")

</div>

I think I’ll start by erasing our current Droplet and set it up from scratch again since this docker was set up a few years back. I’ll report back when I have done that and tested it.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [November 21, 2019, 5:13pm UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/27 "2019-11-21T17:13:23Z")

</div>

Sounds like a good plan. For most communities we recommend sticking to the default tests-passed branch, because it gives you the latest and greatest Discourse features and bug fixes. There have been a lot of changes to authentication since the last stable release, so you might find things start working by themselves.

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [December 18, 2019, 8:46pm UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/28 "2019-12-18T20:46:43Z")

</div>

@david, I’ve taken the time to take another go at it today. I am now using a fresh Discourse install (latest on stable-passed, as you suggested).

I’ve set up Oauth2 using the plugin, just like before with the following settings:

```
oauth2 client id: MY-CLIENT-ID
oauth2 client secret: MY-CLIENT-SECRET
oauth2 authorize url: https://MY-NEON-ID.z2systems.com/np/oauth/auth
oauth2 token url: https://www.z2systems.com/np/oauth/token

```

If I use the manually formatted URL, I get this (which is new):

```
Authorization timed out, or you have switched browsers. Please try again.

```

And the usual error in the logs:

```
(oauth2_basic) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected

```

On the other hand, if I use the OAuth2 button in the Discourse login window, I get:

```
Oops

The software powering this discussion forum encountered an unexpected problem. We apologize for the inconvenience.

Detailed information about the error was logged, and an automatic notification generated. We'll take a look at it.

```

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [December 19, 2019, 12:12am UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/29 "2019-12-19T00:12:41Z")

</div>

I also get the following errors logged in /logs:

```
ArgumentError (Invalid URI: ) /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/excon-0.71.0/lib/excon.rb:126:in `new'

```

and

```
Failed to handle exception in exception app middleware : Invalid URI:

```

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [December 19, 2019, 1:08am UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/30 "2019-12-19T01:08:14Z")

</div>

> [@david](#):
>
> What do you have set for the `oauth2_user_json_url` ? I suspect it is blank. If so, you should also disable `oauth2_fetch_user_details` , so that Discourse does not try and contact a blank URL.

@david I tried your earlier suggestion regarding setting `oauth2_user_json_url` and disabling `oauth2_fetch_user_details`, and I got a bunch of (new) errors after trying it:

> ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR: null value in column “provider\_uid” violates not-null constraint  
> DETAIL: Failing row contains (1, oauth2\_basic, null, null, 2019-12-19 01:00:49.076659, {}, {“token”: “9607”, “expires”: false}, {}, 2019-12-19 01:00:49.077107, 2019-12-19 01:00:49.077107).  
> )  
> /var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.1.4/lib/patches/db/pg.rb:69:in `async\_exec\_params’

> Failed to handle exception in exception app middleware : PG::NotNullViolation: ERROR: null value in column “provider\_uid” violates not-null constraint  
> DETAIL: Failing row contains (1, oauth2\_basic, null, null, 2019-12-19 01:00:49.076659, {}, {“token”: “9607”, “expires”: false}, {}, 2019-12-19 01:00:49.077107, 2019-12-19 01:00:49.077107).

And of course the usual:

> (oauth2\_basic) Authentication failure! csrf\_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf\_detected | CSRF detected

However I noticed in this last one (CSRF Detected) that in the env tab, it says:

> hostname forum-app  
> process\_id 762  
> application\_version db7d00a8dce2cc1f7b9d86192cde1f55dd57408b  
> HTTP\_HOST forum.efao.ca

Is it normal for the hostname to not match the HTTP\_HOST name? Could that be why I get CSRF error?

---

<div class="post-metadata">

### Author: ![Beam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/beam/32/169161_2.png) [@Beam](https://meta.discourse.org/u/Beam)
#### Post date: [February 7, 2020, 7:17pm UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/31 "2020-02-07T19:17:19Z")

</div>

Hey Denis,

any luck?  
I got the same error:  
ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR: null value in column “provider\_uid” violates not-null constraint

How did you fix it?

Thanks,  
Beam

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 7, 2020, 7:36pm UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/32 "2020-02-07T19:36:50Z")

</div>

Denis and I worked out that NeonCRM aren’t really sticking to the oauth2 spec… they are sending the user\_id inside the access\_token variable, and it cannot be used as an actual access token.

So, you need to disable oauth2\_fetch\_user\_details, and set oauth2\_callback\_user\_id\_path to `token` (not access\_token, because the oauth2 ruby library renames it for internal use)

With that, it should be functional, but there is no way to fetch the user email/name

---

<div class="post-metadata">

### Author: ![Beam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/beam/32/169161_2.png) [@Beam](https://meta.discourse.org/u/Beam)
#### Post date: [February 7, 2020, 10:59pm UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/33 "2020-02-07T22:59:44Z")

</div>

Hey Denis,

I’m using mattermost so it’s behaving differently.  
However, your info made me look more at the settings and I have it working, thanks!!

Here are my settings for mattermost as an oauth2 provider to discourse:

 ![Screenshot 2020-02-07 at 23.12.31](https://global.discourse-cdn.com/meta/original/3X/5/4/54f4ff8a2a86f1a6c2157804974a2a1a01cbc66d.png)

Settings in text for search engines:

> oauth2 client id: \<client id from mattermost oauth2 provider setup\>  
> oauth2 client secret: \<client secret from mattermost oauth2 provider setup\>  
> oauth2 authorize url: `https://chat.animalrebellion.org/oauth/authorize`  
> oauth2 token url: `https://chat.animalrebellion.org/oauth/access_token`  
> oauth2 token url method: POST  
> oauth2 callback user id path:  
> oauth2 callback user info paths  
> oauth2 fetch user details: CHECKED  
> oauth2 user json url: `https://chat.animalrebellion.org/api/v4/users/me`  
> oauth2 user json url method: GET  
> oauth2 json user id path: id  
> oauth2 json username path: username  
> oauth2 json name path: username  
> oauth2 json email path: email  
> oauth2 json email verified path: email\_verified  
> oauth2 json avatar path:  
> oauth2 email verified: CHECKED

On the mattermost side, the callback url is set as:  
`https://base.animalrebellion.org/auth/oauth2_basic/callback`

Still would like to see how to join: first\_name and last\_name into the “jason name path” as full\_name, but can live with just using the “username” or “first\_name” property.

HTH

Cheers!  
Beam

Links to resources:  
Link to plugin: [GitHub - discourse/discourse-oauth2-basic: A basic OAuth2 plugin for use with Discourse · GitHub](https://github.com/discourse/discourse-oauth2-basic)  
Link to how to install discourse plugin: [Install plugins on a self-hosted site](https://meta.discourse.org/t/install-plugins-in-discourse/19157)

---

<div class="post-metadata">

### Author: ![Denis\_Heraud](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denis_heraud/32/119623_2.png) [@Denis\_Heraud](https://meta.discourse.org/u/Denis_Heraud)
#### Post date: [February 12, 2020, 1:05am UTC](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596/34 "2020-02-12T01:05:16Z")

</div>

Happy you got it working @Beam!

[Previous page](https://meta.discourse.org/t/error-using-discourse-oauth2-basic-plugin-with-neoncrm/132596.md?page=1)
