add feide authentication

This commit is contained in:
John Chen 2017-10-07 21:25:44 +02:00
parent 3d2f07418d
commit a3c68c3c79
3 changed files with 35 additions and 8 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "lib/OAuth2-Client"]
path = lib/OAuth2-Client
url = https://github.com/kasperrt/OAuth2-Client.git

1
lib/OAuth2-Client Submodule

@ -0,0 +1 @@
Subproject commit 7b2dc91100becd0c3d15de8764ad279ded0d3a58

View File

@ -1,4 +1,31 @@
<?php <?php
require_once '../../lib/OAuth2-Client/OAuth2Client.php';
require_once '../../dataporten_config.php';
$oauth2 = new Kasperrt\Oauth2($dataportenConfig);
session_start();
if (isset($_GET['logout'])) {
session_destroy();
header('Location: http://[::1]:1080/paamelding/');
die();
}
if (isset($_GET['code'])) {
$token = $oauth2 -> get_access_token();
error_log($token);
$_SESSION['userdata'] = $oauth2 -> get_identity($token, 'https://auth.dataporten.no/userinfo');
header('Location: http://[::1]:1080/paamelding/');
die();
}
if (!isset($_SESSION['userdata'])) {
$oauth2 -> redirect();
die();
}
//var_export($_SESSION);
//exit;
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if($_POST["firstname"] == null && if($_POST["firstname"] == null &&
$_POST["lastname"] == null && $_POST["lastname"] == null &&
@ -35,20 +62,16 @@ die();
<div> <div>
<form> <form>
<div> <div>
First name: Full name:
<input type="text" name="firstname"> <input type="text" name="lastname" value="<?= $_SESSION['userdata']['user']['name'] ?>" readonly>
</div>
<div>
Last name:
<input type="text" name="lastname">
</div> </div>
<div> <div>
NTNU username: NTNU username:
<input type="text" name="username"> <input type="text" name="username" value="<?= $_SESSION['userdata']['user']['userid_sec'][0] ?>" readonly>
</div> </div>
<div> <div>
Email adress: Email adress:
<input type="text" name="email"> <input type="text" name="email" value="<?= $_SESSION['userdata']['user']['email'] ?>">
</div> </div>
<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>