dynamic sso client data
This commit is contained in:
parent
e50bb0402a
commit
4b92e83f15
|
|
@ -4,31 +4,30 @@ namespace App\Service\SSO;
|
|||
|
||||
|
||||
use App\Entity\Project;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use League\Bundle\OAuth2ServerBundle\Model\Client;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class ProjectService
|
||||
{
|
||||
public function __construct(private readonly HttpClientInterface $httpClient,
|
||||
private string $appUrl,
|
||||
private string $clientSecret)
|
||||
private string $clientIdentifier, private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
}
|
||||
|
||||
// Inside your SSO Server Service
|
||||
public function createRemoteProject(string $clientAppUrl, Project $project): void
|
||||
{
|
||||
// 1. Get a token for "ourselves"
|
||||
// 1. Get a token for "ourselves" -> on en a besoin parce que c'est du M2M.
|
||||
$portalClient = $this->entityManager->getRepository(Client::class)->findOneBy(['identifier' => $this->clientIdentifier]);
|
||||
$tokenResponse = $this->httpClient->request('POST', $this->appUrl . 'token', [
|
||||
'auth_basic' => ['afc7b28b95b61aeeeae8eaed94c5cfe1', $this->clientSecret], // ID and Secret go here
|
||||
'auth_basic' => [$portalClient->getIdentifier(),$portalClient->getSecret()], // ID and Secret go here
|
||||
'body' => [
|
||||
'grant_type' => 'client_credentials',
|
||||
// 'scope' => 'project_sync'
|
||||
],
|
||||
]);
|
||||
// if (400 === $tokenResponse->getStatusCode() || 500 === $tokenResponse->getStatusCode()) {
|
||||
// // This will print the actual OAuth2 error (e.g., "invalid_scope" or "unsupported_grant_type")
|
||||
// dd($tokenResponse->getContent(false));
|
||||
// }
|
||||
|
||||
$accessToken = $tokenResponse->toArray()['access_token'];
|
||||
// data must match easy check database
|
||||
$projectJson = [
|
||||
|
|
|
|||
Loading…
Reference in New Issue