@@ -257,23 +257,23 @@ func handleDeviceFlowCallback(w http.ResponseWriter, r *http.Request, oauth oaut
257257 deviceCode , err := deviceStore .GetByUserCode (userCode )
258258 if err != nil {
259259 w .Header ().Set ("Content-Type" , "text/html" )
260- fmt .Fprint (w , `<html><body><h1>Invalid Code</h1><p> The device code is invalid or has expired.</p></body></html>` )
260+ fmt .Fprint (w , strings . Replace ( errorHTML , "{{ERROR_MESSAGE}}" , " The device code is invalid or has expired." , 1 ) )
261261 return
262262 }
263263
264264 // Get OAuth authorization code
265265 code := r .FormValue ("code" )
266266 if code == "" {
267267 w .Header ().Set ("Content-Type" , "text/html" )
268- fmt .Fprint (w , `<html><body><h1>Error</h1><p> No authorization code received.</p></body></html>` )
268+ fmt .Fprint (w , strings . Replace ( errorHTML , "{{ERROR_MESSAGE}}" , " No authorization code received." , 1 ) )
269269 return
270270 }
271271
272272 // Exchange OAuth code for token
273273 token , err := oauth .Exchange (r .Context (), code )
274274 if err != nil {
275275 w .Header ().Set ("Content-Type" , "text/html" )
276- fmt .Fprintf (w , `<html><body><h1>Error</h1><p> Failed to exchange code: %s</p></body></html>` , err .Error ())
276+ fmt .Fprint (w , strings . Replace ( errorHTML , "{{ERROR_MESSAGE}}" , fmt . Sprintf ( " Failed to exchange code: %s." , err .Error ()), 1 ))
277277 return
278278 }
279279
@@ -282,87 +282,11 @@ func handleDeviceFlowCallback(w http.ResponseWriter, r *http.Request, oauth oaut
282282 deviceCode .AccessToken = token .AccessToken
283283 if err := deviceStore .Update (deviceCode ); err != nil {
284284 w .Header ().Set ("Content-Type" , "text/html" )
285- fmt .Fprintf (w , `<html><body><h1>Error</h1><p> Failed to approve device: %s</p></body></html>` , err .Error ())
285+ fmt .Fprint (w , strings . Replace ( errorHTML , "{{ERROR_MESSAGE}}" , fmt . Sprintf ( " Failed to approve device: %s." , err .Error ()), 1 ))
286286 return
287287 }
288288
289289 // Show success page
290290 w .Header ().Set ("Content-Type" , "text/html" )
291- successHTML := `<!DOCTYPE html>
292- <html lang="en">
293- <head>
294- <meta charset="UTF-8">
295- <meta name="viewport" content="width=device-width, initial-scale=1.0">
296- <title>Device Approved - Magistrala</title>
297- <style>
298- * { margin: 0; padding: 0; box-sizing: border-box; }
299- body {
300- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
301- background: #073764;
302- min-height: 100vh;
303- display: flex;
304- align-items: center;
305- justify-content: center;
306- padding: 20px;
307- }
308- .container {
309- background: white;
310- border-radius: 16px;
311- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
312- padding: 48px;
313- max-width: 500px;
314- width: 100%;
315- text-align: center;
316- }
317- .success-icon {
318- width: 80px;
319- height: 80px;
320- margin: 0 auto 24px;
321- background: #10b981;
322- border-radius: 50%;
323- display: flex;
324- align-items: center;
325- justify-content: center;
326- }
327- .checkmark {
328- width: 50px;
329- height: 50px;
330- }
331- .checkmark-path {
332- stroke: white;
333- stroke-width: 4;
334- fill: none;
335- stroke-linecap: round;
336- stroke-linejoin: round;
337- }
338- h1 {
339- color: #073764;
340- font-size: 32px;
341- margin-bottom: 16px;
342- }
343- p {
344- color: #4a5568;
345- font-size: 18px;
346- line-height: 1.6;
347- }
348- @media (max-width: 600px) {
349- .container { padding: 32px 24px; }
350- h1 { font-size: 28px; }
351- }
352- </style>
353- </head>
354- <body>
355- <div class="container">
356- <div class="success-icon">
357- <svg class="checkmark" viewBox="0 0 52 52">
358- <path class="checkmark-path" d="M14 27l10 10 18-20"/>
359- </svg>
360- </div>
361- <h1>Device Approved!</h1>
362- <p>Your device has been successfully authorized.</p>
363- <p>You can now close this window and return to your device.</p>
364- </div>
365- </body>
366- </html>`
367291 fmt .Fprint (w , successHTML )
368292}
0 commit comments