<?php
namespace Claromentis\OAuth2;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"] ?: array()) + array("_c69e6552374e0028da2b" . "1bcff2b40629" => base64_decode("T0F1dGgyIGV4Y2Vw" . "dGlvbiA="), "_bfca398626e2648b1803e02" . "7f7e347de" => base64_decode("T0F1dGgyIGVycm9yOiA" . "="), "_5b9126ef1203ad" . "ad78ba3bb44709b" . "439" => base64_decode("b2F1dG" . "hfdXNl" . "cl9pZA" . "=="), "_9dd6622bc2a" . "926e02c1cb73" . "fbcf9302c" => base64_decode("T0F1dGgyIC0gcmVxdWVzdCBjb250YWlu" . "cyB0b2tlbjog"), "_70809333a0f254acf" . "7a1ad0c7dadd46b" => base64_decode("OiA" . "="), "_fc9d7314a9d9958d8fa0a" . "403ba8ff197" => base64_decode("Z2V0X2N" . "sYXNz"), "_d58d9d29845f0d3d62e53f" . "8e87260f39" => base64_decode("cHNyNy5" . "wc3JfZm" . "FjdG9ye" . "Q=="));
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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_d58d9d29845f0d3d62e53f8e8" . "7260f39"]];
            $request = $_6eec82564352e2a97cddf7a7b6ad9a41->createRequest($request);
            $this->server->setRequest($request);
            $_9fafdb4f169d9de8376037b65724825c = $this->server->determineAccessToken(false);
            $this->logger->debug($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_9dd6622bc" . "2a926e02c1" . "cb73fbcf93" . "02c"] . $_9fafdb4f169d9de8376037b65724825c);
        } catch (OAuthServerException $e) {
            
            
            return;
        }
        try {
            
            
            $request = $this->server->getRequest();
            $user_id = $request->getAttribute($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_5b9126ef1203adad78ba3bb44709b4" . "39"]);
            $_a34812c777e8a5777cd0e658b92f0ab2->SetUserId($user_id);
        } catch (OAuthServerException $e) {
            throw new BadCredentialsException($e->getMessage(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_bfca398626e2648b" . "1803e027f7e347de"] . $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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_bfca398626e2648b1803e02" . "7f7e347de"] . $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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_bfca398626e2648b180" . "3e027f7e347de"] . $e->getMessage());
        }
        throw (new AuthenticationException($e->getMessage(), $e->getCode(), $e))->setAuditMessage($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_c69e6552374e0028da2b1" . "bcff2b40629"] . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_fc9d7314a9d9958d8fa0a403" . "ba8ff197"]($e) . $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_70809333" . "a0f254acf" . "7a1ad0c7d" . "add46b"] . $e->getMessage());
    }
}