Permalink
Browse files

Move sinatra token app to a bin file with instructions

  • Loading branch information...
1 parent 47873d6 commit a1cee41de0e18d0d28f8085be16e62d9aeb6dc20 @jwilger committed Jun 27, 2011
Showing with 56 additions and 28 deletions.
  1. +0 −2 .gitignore
  2. +1 −1 .rvmrc
  3. +55 −0 bin/github-v3-api-get-token
  4. +0 −25 get_access_token_sinatra_app.rb.template
View
@@ -46,5 +46,3 @@ pkg
# For rubinius:
#*.rbc
-
-get_access_token_sinatra_app.rb
View
2 .rvmrc
@@ -1,2 +1,2 @@
-rvm use ree-1.8.7-2011.03@github-v3-api --create --install
+rvm use ruby-1.9.2-p180@github-v3-api --create --install
bundle check
@@ -0,0 +1,55 @@
+#!/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.
+
+Once the server has started, just browse to http://localhost:4567. You may be
+prompted to log in to GitHub and/or authorize the app. After that, your access
+token will be displayed to you.
+
+You will need to create a GitHub Application in order to use this. Just go to
+https://github.com/account/applications/new and fill out the form. Pick any name
+you want, and use http://localhost:4567 and
+http://localhost:4567/auth/github/callback for the Main and Callback URLs,
+respectively. After creating the application, use the generated client id and
+client secret by running this script with the OAUTH_GITHUB_CLIENT_ID and
+OATH_GITHUB_CLIENT_SECRET environment variables set.
+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
@@ -1,25 +0,0 @@
-require 'rubygems'
-require 'bundler/setup'
-Bundler.setup(:sinatra)
-require 'sinatra'
-require 'openssl'
-require 'omniauth'
-
-# Because fuck you, Apple
-OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
-
-enable :sessions
-
-use OmniAuth::Builder do
- provider :github, YOUR_APP_ID, YOUR_APP_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

0 comments on commit a1cee41

Please sign in to comment.