get_swagger_ui_oauth2_redirect_html() — fastapi Function Reference
Architecture documentation for the get_swagger_ui_oauth2_redirect_html() function in docs.py from the fastapi codebase.
Entity Profile
Dependency Diagram
graph TD 9e591d9c_65d6_09d8_497c_322cdf94b4b4["get_swagger_ui_oauth2_redirect_html()"] 6383cfb2_5918_5c8c_5124_dbbbe44fbe24["docs.py"] 9e591d9c_65d6_09d8_497c_322cdf94b4b4 -->|defined in| 6383cfb2_5918_5c8c_5124_dbbbe44fbe24 bf57980b_6b1e_4f1a_9a9d_0deef75f4dcb["swagger_ui_redirect()"] bf57980b_6b1e_4f1a_9a9d_0deef75f4dcb -->|calls| 9e591d9c_65d6_09d8_497c_322cdf94b4b4 447eb742_fe66_0f29_323a_09cc3b35a3b6["swagger_ui_redirect()"] 447eb742_fe66_0f29_323a_09cc3b35a3b6 -->|calls| 9e591d9c_65d6_09d8_497c_322cdf94b4b4 c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d["setup()"] c029d7d0_68b4_7ce7_47cc_25c5b9dccd5d -->|calls| 9e591d9c_65d6_09d8_497c_322cdf94b4b4 style 9e591d9c_65d6_09d8_497c_322cdf94b4b4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
fastapi/openapi/docs.py lines 287–375
def get_swagger_ui_oauth2_redirect_html() -> HTMLResponse:
"""
Generate the HTML response with the OAuth2 redirection for Swagger UI.
You normally don't need to use or change this.
"""
# copied from https://github.com/swagger-api/swagger-ui/blob/v4.14.0/dist/oauth2-redirect.html
html = """
<!doctype html>
<html lang="en-US">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1).replace('?', '&');
} else {
qp = location.search.substring(1);
}
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value);
}
) : {};
isValid = qp.state === sentState;
if ((
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does get_swagger_ui_oauth2_redirect_html() do?
get_swagger_ui_oauth2_redirect_html() is a function in the fastapi codebase, defined in fastapi/openapi/docs.py.
Where is get_swagger_ui_oauth2_redirect_html() defined?
get_swagger_ui_oauth2_redirect_html() is defined in fastapi/openapi/docs.py at line 287.
What calls get_swagger_ui_oauth2_redirect_html()?
get_swagger_ui_oauth2_redirect_html() is called by 3 function(s): setup, swagger_ui_redirect, swagger_ui_redirect.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free