# Bypass the account creation modal when using OAuth2

**URL:** <https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123>\
**Category:** Product Support\
**Created:** [26 בפברואר,‏ 2019,‏ 1:23pm UTC](https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123 "2019-02-26T13:23:56Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![ryancey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryancey/32/99309_2.png) [@ryancey](https://meta.discourse.org/u/ryancey)\
**Post date:** [1 במרץ,‏ 2019,‏ 11:46am UTC](https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123/8 "2019-03-01T11:46:48Z")

</div>

Added code is between the comments (taken from [https://meta.discourse.org/t/disable-create-account-screen-for-cas-logins/11334/6?u=ryancey](https://meta.discourse.org/t/disable-create-account-screen-for-cas-logins/11334/6)).

```ruby
  def after_authenticate(auth)
    log("after_authenticate response: \n\ncreds: #{auth['credentials'].to_hash}\ninfo: #{auth['info'].to_hash}\nextra: #{auth['extra'].to_hash}")

    result = Auth::Result.new
    token = auth['credentials']['token']
    user_details = fetch_user_details(token, auth['info'][:id])

    result.name = user_details[:name]
    result.username = user_details[:username]
    result.email = user_details[:email]
    result.email_valid = result.email.present? && SiteSetting.oauth2_email_verified?
    avatar_url = user_details[:avatar]

    current_info = ::PluginStore.get("oauth2_basic", "oauth2_basic_user_#{user_details[:user_id]}")
    if current_info
      result.user = User.where(id: current_info[:user_id]).first
    elsif SiteSetting.oauth2_email_verified?
      result.user = User.find_by_email(result.email)
      if result.user && user_details[:user_id]
        ::PluginStore.set("oauth2_basic", "oauth2_basic_user_#{user_details[:user_id]}", user_id: result.user.id)
      end
    end

    download_avatar(result.user, avatar_url)

    result.extra_data = { oauth2_basic_user_id: user_details[:user_id], avatar_url: avatar_url }

    # --------------
    if User.find_by_email(user_details[:email]).nil?
      user = User.create(name: user_details[:name], email: user_details[:email], username: user_details[:username])
      log("created user account")
    end
    # --------------

    result
  end

```

---

_[View the full topic](https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123)._
