Integration with Juno Payment API

Asked

Viewed 1,205 times

0

I’m having a hard time finalizing authentication with Juno’s api 2.0. She is asking for grant_type=client_credentials, but I’ve tried almost everything but all I got was a 400 error.

Link Doc https://dev.juno.com.br/api/v2#Operation/getAccessToken

$data = $info;
    $base64 = base64_encode("$clientID:$clientSecret");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://api.juno.com.br/authorization-server/oauth/token");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $headers = [
        'Content-Type: application/x-www-form-urlencoded;',
        'Authorization: Basic '.$base64.'',
        'Host: api.fullprog.dev',
        'grant_type=client_credentials&clientId='.$clientID.'&clientSecret='.$clientSecret.''
    ];
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $server_output = curl_exec ($ch);
    curl_close ($ch);
    $json = json_decode($server_output);
    $status = $json->status;
    if ($status == '401') {
        $errorMessage = $json->error;
        $ErroMensagem = $json->message;
        $time = date('d/m/Y H:i', strtotime($json->timestamp));
        echo 'Em '.$time.' ocorreu um erro. <br>Detalhes: '.$errorMessage.' Complemento: '.$ErroMensagem;
    }else{
        if (isset($json->error)) {
            echo $json->error.' informa: '.$json->error_description;
        }else{
            print  $server_output ;
        }
        
    }

He returns to me: Bad Request Your browser sent a request that this server could not understand.

Or

invalid_request informa: Missing Grant type

1 answer

2


You must do so:

<?php

$clientId = "ggdsgsdgd";
$clientSecret = "fsdhshtegeTl#50dS5o4e<;wzzD";

$base64 = base64_encode("{$clientId}:{$clientSecret}");

$ch = curl_init("https://sandbox.boletobancario.com/authorization-server/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/x-www-form-urlencoded",
    "Authorization: Basic {$base64}"
]);
$resultado = json_decode(curl_exec($ch));


var_dump($resultado);
  • 1

    Man, thank you so much for the answer, I was already getting lost here to learn. Thank you so much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.