Skip to content

Instantly share code, notes, and snippets.

@sebastiangeiger
Created April 16, 2011 20:03
Show Gist options
  • Save sebastiangeiger/923438 to your computer and use it in GitHub Desktop.
Save sebastiangeiger/923438 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'haml'
# Session needs to be before Rack::OpenID
use Rack::Session::Cookie
require 'rack/openid'
require 'gapps_openid'
use Rack::OpenID
get '/login' do
haml :login
end
post '/login' do
if resp = request.env["rack.openid.response"]
p resp.class
if resp.status == :success
ax_response = OpenID::AX::FetchResponse.from_success_response(resp)
@email = ax_response['http://axschema.org/contact/email'].first
"Welcome: #{@email}"
else
"Error: #{resp.status}"
end
else
headers 'WWW-Authenticate' => Rack::OpenID.build_header(
:identifier => "http://randomgoogleappdomain.org",
:required => ['http://axschema.org/namePerson/friendly', 'http://axschema.org/contact/email']
)
throw :halt, [401, 'got openid?']
end
end
enable :inline_templates
__END__
@@ login
You need to sign in with your randomgoogleappdomain.org account
%form{:method => "post", :action => '/login'}
%input{:type => 'submit', :value => "proceed to login"}
@sebastiangeiger
Copy link
Author

Gemfile:
gem "sinatra"
gem "shotgun"
gem "haml"
gem "ruby-openid"
gem "ruby-openid-apps-discovery"
gem "rack-openid"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment