Support for authentication
This commit is contained in:
7
main/mashape/auth/Auth.php
Normal file
7
main/mashape/auth/Auth.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
interface Auth {
|
||||
public function handleHeader();
|
||||
|
||||
public function handleParams();
|
||||
}
|
||||
?>
|
||||
24
main/mashape/auth/BasicAuth.php
Normal file
24
main/mashape/auth/BasicAuth.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/HeaderAuth.php");
|
||||
|
||||
class BasicAuth extends HeaderAuth {
|
||||
|
||||
private $header;
|
||||
|
||||
function __construct($username, $password) {
|
||||
$headerValue = $username . ":" . $password;
|
||||
$this->header = "Authorization: " . base64_encode($headerValue);
|
||||
}
|
||||
|
||||
public function handleHeader() {
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
public function handleParams() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
22
main/mashape/auth/CustomHeaderAuth.php
Normal file
22
main/mashape/auth/CustomHeaderAuth.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/HeaderAuth.php");
|
||||
|
||||
class CustomHeaderAuth extends HeaderAuth {
|
||||
|
||||
private $header;
|
||||
|
||||
function __construct($headerName, $headerValue) {
|
||||
$this->header = $headerName . ": " . $headerValue;
|
||||
}
|
||||
|
||||
public function handleHeader() {
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
public function handleParams() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
9
main/mashape/auth/HeaderAuth.php
Normal file
9
main/mashape/auth/HeaderAuth.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/Auth.php");
|
||||
|
||||
abstract class HeaderAuth implements Auth {
|
||||
public function handleParams() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
18
main/mashape/auth/MashapeAuth.php
Normal file
18
main/mashape/auth/MashapeAuth.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../http/AuthUtil.php");
|
||||
require_once(dirname(__FILE__) . "/HeaderAuth.php");
|
||||
|
||||
class MashapeAuth extends HeaderAuth {
|
||||
|
||||
private $header;
|
||||
|
||||
function __construct($publicKey, $privateKey) {
|
||||
$this->header = AuthUtil::generateAuthenticationHeader($publicKey, $privateKey);
|
||||
}
|
||||
|
||||
public function handleHeader() {
|
||||
return $this->header;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
21
main/mashape/auth/QueryAuth.php
Normal file
21
main/mashape/auth/QueryAuth.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/Auth.php");
|
||||
|
||||
class QueryAuth implements Auth {
|
||||
|
||||
private $params;
|
||||
|
||||
function __construct($queryKey, $queryValue) {
|
||||
$this->params = array($queryKey => $queryValue);
|
||||
}
|
||||
|
||||
public function handleHeader() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function handleParams() {
|
||||
return $this->params;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user