Hi @matti.kiviharju,
"sub" => 'urn:atlassian:connect:useraccountid:'.$appKey,
Instead of $appKey that should be the accountId of the user.
On another note, you need to replace the authorization server hostname auth.atlassian.io with oauth-2-authorization-server.services.atlassian.com.
The deprecation notice from July 2020 is here.