-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix authorization grant and walert widget
- Loading branch information
HugoMartineau
committed
Oct 10, 2024
1 parent
9078497
commit 375569e
Showing
9 changed files
with
198 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<?php | ||
|
||
/* | ||
Enable to debug | ||
ini_set('display_errors', 1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,55 @@ | ||
<?php | ||
use GuzzleHttp\Psr7\Message; | ||
require 'app/Config.php'; | ||
|
||
$repository = Config::getInstance()->repo; | ||
$apiWrapper = Config::getInstance()->apiWrapper; | ||
|
||
$organizationSlug = $_GET['organizationSlug']; | ||
if($organizationSlug == null) | ||
{ | ||
throw new Exception("Erreur : OrganizationSlug introuvable"); | ||
} | ||
|
||
$partnerTokenData = $apiWrapper->getAccessTokensAndRefreshIfNecessary(null); | ||
$accessToken = $partnerTokenData['access_token']; | ||
//Vérification si l'association à déjà lié son compte | ||
//Récupération du refresh_token de l'association en BDD pour voir si c'est nécessaire de générer une URL de mire | ||
$organizationToken = $repository->getAccessTokensDB($organizationSlug); | ||
|
||
$apiWrapper->setClientDomain(Config::getInstance()->webSiteDomain, $accessToken); | ||
if ($organizationToken != null) | ||
{ | ||
//Nous avons réussi à récupérer un token de l'association | ||
//Si on peut rafraichir ce token c'est qu'il est encore valide | ||
try | ||
{ | ||
$decryptedOrganizationRefreshToken = Helpers::decryptToken($organizationToken['refresh_token']); | ||
$refreshToken = $apiWrapper->refreshToken( $decryptedOrganizationRefreshToken, $organizationSlug); | ||
echo 'Nous possédons déjà un token pour le compte ' . $organizationSlug . ' et nous l\'avons rafraichi, vous pouvez fermer cette page.'; | ||
} | ||
catch (Exception $e) | ||
{ | ||
redirectionToAuthorizationUrl(); | ||
} | ||
} | ||
else | ||
{ | ||
redirectionToAuthorizationUrl(); | ||
} | ||
|
||
// Générer l'URL d'autorisation | ||
$authorizationUrl = $apiWrapper->generateAuthorizationUrl($organizationSlug); | ||
function redirectionToAuthorizationUrl() | ||
{ | ||
global $apiWrapper; | ||
global $organizationSlug; | ||
|
||
// Rediriger vers l'URL générée | ||
header('Location: ' . $authorizationUrl); | ||
exit; | ||
// Nous ne possédons pas de Refresh valide pour cette association, nous allons donc générer une Url pour la liaison | ||
// Récupération du token global HelloassoCharityStream pour set le domain (important pour la mire) | ||
$globalTokens = $apiWrapper->getGlobalTokensAndRefreshIfNecessary(); | ||
$globalAccessToken = $globalTokens['access_token']; | ||
|
||
$apiWrapper->setClientDomain(Config::getInstance()->webSiteDomain, $globalAccessToken); | ||
|
||
// Générer l'URL d'autorisation | ||
$authorizationUrl = $apiWrapper->generateAuthorizationUrl($organizationSlug); | ||
|
||
// Rediriger vers l'URL générée | ||
header('Location: ' . $authorizationUrl); | ||
} |
Oops, something went wrong.