Sha256: bb3a6bf1cb4f5a3b95e0f237bc6c3d0afe569cabc83e8a11445f510a27ba75a0
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
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 "#{request.script_name}/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.set :gauth_openid_store, OpenID::Store::Filesystem.new(app.settings.gauth_tmp_dir) app.use OmniAuth::Builder do provider :google_apps, store: app.settings.gauth_openid_store, name: 'g', domain: app.settings.gauth_domain end app.post '/auth/g/callback' do if auth = request.env['omniauth.auth'] session[:_gauth] = { id: auth['uid'], name: auth['info']['name'], email: auth['info']['email'] } 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.5 | lib/sinatra/g_auth.rb |