Skip to content

Commit

Permalink
Move sinatra token app to a bin file with instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilger committed Jun 27, 2011
1 parent 47873d6 commit a1cee41
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Expand Up @@ -46,5 +46,3 @@ pkg


# For rubinius: # For rubinius:
#*.rbc #*.rbc

get_access_token_sinatra_app.rb
2 changes: 1 addition & 1 deletion .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 bundle check
55 changes: 55 additions & 0 deletions bin/github-v3-api-get-token
@@ -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
25 changes: 0 additions & 25 deletions get_access_token_sinatra_app.rb.template

This file was deleted.

0 comments on commit a1cee41

Please sign in to comment.