Got error 500 while receiving access token

Hi! I am implementing simple OAUTH2 authorization, it works, but…

If I am not logged in Patreon yet, I click “Link your Patreon account” link, go to Patreon login page, then type email and password, then click “Allow”, go back to redirect URI at my site, then receive access token from API successfully.

But if I am already logged in Patreon, after clicking “Link your Patreon account” button and clicking “Allow” button I have error 500 from API while retrieving https://www.patreon.com/api/oauth2/token URL.

If I am logging out Patreon, all ok again (thru Patreon login page)

My code of redirect_uri page (PHP):

$code = $_REQUEST['code']??'';
if(!empty($code)){
	$request = array(
		'code'=>$code,
		'grant_type'=>'authorization_code',
		'client_id'=>$patreon_client_id,
		'client_secret'=>$patreon_client_secret,
		'redirect_uri'=>$patreon_redirect_uri,
	);

	$opts = array('http' =>
		array(
			'method'  => 'POST',
			'header'  => 'Content-Type: application/x-www-form-urlencoded',
			'content' => http_build_query($request),
			'ignore_errors' => true,
		)
	);
	$context  = stream_context_create($opts);
	$url = 'https://www.patreon.com/api/oauth2/token';
	$result = file_get_contents($url, false, $context);
	$result = json_decode($result, true);

	print_r($result);
}
Array
(
    [errors] => Array
        (
            [0] => Array
                (
                    [challenge_metadata] => 
                    [code] => 
                    [code_name] => InternalError
                    [detail] => An unrecoverable internal server error has occurred.
                    [id] => 1314c761-5dc4-54b6-8aad-09d9ac896a61
                    [status] => 500
                    [title] => Internal Error.
                )

        )

)