This may be nothing, but filing as a security task just in case. I noticed it while investigating this comment on a routine OAuth dependency update: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/OAuth/+/1318222/comments/f454d31c_31096be4
It seems like this bug should have resulted in missing all scopes in an access token that was obtained via a refresh token, but surely we'd have noticed that. Do we have a workaround somewhere (that probably isn't needed anymore)?
I tested this locally. It works fine because we have our own ScopeRepository, and it doesn't look at the user ID when using a refresh_token grant: https://gerrit.wikimedia.org/g/mediawiki/extensions/OAuth/+/b90fe3871cbb016c4b5bb461b6f471ea7ad1b697/src/Repository/ScopeRepository.php#72
That means that we issue an access token with scopes that the user may have revoked in the meantime via OAuthManageMyGrants. This is where it gets interesting… Wouldn't that token allow performing actions that it shouldn't?
It turns out it doesn't, but I feel like this only works by accident (or, you could also say, thanks to defence-in-depth). AccessTokenEntity double-checks approved scopes here: https://gerrit.wikimedia.org/g/mediawiki/extensions/OAuth/+/b90fe3871cbb016c4b5bb461b6f471ea7ad1b697/src/Entity/AccessTokenEntity.php#165 and as a result, we store that token in oauth2_access_tokens with oaat_acceptance_id=0.
SessionProvider then mis-interprets that as an anonymous client credentials access token: https://gerrit.wikimedia.org/g/mediawiki/extensions/OAuth/+/b90fe3871cbb016c4b5bb461b6f471ea7ad1b697/src/SessionProvider.php#132 and errors out with the mwoauth-invalid-authorization-invalid-user code here: https://gerrit.wikimedia.org/g/mediawiki/extensions/OAuth/+/b90fe3871cbb016c4b5bb461b6f471ea7ad1b697/src/SessionProvider.php#187
That's definitely not the right error message, and also, doesn't that mean that legitimate anonymous client credentials access tokens also error out every time? We may have broken something in dc8b4323f9128891a799dd27a6ebd192d37aeea4.
