Fix builtin Swagger-UI OAuth login #1142
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR intends to fix an issue when using the OAuth authentication mechanism built into Swagger-UI.
When using this mechanism, Swagger-UI authenticates against an OAuth provider on its own and then uses the retrieved access tokens for making requests to the django api. However this does not always work because Swagger-UI implements its authentication using two tabs and then accessing the initiating one via the window.opener property. This property can be null under some circumstances. One of them is that the tab where the main Swagger-UI is open, sets a Cross-Origin-Opener-Policy to a restrictive value. Django does the right thing (generally speaking) and sets it to such a restrictive value (see django docs).
This leads to errors as described in swagger-api/swagger-ui#8030.
This PR overwrites the required header for the Swagger-UI view only so that Swagger-UI can perform its authentication as intended.
Side note: Choosing the value
same-origin-allow-popups
as COOP also works depending on the OAuth provider that someone is using. Since we cannot ensure that a compatible OAuth provider is used, I chose to go for increased compatibility and a little less security here since Swagger-UI is mainly used for dev setups and documentation anyways.