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
bc33ec4a
Verified
Commit
bc33ec4a
authored
Aug 24, 2020
by
Mehdi Baaboura
Browse files
Handle ClientException in ThirdPartyIntegration
parent
760ca41f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
34 deletions
+40
-34
src/Service/OAuth/ThirdPartyIntegration.php
src/Service/OAuth/ThirdPartyIntegration.php
+40
-34
No files found.
src/Service/OAuth/ThirdPartyIntegration.php
View file @
bc33ec4a
...
...
@@ -26,6 +26,7 @@ use Doctrine\ORM\EntityManagerInterface;
use
Exception
;
use
Gigadrive\Bundle\SymfonyExtensionsBundle\DependencyInjection\Util
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Exception\ClientException
;
use
Psr\Log\LoggerInterface
;
use
qpost\Entity\LinkedAccount
;
use
qpost\Entity\User
;
...
...
@@ -245,52 +246,57 @@ class ThirdPartyIntegration {
public
function
refreshToken
(
LinkedAccount
$account
):
?LinkedAccount
{
if
(
!
$account
->
isExpired
())
return
$account
;
if
(
$account
->
getService
()
!==
$this
->
getServiceIdentifier
())
return
$account
;
try
{
if
(
$account
->
getService
()
!==
$this
->
getServiceIdentifier
())
return
$account
;
$refreshToken
=
$account
->
getRefreshToken
();
if
(
is_null
(
$refreshToken
))
return
null
;
$refreshToken
=
$account
->
getRefreshToken
();
if
(
is_null
(
$refreshToken
))
return
null
;
$baseURL
=
$this
->
getBaseURL
();
if
(
is_null
(
$baseURL
))
return
null
;
$baseURL
=
$this
->
getBaseURL
();
if
(
is_null
(
$baseURL
))
return
null
;
$clientId
=
$account
->
getClientId
();
if
(
is_null
(
$clientId
))
return
null
;
$clientId
=
$account
->
getClientId
();
if
(
is_null
(
$clientId
))
return
null
;
$clientSecret
=
$account
->
getClientSecret
();
if
(
is_null
(
$clientSecret
))
return
null
;
$clientSecret
=
$account
->
getClientSecret
();
if
(
is_null
(
$clientSecret
))
return
null
;
$response
=
$this
->
httpClient
->
post
(
$baseURL
.
"/token"
,
[
"form_params"
=>
[
"client_id"
=>
$clientId
,
"client_secret"
=>
$clientSecret
,
"grant_type"
=>
"refresh_token"
,
"refresh_token"
=>
$refreshToken
]
]);
$response
=
$this
->
httpClient
->
post
(
$baseURL
.
"/token"
,
[
"form_params"
=>
[
"client_id"
=>
$clientId
,
"client_secret"
=>
$clientSecret
,
"grant_type"
=>
"refresh_token"
,
"refresh_token"
=>
$refreshToken
]
]);
$body
=
$response
->
getBody
();
if
(
is_null
(
$body
))
return
null
;
$body
=
$response
->
getBody
();
if
(
is_null
(
$body
))
return
null
;
$content
=
$body
->
getContents
();
$body
->
close
();
if
(
is_null
(
$content
))
return
null
;
$content
=
$body
->
getContents
();
$body
->
close
();
if
(
is_null
(
$content
))
return
null
;
$data
=
@
json_decode
(
$content
,
true
);
if
(
!
$data
)
return
null
;
$data
=
@
json_decode
(
$content
,
true
);
if
(
!
$data
)
return
null
;
if
(
!
isset
(
$data
[
"access_token"
])
||
!
isset
(
$data
[
"refresh_token"
])
||
!
isset
(
$data
[
"token_type"
])
||
!
isset
(
$data
[
"expires_in"
]))
return
null
;
if
(
!
isset
(
$data
[
"access_token"
])
||
!
isset
(
$data
[
"refresh_token"
])
||
!
isset
(
$data
[
"token_type"
])
||
!
isset
(
$data
[
"expires_in"
]))
return
null
;
$expiry
=
new
DateTime
(
"now"
);
$expiry
->
add
(
new
DateInterval
(
"PT"
.
$data
[
"expires_in"
]
.
"S"
));
$expiry
=
new
DateTime
(
"now"
);
$expiry
->
add
(
new
DateInterval
(
"PT"
.
$data
[
"expires_in"
]
.
"S"
));
$this
->
entityManager
->
persist
(
$account
->
setAccessToken
(
$data
[
"access_token"
])
->
setRefreshToken
(
$data
[
"refresh_token"
])
->
setExpiry
(
$expiry
)
);
$this
->
entityManager
->
persist
(
$account
->
setAccessToken
(
$data
[
"access_token"
])
->
setRefreshToken
(
$data
[
"refresh_token"
])
->
setExpiry
(
$expiry
)
);
$this
->
entityManager
->
flush
();
$this
->
entityManager
->
flush
();
return
$account
;
return
$account
;
}
catch
(
ClientException
$e
)
{
$this
->
logger
->
info
(
"Invalid refresh token for "
.
$account
->
getService
()
.
" of user ID #"
.
$account
->
getUser
()
->
getId
());
return
null
;
}
}
}
\ No newline at end of file
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