@@ -33,63 +33,34 @@ <h2>OAuth Authorization</h2>
3333 </ div >
3434
3535 < script >
36- ( function ( ) {
37- const statusDiv = document . getElementById ( 'status' ) ;
38-
39- try {
40- // Parse URL fragment for access_token
41- const hash = window . location . hash . substring ( 1 ) ;
42- const params = new URLSearchParams ( hash ) ;
43-
44- const accessToken = params . get ( 'access_token' ) ;
45- const error = params . get ( 'error' ) ;
46-
47- if ( accessToken ) {
48- statusDiv . innerHTML = '<div class="success">✓ Authorization successful!<br>You can close this window.</div>' ;
49-
50- // Send token back to parent window
51- if ( window . opener ) {
52- window . opener . postMessage ( {
53- access_token : accessToken ,
54- expires_in : params . get ( 'expires_in' ) ,
55- token_type : params . get ( 'token_type' )
56- } , '*' ) ;
57- }
58-
59- // Close after a brief delay
60- setTimeout ( ( ) => {
61- window . close ( ) ;
62- } , 2000 ) ;
63-
64- } else if ( error ) {
65- statusDiv . innerHTML = '<div class="error">✗ Authorization failed:<br>' + error + '</div>' ;
66-
67- if ( window . opener ) {
68- window . opener . postMessage ( {
69- error : error ,
70- error_description : params . get ( 'error_description' )
71- } , '*' ) ;
72- }
73-
74- } else {
75- statusDiv . innerHTML = '<div class="error">✗ No authorization data received</div>' ;
76-
77- if ( window . opener ) {
78- window . opener . postMessage ( {
79- error : 'no_token_received'
80- } , '*' ) ;
81- }
82- }
83-
84- } catch ( e ) {
85- statusDiv . innerHTML = '<div class="error">✗ Error processing authorization:<br>' + e . message + '</div>' ;
86-
87- if ( window . opener ) {
88- window . opener . postMessage ( {
89- error : 'processing_error' ,
90- error_description : e . message
91- } , '*' ) ;
92- }
36+ ( function ( ) {
37+ const statusDiv = document . getElementById ( 'status' ) ;
38+ // Try to make the popup compact immediately. Some browsers block resize calls
39+ // for security/UX reasons; the try/catch keeps this safe.
40+ try { if ( window . resizeTo ) window . resizeTo ( 420 , 160 ) ; } catch ( _ ) { }
41+ function parseFragment ( ) {
42+ const hash = window . location . hash . startsWith ( '#' ) ? window . location . hash . substring ( 1 ) : window . location . hash ;
43+ const params = new URLSearchParams ( hash ) ;
44+ const obj = { } ;
45+ for ( const [ k , v ] of params . entries ( ) ) obj [ k ] = v ;
46+ return obj ;
47+ }
48+ function post ( msg ) {
49+ try { window . opener && window . opener . postMessage ( msg , '*' ) ; } catch ( _ ) { }
50+ }
51+ try {
52+ const data = parseFragment ( ) ;
53+ if ( data . access_token ) {
54+ statusDiv . innerHTML = '<div class="success">✓ Authorization successful!<br>Stänger fönstret...</div>' ;
55+ post ( { type : 'OAUTH_SUCCESS' , token : data . access_token , expires_in : data . expires_in , token_type : data . token_type } ) ;
56+ // Close quicker so the page is visible for a shorter time
57+ setTimeout ( ( ) => { try { window . close ( ) ; } catch ( _ ) { } } , 400 ) ;
58+ } else if ( data . error ) {
59+ statusDiv . innerHTML = '<div class="error">✗ Authorization failed:<br>' + data . error + '</div>' ;
60+ post ( { type : 'OAUTH_ERROR' , error : data . error , error_description : data . error_description } ) ;
61+ } else {
62+ statusDiv . innerHTML = '<div class="error">✗ No authorization data received</div>' ;
63+ post ( { type : 'OAUTH_ERROR' , error : 'no_token_received' } ) ;
9364 }
9465 } ) ( ) ;
9566 </ script >
0 commit comments