Drop-in authentication for Sinatra with Google's OpenID endpoint.
Add this line to your application's Gemfile:
gem 'sinatra-google-auth'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sinatra-google-auth
The gem exposes a single authenticate helper that protects the endpoint with
Google OpenID authentication.
require 'sinatra'
require 'sinatra/google-auth'
get '*' do
authenticate
'hello'
endrequire 'sinatra/base'
require 'sinatra/google-auth'
class App < Sinatra::Base
register Sinatra::GoogleAuth
get '*' do
authenticate
'hello'
end
endDefine an on_user method in your app to do something with the user info after authentication.
class App < Sinatra::Base
register Sinatra::GoogleAuth
def on_user(info)
puts info.inspect
end
get '*' do
authenticate
'hello'
end
endConfigure your Google OpenID endpoint via setting the ENV var GOOGLE_AUTH_URL
$ export GOOGLE_AUTH_URL=http://myurl.com/openid
or before requiring
ENV['GOOGLE_AUTH_URL'] = 'http://myurl.com/openid'
require 'sinatra'
require 'sinatra/google-auth'Configure your session secret by setting SESSION_SECRET or SECURE_KEY ENV vars.
$ export SESSION_SECRET='super secure secret'
The 'SecureKey' add-on sets the SECURE_KEY variable for you and automatically rotates it.
$ heroku addons:add securekey
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request