@@ -48,72 +48,65 @@ function handleLogin() {
4848 str += '</label></li>' ;
4949 popup . append ( str ) ;
5050 }
51-
52-
53- var $win = $ ( window ) ,
54- dw = $win . width ( ) ,
55- dh = $win . height ( ) ,
56- st = $win . scrollTop ( ) ,
57- dlgWd = popupDialog . outerWidth ( ) ,
58- dlgHt = popupDialog . outerHeight ( ) ,
59- top = ( dh - dlgHt ) / 2 + st ,
60- left = ( dw - dlgWd ) / 2 ;
61-
62- popupDialog . css ( {
63- top : ( top < 0 ? 0 : top ) + 'px' ,
64- left : ( left < 0 ? 0 : left ) + 'px'
65- } ) ;
66-
67- popupDialog . find ( 'button.api-popup-cancel' ) . click ( function ( ) {
68- popupMask . hide ( ) ;
69- popupDialog . hide ( ) ;
70- } ) ;
71- popupDialog . find ( 'button.api-popup-authbtn' ) . click ( function ( ) {
72- popupMask . hide ( ) ;
73- popupDialog . hide ( ) ;
74-
75- var authSchemes = window . swaggerUi . api . authSchemes ;
76- var location = window . location ;
77- var locationUrl = location . protocol + '//' + location . host + location . pathname ;
78- var redirectUrl = locationUrl . replace ( "index.html" , "" ) . concat ( "/o2c.html" ) . replace ( "//o2c.html" , "/o2c.html" ) ;
79- var url = null ;
80-
81- var p = window . swaggerUi . api . authSchemes ;
82- for ( var key in p ) {
83- if ( p . hasOwnProperty ( key ) ) {
84- var o = p [ key ] . grantTypes ;
85- for ( var t in o ) {
86- if ( o . hasOwnProperty ( t ) && t === 'implicit' ) {
87- var dets = o [ t ] ;
88- url = dets . loginEndpoint . url + "?response_type=token" ;
89- window . swaggerUi . tokenName = dets . tokenName ;
90- }
51+ }
52+
53+ var $win = $ ( window ) ,
54+ dw = $win . width ( ) ,
55+ dh = $win . height ( ) ,
56+ st = $win . scrollTop ( ) ,
57+ dlgWd = popupDialog . outerWidth ( ) ,
58+ dlgHt = popupDialog . outerHeight ( ) ,
59+ top = ( dh - dlgHt ) / 2 + st ,
60+ left = ( dw - dlgWd ) / 2 ;
61+
62+ popupDialog . css ( {
63+ top : ( top < 0 ? 0 : top ) + 'px' ,
64+ left : ( left < 0 ? 0 : left ) + 'px'
65+ } ) ;
66+
67+ popupDialog . find ( 'button.api-popup-cancel' ) . click ( function ( ) {
68+ popupMask . hide ( ) ;
69+ popupDialog . hide ( ) ;
70+ } ) ;
71+ popupDialog . find ( 'button.api-popup-authbtn' ) . click ( function ( ) {
72+ popupMask . hide ( ) ;
73+ popupDialog . hide ( ) ;
74+
75+ var authSchemes = window . swaggerUi . api . authSchemes ;
76+ var host = window . location ;
77+ var pathname = location . pathname . substring ( 0 , location . pathname . lastIndexOf ( "/" ) ) ;
78+ var redirectUrl = host . protocol + '//' + host . host + pathname + "/o2c.html" ;
79+ var url = null ;
80+
81+ for ( var key in authSchemes ) {
82+ if ( authSchemes . hasOwnProperty ( key ) ) {
83+ var o = authSchemes [ key ] . grantTypes ;
84+ for ( var t in o ) {
85+ if ( o . hasOwnProperty ( t ) && t === 'implicit' ) {
86+ var dets = o [ t ] ;
87+ url = dets . loginEndpoint . url + "?response_type=token" ;
88+ window . swaggerUi . tokenName = dets . tokenName ;
9189 }
9290 }
9391 }
94- var scopes = [ ] ;
95- var scopeForUrl = '' ;
96- var o = $ ( '.api-popup-scopes' ) . find ( 'input:checked' ) ;
97-
98- for ( var k = 0 ; k < o . length ; k ++ ) {
99- scopes . push ( $ ( o [ k ] ) . attr ( "scope" ) ) ;
100- if ( k > 0 ) {
101- scopeForUrl += ' ' ;
102- }
103- scopeForUrl += $ ( o [ k ] ) . attr ( "scope" ) ;
104- }
92+ }
93+ var scopes = [ ]
94+ var o = $ ( '.api-popup-scopes' ) . find ( 'input:checked' ) ;
10595
106- window . enabledScopes = scopes ;
107-
96+ for ( k = 0 ; k < o . length ; k ++ ) {
97+ scopes . push ( $ ( o [ k ] ) . attr ( "scope" ) ) ;
98+ }
10899
109- url += '&redirect_uri=' + encodeURIComponent ( redirectUrl ) ;
110- url += '&realm=' + encodeURIComponent ( realm ) ;
111- url += '&client_id=' + encodeURIComponent ( clientId ) ;
112- url += '&scope=' + encodeURIComponent ( scopeForUrl ) ;
100+ window . enabledScopes = scopes ;
101+
102+ url += '&redirect_uri=' + encodeURIComponent ( redirectUrl ) ;
103+ url += '&realm=' + encodeURIComponent ( realm ) ;
104+ url += '&client_id=' + encodeURIComponent ( clientId ) ;
105+ url += '&scope=' + encodeURIComponent ( scopes ) ;
106+
107+ window . open ( url ) ;
108+ } ) ;
113109
114- window . open ( url ) ;
115- } ) ;
116- }
117110 popupMask . show ( ) ;
118111 popupDialog . show ( ) ;
119112 return ;
@@ -211,7 +204,7 @@ function onOAuthComplete(token) {
211204 }
212205 } ) ;
213206
214- window . authorizations . add ( "key " , new ApiKeyAuthorization ( "Authorization" , "Bearer " + b , "header" ) ) ;
207+ window . authorizations . add ( "oauth2 " , new ApiKeyAuthorization ( "Authorization" , "Bearer " + b , "header" ) ) ;
215208 }
216209 }
217210 }
0 commit comments