Discussions

Ask a Question
Back to All

Authentication Test Failed

Hello,
I always receive an authentication failed response (role=public).
Here is the full code

$keyId = 'qr00fekd2ld3kaqjrli7c01jmdmnq57tngni3qldaq1qtipk2da2ddi15d4huci6n21t2cohb8gcb5ei007cea1b4g4rktmn9iq42v2r463i831kj7qlici5oo1gc886ph0e8757bcf15b6gpll266a4a7fic769gd7dfsnj2gdnp3qgj86um742be7ctmmajj9d4gb9';

        $post = [
            'flow' => 'MATCH_CODE',
            'amount_unit' => '100',
            'currency' => 'EUR',
            'callback_url' => 'https://myServer.com/myCallbackUrl?payment_id={uuid}',
            'metadata' => array("order_id" => "my_order_id",
                "user" => "10",
                "payment_id" => "PPP12345"
                ),
        ];


        $reqDate = 'Tue, 28 Apr 20 10:18:42 +0000';// gmdate(DATE_RFC822);
  
  $digest = base64_encode(hash("sha256", json_encode($post), true));
        

//GENERATED DIGEST IS mI0YGicSLEGMd5/XQcexSVOLL7pbM4XXmXoX0spADsI=

        $string = "(request-target): post /wally-services/protocol/tests/signature\n
                    host: staging.authservices.satispay.com\n
                    date: $reqDate\n
                    digest: SHA-256=$digest";
    
        $pkey = openssl_pkey_get_private(file_get_contents($path.'/private.pem'));
        
        openssl_sign($string, $signatureRaw, $pkey, OPENSSL_ALGO_SHA256);
       
        $signature = base64_encode($signatureRaw);
        

// GENERATED SIGNATURE IS QJ8eCV9RbyiXttn8gDMBk/LNc771wvg56vKpP5bU5C9UPQWWo/zuygJ6i5nobCp0EPoh7jgBhd9q9hvwxtW9HqXsUe3RWZOZWSKVGLuZLSFCeRy3dECFedtJRxclTbvDxe7uB14+Iprv8ALUR0Vp/04k0ZAWJ18Fw9jRn0ojSPO2GaZHKUlj5vjELLwVQHMevz76RlKyh1VK/IFznuGjrgxJV1TJEJSxsbE63I88RBslPetZD9iBhGx/nqK/dCa7QTpjiTrJyS+46rSRi8no0rSTLwx+b29LIh2eXSsnihM6vY/kIe65faUFySUp3iYlApKf3Mp3lrvXp6IeZa8TI2qz/pxH7jp2DTJUDEdab/x9qlz4zljwKpbwGJ7iSlJ2K6Bh/bNO5A1GUEgBdWvCSBd4e9fu8LTYCIG3VImpHDrTXY5/bY3LBcaIW9QsK00lK52gwOK93djAz/DXUeD0omjnRJnymQQ9ta0HS+ts06VdB2WzjwfmDRcB704nGGIqz4nWxRyQKmfj+zZf3rFc5j3cXtNUD/aMvKvc7Rd8tZJMJpFZBZQQUdm8HsauHfHmPEJMout9EKvDC1x0vCS+vW6j8zDydGxvNoP0v7Db9p38Tm03jgPo9dNqV6g3G9CmjXhJosXxsXGRpphVQkRWtCK3AFS7LJwcFABgAi6E4bg=

        $authorizationHeader = "Signature keyId=\"$keyId\", algorithm=\"rsa-sha256\", headers=\"(request-target) host date digest\", signature=\"$signature\"";
        openssl_free_key($pkey);
    
        // Test the Authentication
        
       

$url = 'https://staging.authservices.satispay.com/wally-services/protocol/tests/signature';

$ch = curl_init($url);

$customHeaders = array(
'host: staging.authservices.satispay.com',
'Content-Type: application/json',
'Accept: application/json',
'date: ' . $reqDate,
'digest: ' . $digest,
'Authorization: ' . $authorizationHeader,
);

        curl_setopt($ch, CURLOPT_HTTPHEADER, $customHeaders);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, Json::encode($post));

        $result = curl_exec($ch);

Can you please tell me what i'm doing wrong?

Regards