OAuth With OmniAuth and Github

If you want to authenticate your user in your app with Github  use omniauth-github strategy for that. Here I am describing how you can do that very quickly. OmniAuth provides list of  strategies to use many OAuth for your application. Here is the  List of Strategies.

Github uses the OAuth2 flow. First of all you have to register your app with Github GitHub Applications Page. Create a new application here and get Client ID and Secret. Here is how can you obtain Client ID and Secret from Github.

Steps to use these in your app.

1
 rails new GithubAuthApp
Update your Gemfile add omniauth-github
1
 gem "omniauth-github"
Create a config/initializers/omniauth.rb file. Paste your key instead of XXXX, and secret instead of YYYY
1
2
3
4

use OmniAuth::Builder do
  provider :github, XXXX, YYYY
end

All done start you server

1
 bundle exec rails server

Just open your app in browser with URL

1
 http://localhost:3000/auth/github

You will be redirecting to Github for authentication.

After success your app will redirect to your given callback URL with information and token!

At OmniAuth.org you can try out different -2 Strategies.

Useful links :