<?php
namespace Claromentis\OAuth2\Repository;

$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] ?: array()) + array("_cd1e0b9701991" . "2925fe74fc0325" . "a7e80" => base64_decode("U0VMRUNUIGFjY2Vzc190b2tlbiBGUk9NIG9hdXRoX2FjY2Vzc190b2tlb" . "nMgV0hFUkUgZXhwaXJlX3RpbWUgPCBpbnQ6dGltZXN0YW1w"), "_1f314ffb78debd8ea75e5aadca1" . "5fdb1" => base64_decode("U0VMRUNUIGNvdW50KDEpIEZST00gb2F1dGhfYWNjZXNzX3Rva2VucyBXSEV" . "SRSBhY2Nlc3NfdG9rZW4gZXE6c3RyOmFjY2Vzc190b2tlbg=="), "_dbc35587eab02812e4e3557" . "29e4f1e7e" => base64_decode("c3RyOmFjY2" . "Vzc190b2tl" . "bg=="), "_da102ab" . "6c482948" . "152eda41" . "272485d8" . "6" => base64_decode("b2F1dGhfYWNjZXNzX" . "3Rva2VuX3Njb3Blcw" . "=="), "_26abdb9dd07c49a5a48aa12" . "53b255dfd" => base64_decode("REVMRVRFIEZST00gb2F1dGhfYWNjZXNzX3R" . "va2VucyBXSEVSRSBhY2Nlc3NfdG9rZW4gZX" . "E6c3RyOmFjY2Vzc190b2tlbg=="), "_759df2ae0" . "d33fc1da31" . "593cd1b086" . "229" => base64_decode("c3RyOn" . "Njb3Bl"), "_9bc1e8c6" . "0888a0c74" . "6682a510e" . "002b63" => base64_decode("aW50OmV4cGl" . "yZV90aW1l"), "_eb272d6fd160f2b9213c8b02" . "56ee8c32" => base64_decode("b2F1dGhfYWNjZXNz" . "X3Rva2Vucw=="), "_7cfc19a4a65ec31a570015de6c3127" . "e1" => base64_decode("REVMRVRFIEZST00gb2F1dGhfYWNjZXNzX3Rva2V" . "uX3Njb3BlcyBXSEVSRSBhY2Nlc3NfdG9rZW4gZX" . "E6c3RyOnRva2Vu"), "_f4e5c2cfc0c848205" . "75d1586a6f13ae0" => base64_decode("YWNj" . "ZXNz" . "X3Rv" . "a2Vu"));
use Claromentis\Core\DAL;
use Claromentis\oauth2\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
class AccessTokenRepository implements AccessTokenRepositoryInterface
{
    
    
    protected $db;
    public function __construct(DAL\Db $db)
    {
        $this->db = $db;
    }
    
    
    
    
    
    
    
    
    
    
    public function getNewToken(ClientEntityInterface $_c38c68b4ca2c95f4fee8cf2ea909864e, array $_1db7fbca1ae6df9bac55436bafef3d7f, $_d425367da39a64e2bd3a0b150bd868ac = null)
    {
        $_0485f3da91abfea370d178ae67c6a351 = new AccessTokenEntity();
        $_0485f3da91abfea370d178ae67c6a351->setClient($_c38c68b4ca2c95f4fee8cf2ea909864e);
        foreach ($_1db7fbca1ae6df9bac55436bafef3d7f as $_8c618b28cb8e33e9ba8b291781620142) {
            $_0485f3da91abfea370d178ae67c6a351->addScope($_8c618b28cb8e33e9ba8b291781620142);
        }
        $_0485f3da91abfea370d178ae67c6a351->setUserIdentifier($_d425367da39a64e2bd3a0b150bd868ac);
        return $_0485f3da91abfea370d178ae67c6a351;
    }
    
    
    
    
    
    
    
    
    public function persistNewAccessToken(AccessTokenEntityInterface $_f4e5c2cfc0c84820575d1586a6f13ae0)
    {
        $_49ee1e842dca787e7c39f02341effb25 = new \Date($_f4e5c2cfc0c84820575d1586a6f13ae0->getExpiryDateTime());
        $data = [$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_dbc35587eab02812e4e355729" . "e4f1e7e"] => $_f4e5c2cfc0c84820575d1586a6f13ae0->getIdentifier(), $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_9bc1e8c60888a0c746682a510e00" . "2b63"] => $_49ee1e842dca787e7c39f02341effb25->getDate(DATE_FORMAT_UNIXTIME)];
        $this->db->unsafe_query = true;
        $this->db->query(new DAL\QueryInsert($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_eb272d6" . "fd160f2b" . "9213c8b0" . "256ee8c3" . "2"], $data));
        foreach ($_f4e5c2cfc0c84820575d1586a6f13ae0->getScopes() as $_8c618b28cb8e33e9ba8b291781620142) {
            
            
            $this->AddScopeForAccessToken($_f4e5c2cfc0c84820575d1586a6f13ae0, $_8c618b28cb8e33e9ba8b291781620142);
        }
    }
    
    
    
    
    
    
    public function revokeAccessToken($_f4e5c2cfc0c84820575d1586a6f13ae0)
    {
        $this->DeleteScopesForAccessToken($_f4e5c2cfc0c84820575d1586a6f13ae0);
        $this->db->unsafe_query = true;
        $this->db->query($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_26abdb9dd07c49a5a48aa12" . "53b255dfd"], $_f4e5c2cfc0c84820575d1586a6f13ae0);
    }
    
    
    
    
    public function removeOldAccessTokens()
    {
        $_c8b38c7133c2e8460c1cca42230ac6c2 = new \Date();
        $_97ea09a7faf27c52c6eff69773df1d8a = $_c8b38c7133c2e8460c1cca42230ac6c2->getDate(DATE_FORMAT_UNIXTIME);
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_cd1e0b97019912925fe74fc0" . "325a7e80"], $_97ea09a7faf27c52c6eff69773df1d8a);
        while ($_343a395319323dd7609bcbc465b4d034 = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $this->revokeAccessToken($_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_f4e5c2cfc0c84820575d15" . "86a6f13ae0"]]);
        }
    }
    
    
    
    
    
    
    
    
    public function isAccessTokenRevoked($_f4e5c2cfc0c84820575d1586a6f13ae0)
    {
        $this->removeOldAccessTokens();
        list($_41420dbd0c3745f9b80b6c2b5f463369) = $this->db->query_row($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_1f314ffb" . "78debd8ea" . "75e5aadca" . "15fdb1"], $_f4e5c2cfc0c84820575d1586a6f13ae0);
        return $_41420dbd0c3745f9b80b6c2b5f463369 < 1;
    }
    protected function AddScopeForAccessToken(AccessTokenEntityInterface $_f4e5c2cfc0c84820575d1586a6f13ae0, ScopeEntityInterface $_8c618b28cb8e33e9ba8b291781620142)
    {
        $data = [$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_dbc35587eab02812e4e355729e4f1e" . "7e"] => $_f4e5c2cfc0c84820575d1586a6f13ae0->getIdentifier(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_759df2ae0d" . "33fc1da3159" . "3cd1b086229"] => $_8c618b28cb8e33e9ba8b291781620142->getIdentifier()];
        $this->db->unsafe_query = true;
        $this->db->query(new DAL\QueryInsert($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_da102ab6" . "c48294815" . "2eda41272" . "485d86"], $data));
    }
    protected function DeleteScopesForAccessToken($_f4e5c2cfc0c84820575d1586a6f13ae0)
    {
        $this->db->unsafe_query = true;
        $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_7cfc19a4a65ec31a570015de6c3127e" . "1"], $_f4e5c2cfc0c84820575d1586a6f13ae0);
    }
}