oauth2-redirect.html has script outside html tags
How can we help?
If you examine the contents of the following file in the repository : https://github.com/swagger-api/swagger-ui/blob/master/dist/oauth2-redirect.html you see that the script node is outside the closing html tag Why is this ?
I guess the script should be inside the <head> or <body> tag and not outside the <html> tag.
https://github.com/swagger-api/swagger-ui/blob/master/dist/oauth2-redirect.html
Otherwise, the browser cannot parse the script, and therefore the run() function is not defined at onload.
Chrome 83.0.4103.61
Firefox 76.0.1

Q&A
- OS: Fedora 32
- Browser: Chrome / Firefox
- Version: 83.0.4103.61 / 76.0.1
- Method of installation: GitHub release ZIP file using WebJars Swagger UI https://www.webjars.org/
- Swagger-UI version: 3.25.3
- Swagger/OpenAPI version: OpenAPI 3.0.1
Content & configuration
Example Swagger/OpenAPI definition:
# The rest of the OpenAPI definition is redacted because it should not be important here
securitySchemes:
Keycloak:
type: oauth2
description: Keycloak Identity and Access Management
flows:
implicit:
authorizationUrl: https://keycloak.example.com/auth/realms/master/protocol/openid-connect/auth
refreshUrl: https://keycloak.example.com/auth/realms/master/protocol/openid-connect/token
scopes:
profile: 'OpenID Connect built-in scope: profile'
email: 'OpenID Connect built-in scope: email'
roles: 'OpenID Connect built-in scope: roles
Swagger-UI configuration options:
window.onload = function() {
const location = window.location;
const baseUrl = `${location.origin}/${location.pathname.split('/')[1]}`;
const ui = SwaggerUIBundle({
url: `${baseUrl}/v1/openapi.yaml`,
oauth2RedirectUrl: `${baseUrl}/webjars/swagger-ui/3.25.3/oauth2-redirect.html`,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
validatorUrl: "https://validator.swagger.io/validator",
layout: "StandaloneLayout"
});
ui.initOAuth({
appName: "My Keycloak App Name",
clientId: "my_keycloak_client_id"
});
window.ui = ui;
};
Describe the bug you're encountering
The run() function is not executed onload.
To reproduce...
Steps to reproduce the behavior:
- Use an implicit OAuth2 flow with Keycloak
Expected behavior
oauth2-redirect.html should execute the onload="run()" function and validate the OAuth2 bearer token, state etc. from the window.location.hash and close the window after successfull validation.
Screenshots
Chrome 83.0.4103.61
Firefox 76.0.1

Additional context or thoughts
The <script>....</script> should be in the <head> or <body> tag and not outside the <html> tag.
The W3C Markup Validation Service https://validator.w3.org/nu/?showsource=yes&doc=https://gitcdn.link/cdn/swagger-api/swagger-ui/master/dist/oauth2-redirect.html
This was fixed by 482dea8f534ca44c4d4bc2fca0466b7c859ce5e7 in the copy of the file in the dist directory, but not the copy in dev-helpers. Recently, 35eb10306c7695e31abd7782f2b6b21bbf2599a7 broke this again and it now is broken in both copies. I'm also confused as to what the relationship between these two files is. Are they supposed to be modified in tandem, or is a release commit such as 26e6d3cce2a49195681116c97318b2a38c06e21c supposed to update the dist copy based on the dev-helpers copy? There seems to be a mix of commits that update both copies, or just one of them.
hey @hannes-ucsc 👋
as configured here https://github.com/swagger-api/swagger-ui/blob/2814709f37a80a4c9b974da6a5cb9fc5c7789771/webpack/bundle.js#L50
oauth2-redirect.html file in the dist directory is the copy of the file from dev-helpers and therefore they should be updated in tandem during release
I've created a PR to address the issue https://github.com/swagger-api/swagger-ui/pull/10593
:tada: This issue has been resolved in version 5.29.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Thanks @robert-hebel-sb