Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 47 lines (35 sloc) 1.135 kB
a1cee41 @jwilger Move sinatra token app to a bin file with instructions
authored
1 #!/usr/bin/env ruby
2
3 puts <<EOF
4 This script will start a sinatra web app on your machine that can log you in to
5 GitHub and show you your access token. This access token can then be used with
cfeabfd @jwilger Moved API Token Helper App
authored
6 the GitHubV3API. You will need to set the OAUTH_GITHUB_CLIENT_ID and
7 OAUTH_GITHUB_CLIENT_SECRET environment variables. See the README for more
8 information.
9
a1cee41 @jwilger Move sinatra token app to a bin file with instructions
authored
10 EOF
11
12 print "Ready to go? (y/N): "
13
14 answer = STDIN.gets.chomp
15
16 unless answer =~ /^y(es)?$/i
17 exit(1)
18 end
19
20 unless ENV['OAUTH_GITHUB_CLIENT_ID'] && ENV['OAUTH_GITHUB_CLIENT_SECRET']
21 raise "Please set the OAUTH_GITHUB_CLIENT_ID and OAUTH_GITHUB_CLIENT_SECRET " \
22 + "environment variables before running this."
23 end
24
25 require 'rubygems'
26 require 'bundler/setup'
27 Bundler.setup(:sinatra)
28 require 'sinatra'
29 require 'openssl'
30 require 'omniauth'
31
32 enable :sessions
33
34 use OmniAuth::Builder do
35 provider :github, ENV['OAUTH_GITHUB_CLIENT_ID'], ENV['OAUTH_GITHUB_CLIENT_SECRET'],
36 :scope => 'user,repo,gist'
37 end
38
39 get '/' do
40 redirect '/auth/github'
41 end
42
43 get '/auth/github/callback' do
44 token = request.env['omniauth.auth']['credentials']['token']
45 "Your GitHub Access Token is #{token}"
46 end
Something went wrong with that request. Please try again.