Page MenuHomePhabricator

Improve test coverage for OAuth2 authorization and token exchange
Open, Needs TriagePublic

Description

This involves writing an integration test to verify the REST API handlers that handle authorization and token exchange for OAuth2 consumers. The corresponding classes are:

  • Authorize (endpoint: /oauth2/authorize)
  • AccessToken (endpoint: /oauth2/access_token)
  • ResetClientSecret (endpoint: /oauth2/client/{client_key}/reset_secret)

We already have a way to write integration tests for REST API handlers in MediaWiki using the HandlerTestTrait trait. Some good examples can be found at: https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/0aa7ce021b7904ed4f63f941f307f0143a32d0bf/tests/phpunit/integration/includes/Rest/Handler

Impact

Event Timeline

OAuth 2 has several flows ("grants").

  • authorization code flow (with or without a PKCE challange, depending on whether the client is confidential): /oauth2/authorize to show authorization dialog, and then /oauth2/access_token. (Note that /oauth2/authorize is just a redirect to SpecialMWOAuth/approve.)
  • refresh token flow: call /oauth2/access_token to exchange a refresh token for an access token
  • client credentials: call /oauth2/access_token with whatever we use as client credentials. TBH I have no idea about the details of this.

ResetClientSecret belongs to T416490: Improve test coverage of SpecialMWOAuthConsumerRegistration (it's the API equivalent of /update).