krot

slim 4 authorization

Nov 23rd, 2020 (edited)
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. class authorization {
  2.       public function __invoke($request, $handler): Response {
  3.              $response = new Response();
  4.              if(isset($_SERVER['HTTP_AUTHORIZATION'])){
  5.                 list($user_id,$pass)=explode(':',base64_decode($_SERVER['HTTP_AUTHORIZATION']));
  6.                 if(is_numeric($user_id)){
  7.                     $request=$request->withAttribute('user_id',$user_id);
  8.                     return $handler->handle($request);
  9.                 }
  10.             }
  11.              return $response->withStatus(403);
  12.       }
  13. }
  14. //route
  15. $param['user_id']=$request->getAttribute('user_id');
  16. })->add(new authorization());
  17. SetEnvIf Authorization "Basic (.*)" HTTP_AUTHORIZATION=$1
  18.  
  19. RewriteEngine On
  20. RewriteCond %{REQUEST_FILENAME} !-f
  21. RewriteCond %{REQUEST_FILENAME} !-d
  22. RewriteRule ^api index.php [QSA,L,NC]
  23.  
Add Comment
Please, Sign In to add comment