Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move sinatra token app to a bin file with instructions
- Loading branch information
Showing
4 changed files
with
56 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -46,5 +46,3 @@ pkg | ||
|
|
||
# For rubinius: | # For rubinius: | ||
#*.rbc | #*.rbc | ||
|
|||
get_access_token_sinatra_app.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.