Skip to content

Commit

Permalink
fix(profile): authenticate api request
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbanSdl committed Jul 13, 2023
1 parent a1b3776 commit c4b8a11
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@
$app['etuutt.secret']
]
]);
$url = '/api/public/users/image/' . $app['session']->get('user')['login'] . '_official.jpg';
try {
$refresh = $client->post('/api/oauth/token', [ 'form_params' => [
'grant_type' => 'refresh_token',
'refresh_token' => $app['session']->get('user.etuRefreshToken')
]]);
$json = json_decode($refresh->getBody()->getContents(), true)['response'];
$app['session']->set('user.etuRefreshToken', $json['refresh_token']);

$url = '/api/public/users/image/' . $app['session']->get('user')['login'] . '_official.jpg?access_token=' . $json['access_token'];
$avatar = $client->get($url);
} catch (GuzzleException $e) {
return new Response('Unable to access profile picture', 403);
Expand Down Expand Up @@ -284,9 +291,10 @@
'grant_type' => 'refresh_token',
'refresh_token' => $refresh_token
]]);
$json = json_decode($response->getBody()->getContents(), true)['response'];

try {
$response = $client->get('/api/private/user/organizations?access_token=' . json_decode($response->getBody()->getContents(), true)['response']['access_token']);
$response = $client->get('/api/private/user/organizations?access_token=' . $json['access_token']);
} catch (GuzzleException $e) {
die($e->getMessage());
return new Response('Unable to login', 402);
Expand All @@ -300,7 +308,8 @@
}

$dolibarr = $app['dolibarr']->getMemberByLogin($json['login']);


$app['session']->set('user.etuRefreshToken', $json['refresh_token']);
if($dolibarr) {
$app['session']->set('dolibarr', $dolibarr);
$app['session']->set('user', $json);
Expand Down

0 comments on commit c4b8a11

Please sign in to comment.