<?php
namespace Claromentis\OAuth2;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"] = (@$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] ?: array()) + array("_fc9d7314a9d9958" . "d8fa0a403ba8ff19" . "7" => base64_decode("Z2V0" . "X2Ns" . "YXNz"), "_c69e6552374" . "e0028da2b1bc" . "ff2b40629" => base64_decode("T0F1dGgyIGV4Y2" . "VwdGlvbiA="), "_d58d9d29845f0d3d62e53f8e872" . "60f39" => base64_decode("cHNyNy5wc3JfZ" . "mFjdG9yeQ=="), "_5b9126ef1203adad7" . "8ba3bb44709b439" => base64_decode("b2F1dGhfdXNlcl9pZA" . "=="), "_9dd6622bc2a92" . "6e02c1cb73fbcf" . "9302c" => base64_decode("T0F1dGgyIC0gcmVxd" . "WVzdCBjb250YWlucy" . "B0b2tlbjog"), "_bfca398626e2648b18" . "03e027f7e347de" => base64_decode("T0F1dGgyIGVycm" . "9yOiA="), "_7080933" . "3a0f254a" . "cf7a1ad0" . "c7dadd46" . "b" => base64_decode("Oi" . "A="));
use Claromentis\Core\Security\AuthenticatorInterface;
use Claromentis\Core\Security\Exception\BadCredentialsException;
use Claromentis\Core\Security\SessionSecurityContext;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Psr\Log\LoggerInterface;






class OAuth2Authenticator implements AuthenticatorInterface
{
    private $server;
    private $logger;
    public function __construct(ResourceServer $_9892bd107000e49a32f2013f56e71f64, LoggerInterface $logger = null)
    {
        $this->server = $_9892bd107000e49a32f2013f56e71f64;
        $this->logger = $logger;
    }
    
    
    
    
    
    
    
    
    
    
    
    public function Handle(RequestEvent $event, SessionSecurityContext $_a34812c777e8a5777cd0e658b92f0ab2)
    {
        global $g_application;
        try {
            $request = $event->getRequest();
            
            
            $_6eec82564352e2a97cddf7a7b6ad9a41 = $g_application[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d58d9d29845f0d" . "3d62e53f8e87260" . "f39"]];
            $request = $_6eec82564352e2a97cddf7a7b6ad9a41->createRequest($request);
            $this->server->setRequest($request);
            $_9fafdb4f169d9de8376037b65724825c = $this->server->determineAccessToken(false);
            $this->logger->debug($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_9dd6622bc2a926e02" . "c1cb73fbcf9302c"] . $_9fafdb4f169d9de8376037b65724825c);
        } catch (OAuthServerException $e) {
            
            
            return;
        }
        try {
            
            
            $request = $this->server->getRequest();
            $user_id = $request->getAttribute($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_5b9126ef1203ada" . "d78ba3bb44709b43" . "9"]);
            $_a34812c777e8a5777cd0e658b92f0ab2->SetUserId($user_id);
        } catch (OAuthServerException $e) {
            throw new BadCredentialsException($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_bfca398626e2648b1803" . "e027f7e347de"] . $e->getMessage(), $e->getCode(), $e);
        }
    }
    private function HandleException(OAuthException $e)
    {
        if ($e instanceof \League\OAuth2\Server\Exception\InvalidRequestException) {
            throw (new BadCredentialsException($e->getMessage(), $e->getCode(), $e))->setAuditMessage($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_bfca398" . "626e2648" . "b1803e02" . "7f7e347d" . "e"] . $e->getMessage());
        }
        if ($e instanceof \League\OAuth2\Server\Exception\AccessDeniedException) {
            throw new AccessDeniedException($e->getMessage(), 403, $e);
        }
        if ($e instanceof \League\OAuth2\Server\Exception\InvalidCredentialsException) {
            throw (new BadCredentialsException($e->getMessage(), $e->getCode(), $e))->setAuditMessage($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_bfca398626e2648b1803e02" . "7f7e347de"] . $e->getMessage());
        }
        throw (new AuthenticationException($e->getMessage(), $e->getCode(), $e))->setAuditMessage($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_c69e6552374e0028da2b1bc" . "ff2b40629"] . $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_fc9d7314a9d9958d8fa0a4" . "03ba8ff197"]($e) . $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_70809333a0f254acf7" . "a1ad0c7dadd46b"] . $e->getMessage());
    }
}