Debian Codegraph @

examples/openid20/gsasl-openid20-redirect.php

raw
1 #!/usr/bin/php5
2 <?php # -*- mode: php -*-
3
4 // gsasl-openid20-redirect.php --- OpenID redirector helper.
5 // Copyright (C) 2012-2026 Simon Josefsson
6 //
7 // This file is part of GNU SASL.
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 require_once "Auth/OpenID/Consumer.php";
23 require_once "Auth/OpenID/FileStore.php";
24 require_once "Auth/OpenID/SReg.php";
25 session_start ();
26
27 $store_path = $argv[1];
28 $nonce = $argv[2];
29 $openid_url = file_get_contents ($store_path . "/state/$nonce/openid_url");
30 $realm = file_get_contents ($store_path . "/state/$nonce/realm");
31 $return_to = file_get_contents ($store_path . "/state/$nonce/return_to");
32
33 print "nonce: ". $nonce ."\n";
34 print "openid_url: ". $openid_url ."\n";
35 print "realm: ". $realm ."\n";
36 print "return_to: ". $return_to ."\n";
37
38 $store = new Auth_OpenID_FileStore($store_path);
39 if (!$store) {
40 print "error: Auth_OpenID_FileStore.\n";
41 exit (1);
42 }
43
44 $consumer = new Auth_OpenID_Consumer($store);
45 if (!$consumer) {
46 print "error: Auth_OpenID_Consumer.\n";
47 exit (1);
48 }
49
50 $request = $consumer->begin($openid_url);
51 if (!$request) {
52 print "error: Auth_OpenID_Consumer->begin.\n";
53 exit (1);
54 }
55
56 $sreg = Auth_OpenID_SRegRequest::build(array(),
57 array('nickname', 'fullname', 'email'));
58 if (!$sreg) {
59 print "error: Auth_OpenID_SRegRequest::build\n";
60 exit (1);
61 }
62
63 $request->addExtension($sreg);
64
65 $redirect_url = $request->redirectURL($realm, $return_to);
66 if (Auth_OpenID::isFailure($redirect_url)) {
67 print ("error: Auth_OpenID_Consumer->redirectURL: " . $redirect_url->message);
68 exit (1);
69 }
70
71 file_put_contents ($store_path . "/state/$nonce/redirect_url", $redirect_url);
72
73 print "redirect_url: ". $redirect_url ."\n";
74
75 ?>