Last active
May 8, 2019 10:58
-
-
Save sawanoboly/6590438 to your computer and use it in GitHub Desktop.
SphinxをShinatraでホストしつつGithubのOAuth経由でチーム認証をかけたが ref: http://qiita.com/sawanoboly/items/9646c4c53d442a7c6b46
This file contains hidden or 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
require 'sinatra' | |
require 'sinatra_auth_github' | |
set :public_folder, File.dirname(__FILE__) + '/build/html' | |
use Rack::Session::Cookie, | |
:secret => Digest::SHA1.hexdigest(rand.to_s), | |
:expire_after => 3600 | |
set :github_options, { | |
:scopes => "user", | |
:secret => ENV['GITHUB_CLIENT_SECRET'], | |
:client_id => ENV['GITHUB_CLIENT_ID'], | |
} | |
@@github_team = ENV['GITHUB_TEAM_ID'] | |
register Sinatra::Auth::Github | |
## Monkey for static filter | |
module Sinatra | |
class Base | |
class_eval do | |
alias :org_static! :static! | |
def static! | |
filter! :before | |
org_static! | |
end | |
end | |
end | |
end | |
## user is team_member? | |
before do | |
if request.path_info.end_with?('.html') | |
begin | |
body = github_team_authenticate!(@@github_team) | |
rescue | |
## return securocat! | |
halt 401, body | |
end | |
end | |
if request.path_info == '/logout' | |
logout! | |
redirect 'https://github.com' | |
end | |
end | |
get '/' do | |
redirect "/index.html", 301 | |
end | |
not_found do | |
unless request.path_info.end_with?('.ico') | |
redirect "#{request.path_info}.html", 301 | |
end | |
halt 404 | |
end | |
run Sinatra::Application |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment