Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Gigadrive
qpost
qpost
Commits
2793068a
Verified
Commit
2793068a
authored
Aug 27, 2020
by
Mehdi Baaboura
Browse files
Check if Authorization header starts with "Bearer"
parent
12f91109
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
src/Service/TokenService.php
src/Service/TokenService.php
+5
-5
No files found.
src/Service/TokenService.php
View file @
2793068a
...
...
@@ -23,6 +23,7 @@ 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
;
...
...
@@ -71,14 +72,13 @@ class TokenService {
public
function
getTokenFromRequest
(
Request
$request
):
?Token
{
$token
=
null
;
$authorizationHeader
=
$request
->
headers
->
has
(
"Authorization"
)
?
$request
->
headers
->
get
(
"Authorization"
)
:
null
;
$authorizationHeaderPrefix
=
"Bearer "
;
$authorizationHeader
=
$request
->
headers
->
has
(
"Authorization"
)
&&
Util
::
startsWith
(
$request
->
headers
->
get
(
"Authorization"
),
$authorizationHeaderPrefix
,
true
)
?
$request
->
headers
->
get
(
"Authorization"
)
:
null
;
if
(
$authorizationHeader
&&
is_string
(
$authorizationHeader
))
{
$prefix
=
"Bearer "
;
// Check if starts with token type prefix
if
(
strlen
(
$authorizationHeader
)
>
strlen
(
$
p
refix
)
&&
substr
(
$authorizationHeader
,
0
,
strlen
(
$
prefix
))
===
$p
refix
)
{
$token
=
substr
(
$authorizationHeader
,
strlen
(
$
p
refix
));
if
(
strlen
(
$authorizationHeader
)
>
strlen
(
$
authorizationHeaderP
refix
)
&&
substr
(
$authorizationHeader
,
0
,
strlen
(
$
authorizationHeaderPrefix
))
===
$authorizationHeaderP
refix
)
{
$token
=
substr
(
$authorizationHeader
,
strlen
(
$
authorizationHeaderP
refix
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment