From df102d14d1225041fae47b781259d16a71669448 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Sat, 7 Oct 2023 07:54:21 +0200 Subject: [PATCH] [IMP] base_rest: base_rest: Define the oauth2 redirect url into swagger ui Add support for oauth2 security scheme in the Swagger UI. If your openapi specification contains a security scheme of type oauth2, the Swagger UI will display a login button in the top right corner. In order to finalize the login process, a redirect URL must be provided when initializing the Swagger UI. The Swagger UI is now initialized with a `oauth2RedirectUrl` option that references a oauth2-redirect.html file provided by the swagger-ui lib and served by the current addon. --- base_rest/readme/newsfragments/.gitignore | 0 base_rest/readme/newsfragments/379.feature | 7 +++++++ base_rest/static/src/js/swagger_ui.js | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 base_rest/readme/newsfragments/.gitignore create mode 100644 base_rest/readme/newsfragments/379.feature diff --git a/base_rest/readme/newsfragments/.gitignore b/base_rest/readme/newsfragments/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/base_rest/readme/newsfragments/379.feature b/base_rest/readme/newsfragments/379.feature new file mode 100644 index 00000000..d1ea9609 --- /dev/null +++ b/base_rest/readme/newsfragments/379.feature @@ -0,0 +1,7 @@ +Add support for oauth2 security scheme in the Swagger UI. If your openapi +specification contains a security scheme of type oauth2, the Swagger UI will +display a login button in the top right corner. In order to finalize the +login process, a redirect URL must be provided when initializing the Swagger +UI. The Swagger UI is now initialized with a `oauth2RedirectUrl` option that +references a oauth2-redirect.html file provided by the swagger-ui lib and served +by the current addon. diff --git a/base_rest/static/src/js/swagger_ui.js b/base_rest/static/src/js/swagger_ui.js index c3ca1ae6..6a8b00ba 100644 --- a/base_rest/static/src/js/swagger_ui.js +++ b/base_rest/static/src/js/swagger_ui.js @@ -43,6 +43,9 @@ odoo.define("base_rest.swagger_ui", function (require) { $(".topbar").prepend(this.web_btn); } }, + oauth2RedirectUrl: + window.location.origin + + "/base_rest/static/lib/swagger-ui-3.51.1/oauth2-redirect.html", }; const config = this.$el.data("settings"); return Object.assign({}, defaults, config);