This commit is contained in:
Yuri Kuznetsov
2020-07-08 17:50:53 +03:00
parent f8f7c4fbff
commit 773abf3028
6 changed files with 25 additions and 2 deletions
+12
View File
@@ -68,16 +68,26 @@ class Auth
$this->isResolvedUseNoAuth = true;
}
/**
* Logged in succesfully.
*/
public function isResolved() : bool
{
return $this->isResolved;
}
/**
* No need to log in.
*/
public function isResolvedUseNoAuth() : bool
{
return $this->isResolvedUseNoAuth;
}
/**
* Determines which auth method to use. Fetches a username and password from headers and server parameters.
* Then tries to log in.
*/
public function process(Request $request, Response $response)
{
$httpMethod = $request->getMethod();
@@ -95,6 +105,8 @@ class Auth
$authenticationMethod = 'Hmac';
} else if ($request->hasHeader('X-Api-Key')) {
$authenticationMethod = 'ApiKey';
} else if ($request->hasHeader('X-Auth-Method')) {
$authenticationMethod = $request->getHeader('X-Auth-Method');
}
if (!$authenticationMethod) {
+7
View File
@@ -146,6 +146,13 @@ class Auth
) : ?array {
$isByTokenOnly = false;
if ($authenticationMethod) {
if (!$this->metadata->get(['authenticationMethods', $authenticationMethod, 'api'])) {
$GLOBALS['log']->warning("AUTH: Trying to use not allowed authentication method '{$authenticationMethod}'.");
return null;
}
}
if (!$authenticationMethod) {
if ($request->getHeader('Espo-Authorization-By-Token') === 'true') {
$isByTokenOnly = true;
@@ -0,0 +1,3 @@
{
"api": true
}
@@ -1,5 +1,4 @@
{
"settings": {
"isAvailable": true
}
@@ -0,0 +1,3 @@
{
"api": true
}
@@ -1,5 +1,4 @@
{
"settings": {
"isAvailable": true,
"layout": {