aboutsummaryrefslogtreecommitdiff
path: root/www/authenticate.pl
blob: a36ad0210b225fac22f7a5707e70e57502a6447c (plain)
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
43
44
45
46
47
48
#! /usr/bin/env perl
# Copyright 2012, Matthias Andreas Benkard <code@mail.matthias.benkard.de>.

use common::sense;
#use Modern::Perl 2011;
use Modern::Perl;

use JSON;

use CGI;
use CGI::Fast;
use CGI::Session;

use Net::Google::FederatedLogin;

do "common.pl";

while (my $cgi = new CGI::Fast) {
  load_config();

  my $claimed_email = $cgi->param('email');

  my $g = Net::Google::FederatedLogin->new(
    claimed_id => $claimed_email,
    return_to  => reluri($cgi, 'login.pl'),
    extensions => [{ns          => 'ax',
                    uri         => 'http://openid.net/srv/ax/1.0',
                    attributes  => {mode        => 'fetch_request',
                                    required    => 'email',
                                    type        => {email => 'http://axschema.org/contact/email'}}}]
  );

  my $cookie = $cgi->cookie('mulkid_session');
  my $session = new CGI::Session("driver:File", $cookie, {Directory=>"/tmp"});
  $session->param('claimed_email', $claimed_email);
  if ($cookie) {
    print $cgi->redirect(-url => $g->get_auth_url());
  } else {
    my $cookie = $cgi->cookie(-name     => 'mulkid_session',
                              -value    => $session->id,
                              -expires  => '+1d',
                              #-secure   => 1,
                              -httponly => 1,
                              #-domain   => '.'.$::MULKONF->{realm}
                             );
    print $cgi->redirect(-cookie => $cookie, -url => $g->get_auth_url());
  }
}