using Microsoft.AspNetCore.Mvc; using RadicadeServer.DB; namespace RadicadeServer.Auth { [Route("/")] public class DeviceApprovalAPI : Controller { public DeviceApprovalAPI() { } [HttpGet("device")] public IActionResult Device([FromQuery(Name = "user_code")] string userCode) { var (found, approved, accountId, expiresUtc) = StudioAuthAPI.DescribeUserCode(userCode); return Content(DevicePage(userCode, found, approved, accountId, expiresUtc), "text/html"); } private static string DevicePage(string userCode, bool found, bool approved, long accountId, DateTime expiresUtc) { var glyph = found && approved ? "✅" : found ? "⏳" : "⚠️"; var color = found && approved ? "#16a34a" : found ? "#d97706" : "#dc2626"; var title = found && approved ? "Approved" : found ? "Waiting for approval" : "Code not recognised"; var body = found && approved ? "This server signs Rec Room Studio in automatically, so this code is already approved as account " + accountId + ". Close this tab and go back to Unity." : found ? "The code is valid, but it has not been approved yet. Return to Unity and try again." : "This server has no pending sign-in for that code - it may have expired, or it may already have been used (device codes are single use). Start the sign-in again from Unity."; var codeBlock = string.IsNullOrWhiteSpace(userCode) ? "

No user_code was supplied. Unity sends one when it opens this page.

" : "

Your code

" + "

" + System.Net.WebUtility.HtmlEncode(userCode) + "

"; var expiry = found && expiresUtc > DateTime.UtcNow ? "

Code expires " + expiresUtc.ToString("u") + " UTC.

" : ""; return "" + "Radicade - Rec Room Studio sign-in" + "" + "
" + "
" + glyph + "
" + "

" + title + "

" + codeBlock + "

" + body + "

" + expiry + "

" + DBConfig.ServerUrl + " - local Radicade server

" + "
"; } } }