forked from PHPExpertsInc/multiauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.php
117 lines (104 loc) · 3.33 KB
/
demo.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* PHP University Learning Lesson - 3rd Party Authentication Systems
* Copyright © 2012 PHP Experts, Inc.
* Author: Theodore R. Smith <[email protected]>
* http://users.phpexperts.pro/tsmith/
*
* The following code is licensed under a modified BSD License.
* All of the terms and conditions of the BSD License apply with one
* exception:
*
* 1. Every one who is not or has not been a registered student of the
* PHP University (http://www.phpu.cc/) is expressly forbidden
* from modifing this code or using in an another project, either as a
* deritvative work or stand-alone .
*
* BSD License: http://www.opensource.org/licenses/bsd-license.php
**/
include 'MultiAuth.php';
new Thrive_Autoloader(realpath(dirname(__FILE__) . '/../'));
$isLoggedIn = null;
$sessionGuard = new SessionGuardian();
$service = null; $serviceParams = null;
if (isset($_POST['service']))
{
$service = $_POST['service'];
if (isset($_POST['serviceParams']))
{
$serviceParams = $_POST['serviceParams'];
}
}
// TODO: It'd be nice to be able to add this back someday.
//echo 'Log in process has not started.';
// TODO: Add support for any OpenID URL.
//$ticketMan = new LoginLogic_OpenID('https://www.google.com/accounts/o8/id');
$ticketMan = new UserAuthenticator($service, $serviceParams);
// 1. Attempt to log in the user.
try
{
$ticketMan->attemptToLogin();
}
catch (Exception $e)
{
$errorMessage = $e->getMessage();
}
$isLoggedIn = $ticketMan->isUserAuthenticated();
$loginStatus = ($isLoggedIn == true ? 'is' : 'is not');
// I want MultiAuth to handle as much of the implementation details as possible.
// The big one right now is all the session stuff; right now that's pretty much
// totally all in the front controller. I want to abstract it out.
$authSecrets = $sessionGuard->createAuthSecrets(4);
?>
<html>
<head>
<title>Multi-System Login</title>
</head>
<body>
<h1>Multi-System Login</h1>
<?php
if (isset($errorMessage))
{
?>
<div id="error_box">
<h2>Error:</h2>
<p><?php echo $errorMessage; ?></p>
</div>
<?php
}
?>
<?php
if (isset($loginStatus))
{
?>
<h2>The user <?php echo $loginStatus ?> logged in<?php echo ($isLoggedIn) ? " via $service" : ''; ?>.</h2>
<?php
}
?>
<div>
<form method="post">
<input type="hidden" name="service" value="Google"/>
<input type="hidden" name="<?php echo FORM_AUTH_KEY; ?>" value="<?php echo $authSecrets[0]; ?>"/>
<input type="submit" name="login" value="Log in via Google"/>
</form>
<form method="post">
<input type="hidden" name="service" value="Yahoo"/>
<input type="hidden" name="<?php echo FORM_AUTH_KEY; ?>" value="<?php echo $authSecrets[1]; ?>"/>
<input type="submit" name="login" value="Log in via Yahoo"/>
</form>
<form method="post">
<input type="hidden" name="service" value="Facebook"/>
<input type="hidden" name="<?php echo FORM_AUTH_KEY; ?>" value="<?php echo $authSecrets[2]; ?>"/>
<input type="submit" name="login" value="Log in via Facebook"/>
</form>
<form method="post">
<input type="hidden" name="service" value="OpenID"/>
<div>
OpenID URL: <input type="text" name="serviceParams[openID_url]"/>
</div>
<input type="hidden" name="<?php echo FORM_AUTH_KEY; ?>" value="<?php echo $authSecrets[3]; ?>"/>
<input type="submit" name="login" value="Log in via Facebook"/>
</form>
</div>
</body>
</html>