Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Auth example skeleton from https://github.com/atmos/sinatra_auth_gith…

  • Loading branch information...
commit 52bf422c16d8c4635612d14a3d65901480281f29 1 parent 674f9ea
@ryanfb authored
Showing with 39 additions and 1 deletion.
  1. +2 −0  .gitignore
  2. +37 −1 grist.rb
View
2  .gitignore
@@ -0,0 +1,2 @@
+config.yml
+/tmp
View
38 grist.rb
@@ -1,5 +1,41 @@
require 'sinatra'
+require 'sinatra_auth_github'
+require 'yaml'
+
+enable :sessions
+
+config = YAML.load_file('config.yml')
+
+set :github_options, {
+ :secret => config["secret"],
+ :client_id => config["client_id"]
+ }
+
+Sinatra.register Sinatra::Auth::Github
+
+helpers do
+ def repos
+ github_request("user/repos")
+ end
+end
get '/' do
- "Hello World"
+ authenticate!
+ "Hello There, #{github_user.name}!#{github_user.token}\n#{repos.inspect}"
+end
+
+get '/orgs/:id' do
+ github_public_organization_authenticate!(params['id'])
+ "Hello There, #{github_user.name}! You have access to the #{params['id']} organization."
+end
+
+# the scopes above need to include repo for team access :(
+# get '/teams/:id' do
+# github_team_authenticate!(params['id'])
+# "Hello There, #{github_user.name}! You have access to the #{params['id']} team."
+# end
+
+get '/logout' do
+ logout!
+ redirect 'https://github.com'
end
Please sign in to comment.
Something went wrong with that request. Please try again.