3
3
< body >
4
4
</ body >
5
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 ( / c o d e | t o k e n | e r r o r / . test ( window . location . hash ) ) {
15
- qp = window . location . hash . substring ( 1 ) . replace ( '?' , '&' ) ;
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 ( (
31
- oauth2 . auth . schema . get ( "flow" ) === "accessCode" ||
32
- oauth2 . auth . schema . get ( "flow" ) === "authorizationCode" ||
33
- oauth2 . auth . schema . get ( "flow" ) === "authorization_code"
34
- ) && ! oauth2 . auth . code ) {
35
- if ( ! isValid ) {
36
- oauth2 . errCb ( {
37
- authId : oauth2 . auth . name ,
38
- source : "auth" ,
39
- level : "warning" ,
40
- message : "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
41
- } ) ;
42
- }
43
-
44
- if ( qp . code ) {
45
- delete oauth2 . state ;
46
- oauth2 . auth . code = qp . code ;
47
- oauth2 . callback ( { auth : oauth2 . auth , redirectUrl : redirectUrl } ) ;
48
- } else {
49
- let oauthErrorMsg
50
- if ( qp . error ) {
51
- oauthErrorMsg = "[" + qp . error + "]: " +
52
- ( qp . error_description ? qp . error_description + ". " : "no accessCode received from the server. " ) +
53
- ( qp . error_uri ? "More info: " + qp . error_uri : "" ) ;
54
- }
55
-
56
- oauth2 . errCb ( {
57
- authId : oauth2 . auth . name ,
58
- source : "auth" ,
59
- level : "error" ,
60
- message : oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
61
- } ) ;
62
- }
63
- } else {
64
- oauth2 . callback ( { auth : oauth2 . auth , token : qp , isValid : isValid , redirectUrl : redirectUrl } ) ;
65
- }
66
- window . close ( ) ;
67
- }
68
-
69
- if ( document . readyState !== 'loading' ) {
70
- run ( ) ;
71
- } else {
72
- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
73
- run ( ) ;
74
- } ) ;
75
- }
76
- </ script >
6
+ < script src ="oauth2-redirect.js "> </ script >
0 commit comments