-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
70 lines (49 loc) · 2.07 KB
/
index.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
<?php
include 'includes/hybridauth/autoload.php';
include 'config.php';
use Hybridauth\Hybridauth;
$hybridauth = new Hybridauth($hybridauthConfig);
$adapters = $hybridauth->getConnectedAdapters();
$isLoggedIn = false;
try {
$userInfoLinkedIn = $adapters['LinkedIn']->getUserProfile();
$tokens = $adapters['LinkedIn']->getAccessToken();
// if we can get here, toggle to being logged in
$isLoggedIn = true;
} catch(Throwable $e) {
#print "Exception: <p> $e";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP HybridAuth Sign In with LinkedIn</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>PHP HybridAuth Sign In with LinkedIn</h1>
<?php if ($isLoggedIn == true) : ?>
<div class="alert alert-warning">
You <strong>are</strong> signed in.
</div>
<p class="mt-5 mb-5">By default, we only have access to the scopes <em>r_liteprofile</em> and <em>r_emailaddress</em>. These are the only fields we get:</p>
<?php
$userInfoLinkedIn = $adapters['LinkedIn']->getUserProfile();
print "<p><strong>identifier:</strong> " . $userInfoLinkedIn->identifier . "</p>";
print "<p><strong>photoURL:</strong> " . $userInfoLinkedIn->photoURL . "</p>";
print "<p><strong>displayName:</strong> " . $userInfoLinkedIn->displayName . "</p>";
print "<p><strong>firstName:</strong> " . $userInfoLinkedIn->firstName . "</p>";
print "<p><strong>lastName:</strong> " . $userInfoLinkedIn->lastName . "</p>";
print "<p><strong>email:</strong> " . $userInfoLinkedIn->email . "</p>";
?>
<p class="mt-5"><a href="<?php print $hybridauthConfig['callback'] . "?logout=true"; ?>">Log Out</a></p>
<?php else :?>
<div class="alert alert-warning">
You are <strong>not</strong> signed in.
</div>
<a href="<?php print $hybridauthConfig['callback'];?>">Login with LinkedIn</a>
<?php endif; ?>
</div>
</body>
</html>