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.
                )

        )

)

Is no one encountered such issue? My creator account is pretty new and have no patrons except test one. I am trying to log in with account, registered via google email, trying to log in with one, registered with email and password - no difference.

I think it might be issue with oauth API. I do all correct, if I still not logged in and authorizing before allowing site access to my personal data, all works fine.

But if I do such things being already logged in, i get error 500 with SAME code.

I changed something:

Previously empty scope parameter in “Link your Patreon account” link now is “identity.memberships”.

So now I have fine result in both cases, if I logged in or not logged in at Patreon yet.