Sha256: 22f926b082d0a10b2260b7a761d05bed3d31ffa7d33739bfb52ba0e7c6860f04
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
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 " <a href='#{ENV['AUTH_URL']}'>Login with MVC</a>" end get '/auth/:provider/callback' do erb "<h1>#{params[:provider]}</h1> <pre>#{JSON.pretty_generate(request.env['omniauth.auth'])}</pre>" end get '/auth/failure' do erb "<h1>Authentication Failed:</h1><h3>message:<h3> <pre>#{params}</pre>" 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 "<pre>#{request.env['omniauth.auth'].to_json}</pre><hr> <a href='/logout'>Logout</a>" end get '/logout' do session[:authenticated] = false redirect '/' end end SinatraApp.run! if __FILE__ == $0 __END__ @@ layout <html> <head> <link href='http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css' rel='stylesheet' /> </head> <body> <div class='container'> <div class='content'> <%= yield %> </div> </div> </body> </html>
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
omniauth-mvc-1.0.1 | example/omniauth_app.rb |