Sha256: f8e0d833172e39904ada7c1135363c10f754c7a93431cee82d3fddbdd2ce77a8
Contents?: true
Size: 954 Bytes
Versions: 1
Compression:
Stored size: 954 Bytes
Contents
require 'sinatra/base' require 'sinatra/g_auth/version' require 'openid/store/filesystem' require 'omniauth/strategies/google_apps' module Sinatra module GAuth module Helpers def protect_with_gauth! redirect '/auth/g' unless session[:_gauth] end end def self.registered(app) app.helpers GAuth::Helpers app.enable :sessions app.set :gauth_domain, 'gmail.com' app.set :gauth_redirect, '/' app.set :gauth_tmp_dir, '/tmp' app.use OmniAuth::Builder do provider :google_apps, store: OpenID::Store::Filesystem.new(app.settings.gauth_tmp_dir), name: 'g', domain: app.settings.gauth_domain end app.post '/auth/g/callback' do if auth = request.env['omniauth.auth'] session[:_gauth] = auth redirect app.settings.gauth_redirect else halt 401, 'Authorization Failed.' end end end end register GAuth end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sinatra-g_auth-0.0.1 | lib/sinatra/g_auth.rb |