Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4020184
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:11:48+00:00 2026-05-20T10:11:48+00:00

I’m trying to set up Devise 1.2 to allow user authentication via GitGub. As

  • 0

I’m trying to set up Devise 1.2 to allow user authentication via GitGub. As far as I can test it locally using Cucumber, and stubbing out GitHub OAuth, it seems to be working fine. After I deploy to Heroku, however, and try to authenticate, I get an error after being redirected back to my application from GitHub.

Checking the Heroku log, the error I see is…

PGError: ERROR: null value in column “email” violates not-null constraint

So apparently, I’m either not getting an email address back from GitHub, or it’s being lost somewhere along the way?

I’ve followed the instructions and examples on https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview and https://github.com/plataformatec/devise/wiki/OmniAuth:–Testing-%27facebook%27-signup–%5BRails-3—Cucumber—Capybara—Mongoid-%5D, but modified them for GitHub instead of Facebook, referring to the OmniAuth source code for the GitHub strategy at https://github.com/intridea/omniauth/blob/master/oa-oauth/lib/omniauth/strategies/github.rb.

Here’s what I have for my devise_steps.rb file, which results in a passing Cucumber feature:

ACCESS_TOKEN = {
  :access_token => "stevejdev"
}

# Not all pieces of this hash are yet proven to be correct.
# It does, at least supply the necessary information for a
# successful login simulation though.
GITHUB_INFO = {
  :user => {
    :id => '12345', 
    :email => 'johndoe@example.com',
    # login value maps to nickname and to <user> part of
    # "http://github.com/<user>" in urls[GitHub]
    :login => 'johnxd',
    :name => 'John Doe',
    # blog value maps to urls[blog]
    :blog => 'http://blaagstop.com/johndoe',
  }
}

When /^GitHub replies$/ do 
  Devise::OmniAuth.short_circuit_authorizers!
  Devise::OmniAuth.stub!(:github) do |b|
    b.post('/login/oauth/access_token') { 
              [200, {}, ACCESS_TOKEN.to_json] }
    b.get('/api/v2/json/user/show?access_token=stevejdev') {
              [200, {}, GITHUB_INFO.to_json ] }
  end

  visit user_omniauth_callback_path(:github)
end

Here’s my callback handler:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def github
    @user = User.find_for_github_oauth(env["omniauth.auth"], current_user)

    if @user.persisted?
      flash[:notice] = I18n.t(
        "devise.omniauth_callbacks.success", :kind => "GitHub" )
      sign_in_and_redirect @user, :event => :authentication
    else
      session["devise.github_data"] = env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

end

Here’s the find_for_github_oauth definition in my User model:

def self.find_for_github_oauth(access_token, signed_in_resource=nil)
  data = access_token['extra']['user_hash']

  # Find the existing user or create a new one.
  #  Omit the password-generation code shown in the example at
  #  https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
  #  because we're intending to use OmniAuth only, so
  #  presumably don't need a password.
  User.find_by_email( data["email"] ) ||
  User.create!( :email => data["email"] )

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:11:49+00:00Added an answer on May 20, 2026 at 10:11 am

    It turns out the problem is that GitHub does not use the email address as the user identifier, and does not necessarily include the email value in the token at all. I solved the problem by using the login instead of the email address.

    Since I’m planning to support multiple providers in the future, I’m now using a combination of auth_provider and login fields as the logical key for the users table, and I’ve specified config.authentication_keys = [ :auth_provider, :login ] in the config/devise.rb file. When I’m adding support for another provider that does use an email address for the user’s login, that’s fine. I’ll just use the email value from the provider’s response as the login value for the model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.