← Back to blog
· 2 min read · Github OAuth OmniAuth

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.

{%img http://farm4.staticflickr.com/3716/9240891751_409f794720_m.jpg%}

Steps to use these in your app. {% codeblock lang:ruby%} rails new GithubAuthApp{% endcodeblock %} Update your Gemfile add omniauth-github {% codeblock lang:ruby%} gem "omniauth-github"{% endcodeblock %} Create a config/initializers/omniauth.rb file. Paste your key instead of XXXX, and secret instead of YYYY {% codeblock lang:ruby%} use OmniAuth::Builder do provider :github, XXXX, YYYY end {% endcodeblock %}

All done start you server

{% codeblock lang:ruby%} bundle exec rails server{% endcodeblock %} Just open your app in browser with URL {% codeblock lang:ruby%} http://localhost:3000/auth/github{% endcodeblock %} 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 :