API: Auth implementation
This commit is contained in:
parent
01a6fb914f
commit
4e91eeb3ab
6 changed files with 147 additions and 2 deletions
rcc/api/auth
52
rcc/api/auth/DigestAuth.php
Normal file
52
rcc/api/auth/DigestAuth.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP Version 7
|
||||
*
|
||||
* Authentication Helper Class
|
||||
*
|
||||
* @category Authentication
|
||||
* @package Rbe
|
||||
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
|
||||
* @license MIT License
|
||||
* @link http://marcel-kapfer.de/rangitaki
|
||||
*/
|
||||
namespace mmk2410\rbe\digestAuth;
|
||||
|
||||
/**
|
||||
* PHP Version 7
|
||||
*
|
||||
* Authentication Helper Class
|
||||
*
|
||||
* @category Authentication
|
||||
* @package Rbe
|
||||
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
|
||||
* @license MIT License
|
||||
* @link http://marcel-kapfer.de/rangitaki
|
||||
*/
|
||||
class DigestAuth
|
||||
{
|
||||
|
||||
/**
|
||||
* parser for http digest
|
||||
*
|
||||
* @param $txt data to parse
|
||||
*
|
||||
* @return parsed data or FALSE
|
||||
*/
|
||||
public function httpDigestParse($txt)
|
||||
{
|
||||
// protect against missing data
|
||||
$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
|
||||
$data = array();
|
||||
$keys = implode('|', array_keys($needed_parts));
|
||||
|
||||
preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
|
||||
|
||||
foreach ($matches as $m) {
|
||||
$data[$m[1]] = $m[3] ? $m[3] : $m[4];
|
||||
unset($needed_parts[$m[1]]);
|
||||
}
|
||||
|
||||
return $needed_parts ? false : $data;
|
||||
}
|
||||
}
|
Reference in a new issue