# Sinatra::GAuth Quickly add Google Apps authentication to any Sintra app. ## Installation Add this line to your application's Gemfile: gem 'sinatra-g_auth', require: 'sinatra/g_auth' And then execute: $ bundle Or install it yourself as: $ gem install sinatra-g_auth ## Usage Configure the settings and register the extension to get up and running. ````ruby class App < Sinatra::Base set :gauth_domain, 'example.org' # set this to your google apps domain set :gauth_tmp_dir, './tmp' # path to a directory that's writable by your web process set :gauth_redirect, '/' # where to redirect users after they've authenticated register Sinatra::GAuth # add the sinatra extension to your stack get '/protected' do protect_with_gauth! # add this to any route you want protected # ... end end ```` Once the user has authenticated with google, some basic information is added to the session: ````ruby session[:_gauth][:id] # => google ID session[:_gauth][:name] # => user's full name session[:_gauth][:email] # => google apps email address ```` If attempting to add `protect_with_gauth!` to a before filter, be sure to skip paths that begin with `/auth`: ````ruby before(%r{^(?!(\/auth))}) do protect_with_gauth! end ```` This extension will enable sessions, but does not configure a session store. Do that with the middleware of your choice (e.g. `Rack::Session::Cookie`, `Rack::Session::Dalli`, etc). Authentication is automatic for any routes that call `protect_with_gauth!`. You can add a more user friendly login page, like this: ````ruby get '/login' do 'Login with Google Apps' end ```` This extension does not provide a logout mechanism, but one can be added easily if you like: ````ruby get '/logout' do session.clear # redirect or whatever... end ```` ## Project Status - Build: [![Build Status](https://secure.travis-ci.org/styleseek/sinatra-g_auth.png?branch=master)](https://travis-ci.org/styleseek/sinatra-g_auth) - Code Quality: [![Code Climate](https://codeclimate.com/github/styleseek/sinatra-g_auth.png)](https://codeclimate.com/github/styleseek/sinatra-g_auth) - Dependencies: [![Dependency Status](https://gemnasium.com/styleseek/sinatra-g_auth.png)](https://gemnasium.com/styleseek/sinatra-g_auth) ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request