https://github.com/runemadsen/github-oauth
A simple gem to handle github authentication via OAuth2
https://github.com/runemadsen/github-oauth
Last synced: 6 months ago
JSON representation
A simple gem to handle github authentication via OAuth2
- Host: GitHub
- URL: https://github.com/runemadsen/github-oauth
- Owner: runemadsen
- Created: 2011-10-30T03:54:31.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2011-10-30T16:07:30.000Z (about 14 years ago)
- Last Synced: 2025-04-01T21:51:56.755Z (9 months ago)
- Language: Ruby
- Homepage: http://www.runemadsen.com
- Size: 93.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this 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.