0.0
No commit activity in last 3 years
No release in over 3 years
A simple gem to handle the Github OAuth authentication
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

Installation

To install the gem, simply run:

gem install 'github-oauth'

Or the bundler equivalent:

bundle install 'github-oauth'

Examples

This shows you how to use the gem (here using sinatra routes).

require 'github-oauth'    

get '/' do
  unless session[:access_token]
    redirect GithubOAuth.authorize_url('github_client_id', 'github_client_secret')
  end
  "You have authenticated"
end

get '/oauth' do
  session[:access_token] = GithubOAuth.token('github_client_id', 'github_client_secret', params[:code])
  redirect '/'
end

The main route checks whether we have a token saved in the database. If not, it redirects to Github for the user to authorize the application. The user is then returned to the /oauth path (specificed via the callback_url in the Github application settings), gets the token with the code parameter, and saves the token in a session variable.

If needed you can specify a specific scope for the authenticating user:

redirect GithubOAuth.authorize_url('github_client_id', 'github_client_secret', 'gist')

I'm planning on releasing my GithubAPI gem that takes this token and makes read/write operations to the Github API super simple.