stable

Clone or download

Read-only

OAuth2 access tokens can be used to query the REST API

Each REST endpoint can now define what's the required scope to access it with an OAuth2 access token with an annotation `@oauth2-scope`. This AOP approch has been choosed as it seems to be the easiest option to add new scopes for developers and the most secure one as it does fail open in case of issue. Others approaches has been evaluated: * force each endpoint to validate the OAuth2 access token: this will lead to a lot of copy/paste for each REST endpoint to validate and potentially refuse the access if the OAuth2 access token does not have the required scope. Also if one endpoint gets the validation wrong it means data can be accessed withotu having the proper authorization. * hiding resources declaration behind a generated proxy to filter the calls: this is not easy to integrate with Restler as it requires to have the capability to generate the code of the proxies with the annotations from the proxified resource. Also it brings the complexity of code generation and the issues that comes with it (e.g. we would need to cache the generated proxies for performance reasons) in the production code. * forcing each resource class to define what is the scope it can be accessed with: this forces to edit all the resource classes and it is not possible (without a exposing cumbersome API to the developpers) to provide fine grained scopes to, for example, distinguish read/write scopes. Having an OAuth2 access token with the required scope does give access to all information exposed by a REST endpoint behind this scope. It's a supplemental condition to access it, the usual permissions handling still applies. In order to test this contribution, a new OAuth2 scope has been introduced. 'read:project' allows to get access to information about projects in a read-only mode. To use it, you will need to create an access token associated with it: mysql > INSERT INTO oauth2_access_token (user_id, verifier) VALUES(<user_id>, SHA2('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 256)); mysql > INSERT INTO oauth2_access_token_scope (access_token_id, scope_key) VALUES(<token_autogenerated_id>, 'read:project'); shell > curl \ -H 'Authorization: Bearer tlp-oauth2-at1-<token_autogenerated_id>.6161616161616161616161616161616161616161616161616161616161616161' \ https://tuleap.example.com/api/projects This is part of story #14542: have OAuth2 flow Change-Id: I443f97f5b1796e7c14c9001106cb0514c47a7349

Modified Files

Name
M plugins/taskboard/include/REST/v1/Cell/CellPatcher.php +2 −2 Go to diff View file
M plugins/taskboard/include/REST/v1/Columns/ColumnsGetter.php +2 −2 Go to diff View file
M plugins/taskboard/phpunit/REST/v1/Cell/CellPatcherTest.php +1 −1 Go to diff View file
M plugins/taskboard/phpunit/REST/v1/Columns/ColumnsGetterTest.php +1 −1 Go to diff View file
M site-content/fr_FR/LC_MESSAGES/tuleap-core.po +6 −0 Go to diff View file
M src/common/Project/REST/v1/ProjectResource.class.php +6 −0 Go to diff View file
M src/common/REST/RESTAuthenticationFlowIsAllowed.php +13 −7 Go to diff View file
M src/common/REST/RESTCurrentUserMiddleware.php +3 −2 Go to diff View file
M src/common/REST/TuleapRESTAuthentication.php +12 −2 Go to diff View file
M src/common/REST/UserManager.class.php +91 −12 Go to diff View file
M src/common/REST/v1/MilestoneRepresentationBase.class.php +1 −1 Go to diff View file
M src/common/User/OAuth2/BearerTokenHeaderParser.php +8 −0 Go to diff View file
A src/common/User/OAuth2/Scope/NoOAuth2ScopeOnRESTEndpointException.php +35 −0 Go to diff View file
A src/common/User/OAuth2/Scope/OAuth2ProjectReadScope.php +98 −0 Go to diff View file
A src/common/User/OAuth2/Scope/OAuth2ScopeExtractorRESTEndpoint.php +69 −0 Go to diff View file
A src/common/User/OAuth2/Scope/OAuth2ScopeRESTEndpointInvalidException.php +51 −0 Go to diff View file
M tests/phpunit/common/User/OAuth2/BearerTokenHeaderParserTest.php +28 −3 Go to diff View file
A tests/phpunit/common/User/OAuth2/Scope/OAuth2ProjectReadScopeTest.php +33 −0 Go to diff View file
A tests/phpunit/common/User/OAuth2/Scope/OAuth2ScopeExtractorRESTEndpointTest.php +95 −0 Go to diff View file