1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > OAuth Redirect</ title >
6+ < style >
7+ body {
8+ font-family : Arial, sans-serif;
9+ padding : 20px ;
10+ text-align : center;
11+ background : # f5f5f5 ;
12+ }
13+ .container {
14+ background : white;
15+ padding : 30px ;
16+ border-radius : 8px ;
17+ box-shadow : 0 2px 10px rgba (0 , 0 , 0 , 0.1 );
18+ max-width : 400px ;
19+ margin : 50px auto;
20+ }
21+ .success {
22+ color : # 28a745 ;
23+ }
24+ .error {
25+ color : # dc3545 ;
26+ }
27+ </ style >
28+ </ head >
29+ < body >
30+ < div class ="container ">
31+ < h2 > OAuth Authorization</ h2 >
32+ < div id ="status "> Processing authorization...</ div >
33+ </ div >
34+
35+ < 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+ }
93+ }
94+ } ) ( ) ;
95+ </ script >
96+ </ body >
97+ </ html >
0 commit comments