8 – OAuth2 Server sending ‘null’ as the ‘sub’ parameter instead of User Id

When using OAuth2 Server module to authorize with users, I am not receiving the correct “sub” parameter in the response from the server. I get all the other fields such as email, email_verified, name, preferred_username, and zoneinfo; just not the sub parameter.

{
  "sub": null,
  "email": "someuser@email.com",
  "email_verified": true,
  "name": "SomeUser",
  "preferred_username": "SomeUser",
  "zoneinfo": "Asia/Dubai"
}

I’ve tried using hook_oauth2_server_user_claims to alter this parameter like so:

function my_module_oauth_server_user_claims($account, $requested_scopes) {
  $claims = ();

  if (in_array('profile', $requested_scopes)) {
    $claims('sub') = $account->id();
    $claims('user_id') = $account->id(); // for debugging purposes
  }

  return $claims;
} 

Doing this adds the user_id parameter to the response body, but the ‘sub’ is still set as ‘null’, therefore it must get override afterwards.

I double checked the documentation and have all the permissions set, but can’t find anything about this particular issue.. Why is `sub’ not being populated correctly during this process?