blob: a7eb162d10fe4e04b797e58ea4fbda70b046dff9 [file] [log] [blame]
Matteo Scandolo431781c2017-09-06 15:33:07 -07001<!doctype html>
2<html lang="en-US">
3<body onload="run()">
4</body>
5</html>
6<script>
7 'use strict';
8 function run () {
9 var oauth2 = window.opener.swaggerUIRedirectOauth2;
10 var sentState = oauth2.state;
11 var redirectUrl = oauth2.redirectUrl;
12 var isValid, qp, arr;
13
14 if (/code|token|error/.test(window.location.hash)) {
15 qp = window.location.hash.substring(1);
16 } else {
17 qp = location.search.substring(1);
18 }
19
20 arr = qp.split("&")
21 arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
22 qp = qp ? JSON.parse('{' + arr.join() + '}',
23 function (key, value) {
24 return key === "" ? value : decodeURIComponent(value)
25 }
26 ) : {}
27
28 isValid = qp.state === sentState
29
30 if (oauth2.auth.schema.get("flow") === "accessCode" && !oauth2.auth.code) {
31 if (!isValid) {
32 oauth2.errCb({
33 authId: oauth2.auth.name,
34 source: "auth",
35 level: "warning",
36 message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
37 });
38 }
39
40 if (qp.code) {
41 delete oauth2.state;
42 oauth2.auth.code = qp.code;
43 oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
44 } else {
45 oauth2.errCb({
46 authId: oauth2.auth.name,
47 source: "auth",
48 level: "error",
49 message: "Authorization failed: no accessCode received from the server"
50 });
51 }
52 } else {
53 oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
54 }
55 window.close();
56 }
57</script>