require 'rubygems' require 'sinatra' require 'json' require 'omniauth' require 'omniauth-mvc' class SinatraApp < Sinatra::Base configure do set :sessions, true set :inline_templates, true end use OmniAuth::Builder do provider :mvc, ENV['APP_ID'], ENV['APP_SECRET'], display: 'popup', callback_url: ENV['CALLBACK_URL'] end get '/' do erb " Login with MVC" end get '/auth/:provider/callback' do erb "

#{params[:provider]}

#{JSON.pretty_generate(request.env['omniauth.auth'])}
" end get '/auth/failure' do erb "

Authentication Failed:

message:

#{params}
" end get '/auth/:provider/deauthorized' do erb "#{params[:provider]} has deauthorized this app." end get '/protected' do throw(:halt, [401, "Not authorized\n"]) unless session[:authenticated] erb "
#{request.env['omniauth.auth'].to_json}

Logout" end get '/logout' do session[:authenticated] = false redirect '/' end end SinatraApp.run! if __FILE__ == $0 __END__ @@ layout
<%= yield %>