-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Reinaldo Araujo Barreto Junior
committed
Aug 9, 2022
1 parent
baa4ab6
commit 2d23c41
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
system_skeleton/rest/api/api_controllers/Authentication.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace api_controllers; | ||
|
||
use Tuupola\Middleware\HttpBasicAuthentication; | ||
|
||
class Authentication | ||
{ | ||
private $urlChamada = null; | ||
private $listPath = array(); | ||
private $listPathIgnore= array(); | ||
private $listUsers = array(); | ||
|
||
public function __construct($urlChamada) | ||
{ | ||
$this->urlChamada = $urlChamada; | ||
$this->listPathIgnore[] = $urlChamada.'api'; | ||
$this->listPathIgnore[] = $urlChamada.'sysinfo'; | ||
$this->listUsers['root']= 'teste123'; | ||
} | ||
|
||
public function getUrlbase(){ | ||
return $this->urlChamada; | ||
} | ||
public function getArrayPath(){ | ||
$result = array(); | ||
if( empty($this->listPath) ){ | ||
$result[] = $this->getUrlbase().'auth'; | ||
}else{ | ||
$result = $this->listPath; | ||
} | ||
return $result; | ||
} | ||
public function addPath($path){ | ||
$this->listPath[] = $this->getUrlbase().$path; | ||
} | ||
|
||
public function getArrayPathIgnore(){ | ||
return $this->listPathIgnore; | ||
} | ||
|
||
public function addUsers(string $login, string $password){ | ||
$this->listUsers[$login] = $password; | ||
} | ||
public function getListUsers(){ | ||
return $this->listUsers; | ||
} | ||
|
||
/** | ||
* Cria um autenticação basica | ||
* | ||
* https://odan.github.io/slim4-skeleton/security.html | ||
* https://github.com/tuupola/slim-basic-auth | ||
* | ||
* @return HttpBasicAuthentication | ||
*/ | ||
public function basicAuth(): HttpBasicAuthentication | ||
{ | ||
return new HttpBasicAuthentication([ | ||
'ignore'=> $this->getArrayPathIgnore() | ||
,'path' => $this->getArrayPath() | ||
,"users" => $this->getListUsers() | ||
]); | ||
} | ||
} |