This is an example Rails 3 application to login to Github using OAuth2 and Devise
For more details on Githubs OAuth2 Setup – GitHub OAuth Busy Developer’s Guide
I built this so I could learn how to use OAuth2 with Github, it provides an easy base to build your own apps
- Latest Rails 3 (GIT master)
- Latest Devise (GIT master)
- Latest OAuth2 Gem (v0.0.10)
- Clone me
git clone git://github.com/lloydpick/rail3_github_oauth2_devise_example.git
- Install latest beta bundler (because Rails 3 master needs it)
gem install bundler --version 1.0.0.beta.4
- Go go magic bundler
bundle install
- Create and migrate the database
rake db:create
&rake db:migrate
Register for an application – GitHub OAuth2 Application Registration – and fill in the form…
Name: My Super Cool App (Development)
Main URL: http://localhost:8080
Callback URL: http://localhost:8080/users/oauth2
Put the Client ID and Secret codes into the config/oauth2_config.yml
file. By default this will have the
authorize_path
and access_token_path
setup correctly for Github Auth.
Then just boot up the app with the server of your choice and click the “Sign in with Github” link. It should
take you off to Github, ask you to authorize, then back to your app, creating a devise user, and logging you in.
While testing it helps to know where you can see all your OAuth2 applications this can be found here on github…
If you need to see or delete your OAuth2 connections for your GitHub account you can do that here…
Github OAuth2 Client Connections
Copyright © 2010 Lloyd Pick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.