This commit is contained in:
2018-04-29 21:55:39 -04:00
parent d8d248672b
commit 8884d1df83
9 changed files with 2824 additions and 35 deletions

36
authlogin/api.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
// uncomment the lines below when running in stand-alone mode:
// for token+session based authentication (see "login_token.html" + "login_token.php"):
/*
require 'auth.php';
$auth = new PHP_API_AUTH(array(
'secret'=>'someVeryLongPassPhraseChangeMe',
));
if ($auth->executeCommand()) exit(0);
if (empty($_SESSION['user']) || !$auth->hasValidCsrfToken()) {
header('HTTP/1.0 401 Unauthorized');
exit(0);
}
*/
// for form+session based authentication (see "login.html"):
require 'auth.php';
$auth = new PHP_API_AUTH(array(
'authenticator'=>function($user,$pass){ if ($user=='admin' && $pass=='admin') $_SESSION['user']=$user; }
));
if ($auth->executeCommand()) exit(0);
if (empty($_SESSION['user']) || !$auth->hasValidCsrfToken()) {
header('HTTP/1.0 401 Unauthorized');
exit(0);
}
// include your api code here:
//
// see: https://github.com/mevdschee/php-crud-api
//
// placeholder for testing:
// echo 'Access granted!';

View File

@@ -1,4 +1,4 @@
<form method="post" action="api.php/">
<form method="post" action="loginInterface.php/">
<input name="username" value="admin"/>
<input name="password" value="admin"/>
<input type="submit" value="ok">

2787
authlogin/loginInterface.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +0,0 @@
<?php
// uncomment the lines below when running in stand-alone mode:
// for token+session based authentication (see "login_token.html" + "login_token.php"):
// require 'auth.php';
// $auth = new PHP_API_AUTH(array(
// 'secret'=>'someVeryLongPassPhraseChangeMe',
// ));
// if ($auth->executeCommand()) exit(0);
// if (empty($_SESSION['user']) || !$auth->hasValidCsrfToken()) {
// header('HTTP/1.0 401 Unauthorized');
// exit(0);
// }
// for form+session based authentication (see "login.html"):
// require 'auth.php';
// $auth = new PHP_API_AUTH(array(
// 'authenticator'=>function($user,$pass){ if ($user=='admin' && $pass=='admin') $_SESSION['user']=$user; }
// ));
// if ($auth->executeCommand()) exit(0);
// if (empty($_SESSION['user']) || !$auth->hasValidCsrfToken()) {
// header('HTTP/1.0 401 Unauthorized');
// exit(0);
// }
// include your api code here:
//
// see: https://github.com/mevdschee/php-crud-api
//
// placeholder for testing:
// echo 'Access granted!';