Skip to content

Commit

Permalink
🔨 #118 classe authentication
Browse files Browse the repository at this point in the history
  • 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.
65 changes: 65 additions & 0 deletions system_skeleton/rest/api/api_controllers/Authentication.class.php
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()
]);
}
}

0 comments on commit 2d23c41

Please sign in to comment.