Operator Error

adventures in software development and continuous learning

Github User Authentication in Rails

So you want to authenticate users using the Github API on your next Ruby and Rails project? Using Omniauth this is very easy to accomplish, however I set out to make it even easier by building a Rails skeleton for just this task!

First thing you want to do is create a new application on Github!

Set your Main and Callback URL accordingly! If you’re only doing local development for now, then you should be all set using both example URLs.

Now that your Github application is created, we need set some environment variables for the Client ID and Client Secret. You can do this on the command line or place both these values in your ~/.bashrc file.

1
2
$ export GITHUB_KEY="c6e53fab550fd8aa1523"
$ export GITHUB_SECRET="a651c99cb4de311795f924a3209984f1d27628e0"

Now we need to clone the project from Github and get it up and running!

1
2
3
4
5
$ git clone git@github.com:notfunk/rails-github-skeleton.git
$ cd rails-github-skeleton
$ bundle install
$ rake db:migrate
$ rails s

Now just visit http://127.0.0.1:3000 in your browser and sign in! Happy hacking.

Comments