Skip to content

Commit

Permalink
🔨 #270 exemplo Basic Authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Aug 5, 2022
1 parent d0e5a28 commit 7cbc2a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions appexemplo_v2.0/api/api_controllers/Authentication.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace api_controllers;

use Tuupola\Middleware\HttpBasicAuthentication;

class Authentication
{

public function __construct()
{
}

public static function basicAuth(): HttpBasicAuthentication
{
return new HttpBasicAuthentication([
"users" => [
"root" => "teste123"
]
]);
}
}
15 changes: 15 additions & 0 deletions appexemplo_v2.0/api/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use api_controllers\SelfilhosmenuAPI;
use api_controllers\SelfilhosmenuqtdAPI;
use api_controllers\SelmenuqtdAPI;

use api_controllers\Authentication;

use api_controllers\Acesso_menuAPI;
use api_controllers\Acesso_perfilAPI;
use api_controllers\Acesso_perfil_menuAPI;
Expand Down Expand Up @@ -78,6 +81,18 @@
$urlChamada = explode('api/', $urlChamada);
$urlChamada = $urlChamada[0];
$urlChamada = $urlChamada.'api/';

$app->add(Authentication::basicAuth());

/*
$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
"users" => [
"root" => "t00r",
"somebody" => "passw0rd"
]
]));
*/

// Define app routes
$app->get($urlChamada, function (Request $request, Response $response, $args) use ($app) {
$url = \ServerHelper::getFullServerName();
Expand Down

0 comments on commit 7cbc2a5

Please sign in to comment.