开发者

Rails: Omniauth: Github provider doesn't quite work

开发者 https://www.devze.com 2023-03-06 07:04 出处:网络
I recently forked https://github.com/fortuity/rails3-mongoid-omniauth and tried to get login working for different providers. It works for Twitter and Facebook (You can try it out at http://jgodse-omn

I recently forked https://github.com/fortuity/rails3-mongoid-omniauth and tried to get login working for different providers. It works for Twitter and Facebook (You can try it out at http://jgodse-omniauth-mongoid.he开发者_如何学JAVAroku.com/), but I couldn't get it working for Github. The code snapshot is here at github.

My environment looks like this:

$ heroku info
=== jgodse-omniauth-mongoid
Web URL:        http://jgodse-omniauth-mongoid.heroku.com/
Git Repo:       git@heroku.com:jgodse-omniauth-mongoid.git
Dynos:          1
Workers:        0
Repo size:      7M
Slug size:      5M
Stack:          bamboo-mri-1.9.2
Data size:      (empty)
Addons:         Basic Logging, MongoHQ MongoHQ Free, Shared Database 5MB
Owner:          xxxxx@yyy.com

Jay@JAY-PC ~/rapps/rails3-mongoid-omniauth (master)
$ heroku config --long
BUNDLE_WITHOUT      => development:test
DATABASE_URL        => postgres://xxxxxxxxxxxxxxxxxxxx.compute-1.amazonaws.com/rrretnhwhj
FACEBOOK_APP_ID     => xxxxxxxxxxxxxxxxxxxx
FACEBOOK_APP_SECRET => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
GITHUB_CLIENT_ID    => xxxxxxxxxxxxxxxxxxxxx
GITHUB_SECRET       => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LANG                => en_US.UTF-8
MONGOHQ_URL         => mongodb://heroku:9xxxxxxxxxxxxxxxx.mongohq.com:27098/app527030
RACK_ENV            => production
SHARED_DATABASE_URL => postgres://xxxxxxxxxxxxxxxxxxxxx.compute-1.amazonaws.com/rrretnhwhj
TWITTER_KEY         => xxxxxxxxxxxxxxxxxxx
TWITTER_SECRET      => xxxxxxxxxxxxxxxxxxxxxxxxxxxx

My github information for "OAuth Application: Jay's Rails3 Mongoid OAuth" is as follows (from my app profile page):

Authorization Token:   https://github.com/login/oauth/authorize
Access Token URL:      https://github.com/login/oauth/access_token
URL:     http://jgodse-omniauth-mongoid.heroku.com/
Callback URL:   http://jgodse-omniauth-mongoid.heroku.com/
Client ID: xxxxxxx
Secret:    xxxxxxxxxxxxxxxx

The client and secret are set as environment variables in omniauth.rb

The authentication happens, but it redirects to http://jgodse-omniauth-mongoid.heroku.com/?error=redirect_uri_mismatch and I haven't apparently logged in. If I change the Callback URL to http://jgodse-omniauth-mongoid.heroku.com/callback, the application crashes.

What am I missing to get github authentication to work?


I don't fu%^&*g believe this.

I went to github.com where the application secret, key, url, callback is configured and removed the trailing slash from the "Callback URL" and "URL", and it worked.

URL: http://jgodse-omniauth-mongoid.heroku.com
Callback URL:  http://jgodse-omniauth-mongoid.heroku.com

This is nuts! Twitter wants the trailing slash on the callback but Github does not. Github and twitter should allow both and then trim it automatically if needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消