public
Description: deepblue's thoughts
Homepage: http://myruby.net/
Clone URL: git://github.com/deepblue/snippets.git
snippets / sinatra / openid_consumer.rb
100644 42 lines (32 sloc) 0.832 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# OpenID Consumer sample application built with sinatra
# by deepblue (http://myruby.net)
 
%w(rubygems sinatra haml).each{|lib| require lib}
 
get '/' do
  haml :login
end
 
load File.dirname(__FILE__) + '/lib/openid_authentication.rb'
 
module OpenIdAuthentication
  def authentication_succeed(oidresp)
    nickname = sreg_data(oidresp)['nickname']
    @message = "Logged in as #{nickname}(#{oidresp.display_identifier})"
    haml :login
  end
 
  def authentication_failed(oidresp, message)
    @message = "FAILED!!"
    haml :login
  end
  
  def sreg_request
    OpenID::SReg::Request.new(%w(nickname))
  end
end
 
use_in_file_templates!
 
__END__
 
## layout
%html
%body
=yield
 
## login
%h1= @message || 'Login'
%form{:action => '/openid/begin', :method => 'post'}
%input{:name => 'openid_identifier'}
%input{:type => 'submit'}