Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 47 lines (35 sloc) 1.11 KB
#!/usr/bin/env ruby
puts <<EOF
This script will start a sinatra web app on your machine that can log you in to
GitHub and show you your access token. This access token can then be used with
the GitHubV3API. You will need to set the OAUTH_GITHUB_CLIENT_ID and
OAUTH_GITHUB_CLIENT_SECRET environment variables. See the README for more
information.
EOF
print "Ready to go? (y/N): "
answer = STDIN.gets.chomp
unless answer =~ /^y(es)?$/i
exit(1)
end
unless ENV['OAUTH_GITHUB_CLIENT_ID'] && ENV['OAUTH_GITHUB_CLIENT_SECRET']
raise "Please set the OAUTH_GITHUB_CLIENT_ID and OAUTH_GITHUB_CLIENT_SECRET " \
+ "environment variables before running this."
end
require 'rubygems'
require 'bundler/setup'
Bundler.setup(:sinatra)
require 'sinatra'
require 'openssl'
require 'omniauth'
enable :sessions
use OmniAuth::Builder do
provider :github, ENV['OAUTH_GITHUB_CLIENT_ID'], ENV['OAUTH_GITHUB_CLIENT_SECRET'],
:scope => 'user,repo,gist'
end
get '/' do
redirect '/auth/github'
end
get '/auth/github/callback' do
token = request.env['omniauth.auth']['credentials']['token']
"Your GitHub Access Token is #{token}"
end