4 <title>Swagger UI: OAuth2 Redirect
</title>
10 var oauth2
= window
.opener
.swaggerUIRedirectOauth2
;
11 var sentState
= oauth2
.state
;
12 var redirectUrl
= oauth2
.redirectUrl
;
15 if (/code|token|error/.test(window
.location
.hash
)) {
16 qp
= window
.location
.hash
.substring(1);
18 qp
= location
.search
.substring(1);
22 arr
.forEach(function (v
,i
,_arr
) { _arr
[i
] = '"' + v
.replace('=', '":"') + '"';});
23 qp
= qp
? JSON
.parse('{' + arr
.join() + '}',
24 function (key
, value
) {
25 return key
=== "" ? value
: decodeURIComponent(value
);
29 isValid
= qp
.state
=== sentState
;
32 oauth2
.auth
.schema
.get("flow") === "accessCode" ||
33 oauth2
.auth
.schema
.get("flow") === "authorizationCode" ||
34 oauth2
.auth
.schema
.get("flow") === "authorization_code"
35 ) && !oauth2
.auth
.code
) {
38 authId
: oauth2
.auth
.name
,
41 message
: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
47 oauth2
.auth
.code
= qp
.code
;
48 oauth2
.callback({auth
: oauth2
.auth
, redirectUrl
: redirectUrl
});
52 oauthErrorMsg
= "["+qp
.error
+"]: " +
53 (qp
.error_description
? qp
.error_description
+ ". " : "no accessCode received from the server. ") +
54 (qp
.error_uri
? "More info: "+qp
.error_uri
: "");
58 authId
: oauth2
.auth
.name
,
61 message
: oauthErrorMsg
|| "[Authorization failed]: no accessCode received from the server"
65 oauth2
.callback({auth
: oauth2
.auth
, token
: qp
, isValid
: isValid
, redirectUrl
: redirectUrl
});
70 window
.addEventListener('DOMContentLoaded', function () {