Last active
October 19, 2016 20:05
-
-
Save imanalopher/402de52e06c7872e864afd3d38b73515 to your computer and use it in GitHub Desktop.
Just for Note
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OmniAuth with GitHub acount | |
https://api.github.com/users/:user | |
https://api.github.com/users/:user/repos | |
https://api.github.com/repos/:user/:repo/git/refs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use OmniAuth::Builder do | |
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] | |
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'] | |
end | |
get '/auth/:provider/callback' do | |
auth = request.env['omniauth.auth'] | |
user = User.where(:provider => auth["provider"], :uid => auth["uid"].to_i).first() || | |
User.create(:provider => auth["provider"], :uid => auth["uid"].to_i, :name => auth['info']['name']) | |
session[:user_id] = user.id | |
session[:user_name] = user.name | |
session[:uid] = auth['uid'].to_i | |
session[:provider] = auth['provider'] | |
redirect '/' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment