Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint Token error : invalid grant_type #5

Open
lolafrerot opened this issue Jun 20, 2022 · 1 comment
Open

Endpoint Token error : invalid grant_type #5

lolafrerot opened this issue Jun 20, 2022 · 1 comment

Comments

@lolafrerot
Copy link

Hello,

En voulant accéder au endpoint TOKEN en phase de dev (https://fcp.integ01.dev-franceconnect.fr/api/v1/token) j'obtiens le résultat suivant :

400 Bad Request response: {"status":"fail","message":"invalid_grant"}

En utilisant la librairie PHP Guzzle, voici l'appel au endpoint :

$client = new GuzzleHttp\Client();
$response = $client->request('POST', $providerBaseUrl.'token', [
                        "form_params" => [
                          "grant_type" =>"authorization_code",
                          "code" => $code,
                          "redirect_uri" => urlencode(get_permalink($idPageFranceConnect)).'?action=FCloginToken',
                          "client_id" => $clientId, 
                          "client_secret" => $clientSecret                          
                        ]
                    ]);  

L'accès au endpoint 'Authorization' ne pose en revanche aucun souci !

Est-ce que quelqu'un a déjà été confronté au problème ?

Lola

@celidrissi
Copy link

celidrissi commented Nov 28, 2022

Bonjour Lola,

A tu pu résoudre ton problème depuis ? (J'espere que oui)

Pour ceux qui passerait par là, moi ça marche comme ca :

protected function getToken(string $code)
{
    data = [
          "grant_type" => "authorization_code",
          "redirect_uri" => $this->redirectURI, //Liens de redirection non encodé (Guzzle le fait déja)
          "client_id" => $this->clientID,
          "client_secret" => $this->clientSecret,
          "code" => $code
    ];

    $params = [
          "headers" => [
                // Le header n'est pas le meme en fonction de la version de FranceConnect
                "Content-Type" => $this->version == "v1" ? "application/json" : "application/x-www-form-urlencoded",
         ],
    ];

    $this->version == "v1" ? $params["json"] = $data : $params["form_params"] = $data;

    $request =  $this->clientFC->request("POST", "/api/". $this->version ."/token", $params);
    return json_decode($request->getBody()->getContents());
}

En vous laissant le soin d'ajouter des try / catch (Par exemple BadResponseException / ConnectException)

Chafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants