Verified Commit 5444ac18 authored by Mehdi Baaboura's avatar Mehdi Baaboura
Browse files

Updated TokenService

parent 440b6801
......@@ -41,6 +41,7 @@ use qpost\Exception\ResourceNotFoundException;
use qpost\Service\APIService;
use qpost\Service\DataDeletionService;
use qpost\Service\StorageService;
use qpost\Service\TokenService;
use qpost\Service\TranslationService;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
......@@ -76,9 +77,10 @@ class APIController extends qpostController {
EntityManagerInterface $entityManager,
LoggerInterface $logger,
DataDeletionService $dataDeletionService,
StorageService $storageService
StorageService $storageService,
TokenService $tokenService
) {
parent::__construct($generalService, $paginationService, $translationService);
parent::__construct($generalService, $paginationService, $translationService, $tokenService);
$this->apiService = $apiService;
$this->entityManager = $entityManager;
......
......@@ -90,7 +90,7 @@ class TokenController extends APIController {
*/
public function verify() {
$this->validateAuth();
$token = $this->apiService->getToken();
$token = $this->tokenService->getCurrentToken();
$user = $token->getUser();
if (!$user->isSuspended()) {
......
......@@ -23,6 +23,7 @@ namespace qpost\Controller;
use Gigadrive\Bundle\SymfonyExtensionsBundle\Controller\GigadriveController;
use Gigadrive\Bundle\SymfonyExtensionsBundle\Service\Database\Pagination\PaginationService;
use Gigadrive\Bundle\SymfonyExtensionsBundle\Service\GigadriveGeneralService;
use qpost\Service\TokenService;
use qpost\Service\TranslationService;
class qpostController extends GigadriveController {
......@@ -31,13 +32,20 @@ class qpostController extends GigadriveController {
*/
protected $i18n;
/**
* @var TokenService $tokenService
*/
protected $tokenService;
public function __construct(
GigadriveGeneralService $generalService,
PaginationService $pagination,
TranslationService $i18n
TranslationService $i18n,
TokenService $tokenService
) {
parent::__construct($generalService, $pagination);
$this->i18n = $i18n;
$this->tokenService = $tokenService;
}
}
\ No newline at end of file
<?php
/**
/*
* Copyright (C) 2018-2020 Gigadrive - All rights reserved.
* https://gigadrivegroup.com
* https://qpostapp.com
......@@ -23,7 +23,6 @@ namespace qpost\Service;
use DateInterval;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Gigadrive\Bundle\SymfonyExtensionsBundle\DependencyInjection\Util;
use Psr\Log\LoggerInterface;
use qpost\Entity\Token;
use Symfony\Component\HttpFoundation\Cookie;
......@@ -70,16 +69,14 @@ class TokenService {
public function getTokenFromRequest(Request $request): ?Token {
$token = null;
if ((Util::startsWith($request->getPathInfo(), "/api") || Util::startsWith($request->getPathInfo(), "/webpush")) && $request->headers->has("Authorization")) {
$authorization = $request->headers->get("Authorization");
$authorizationHeader = $request->headers->get("Authorization");
if ($authorization && is_string($authorization)) {
$prefix = "Bearer ";
if ($authorizationHeader && is_string($authorizationHeader)) {
$prefix = "Bearer ";
// Check if starts with token type prefix
if (strlen($authorization) > strlen($prefix) && substr($authorization, 0, strlen($prefix)) === $prefix) {
$token = substr($authorization, strlen($prefix));
}
// Check if starts with token type prefix
if (strlen($authorizationHeader) > strlen($prefix) && substr($authorizationHeader, 0, strlen($prefix)) === $prefix) {
$token = substr($authorizationHeader, strlen($prefix));
}
} else if ($request->cookies->has(self::TOKEN_COOKIE_IDENTIFIER)) {
$cookieTokens = $this->getCookieTokens($request);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment