# 自定义 OAuth 提供商问题：access\_token 的 user\_id 被设置为 nil

**URL:** <https://meta.discourse.org/t/issues-with-custom-oauth-provider-user-id-of-access-token-being-set-to-nil/103316>\
**Category:** Development\
**Created:** [2018 年12 月 3 日 02:59 UTC](https://meta.discourse.org/t/issues-with-custom-oauth-provider-user-id-of-access-token-being-set-to-nil/103316 "2018-12-03T02:59:01Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![Daniel\_Lopes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daniel_lopes/32/374589_2.png) [@Daniel\_Lopes](https://meta.discourse.org/u/Daniel_Lopes)\
发布日期： [2018 年12 月 3 日 02:59 UTC](https://meta.discourse.org/t/issues-with-custom-oauth-provider-user-id-of-access-token-being-set-to-nil/103316/1 "2018-12-03T02:59:02Z")

</div>

Hey everyone,

My company is starting to offer access to our discourse as part of our main product, and we decided to build a custom OAuth integration so people can login with the existing account.

We created as an authenticator based on FB and Twitter ones from Discourse codebase, released that as an internal Discourse plugin, and turned our main app into an OAuth provider. So far so good and everything worked just fine in development, but unfortunately I’m getting a PG constraint error in production.

```plaintext
Failed to handle exception in exception app middleware : PG::NotNullViolation: ERROR: null value in column "user_id" violates not-null constraint DETAIL: Failing row contains (XYZ, null, zk320lKJVI... : INSERT INTO "user_auth_tokens" ("auth_token", "prev_auth_token", "user_agent", "client_ip", "rotated_at", "created_at", "updated_at") VALUES (...

```

I’m assuming my plugin is passing something wrong to OmniauthCallbacksController. More precisely here:

```plaintext
  def complete_response_data
    if @auth_result.user
      user_found(@auth_result.user)
    elsif SiteSetting.invite_only?
      @auth_result.requires_invite = true
    else
      session[:authentication] = @auth_result.session_data
    end
  end

```

This is the code of my authenticator: [honcho\_authenticator.rb · GitHub](https://gist.github.com/danielvlopes/c265aeff5a7170512a8f3cb7c8d26d06)

If someone has experience with the authenticator part of Discourse that could shed some light, that would be very helpful.

Thank you.

---

_[View the full topic](https://meta.discourse.org/t/issues-with-custom-oauth-provider-user-id-of-access-token-being-set-to-nil/103316)._
