diff --git a/Moonlight.ApiServer/Moonlight.ApiServer.csproj b/Moonlight.ApiServer/Moonlight.ApiServer.csproj index 24cde91b..be019081 100644 --- a/Moonlight.ApiServer/Moonlight.ApiServer.csproj +++ b/Moonlight.ApiServer/Moonlight.ApiServer.csproj @@ -14,7 +14,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Moonlight.ApiServer/Program.cs b/Moonlight.ApiServer/Program.cs index 1718b76a..9997bbfb 100644 --- a/Moonlight.ApiServer/Program.cs +++ b/Moonlight.ApiServer/Program.cs @@ -1,5 +1,6 @@ using System.Net; using System.Reflection; +using MoonCore.Extended.Extensions; using MoonCore.Extended.Helpers; using MoonCore.Extensions; using MoonCore.Helpers; @@ -142,7 +143,7 @@ if (config.Client.Enable) app.UseRouting(); -app.UseMiddleware(); +app.UseApiErrorHandling(); await Startup.UseTokenAuthentication(app); await Startup.UseOAuth2(app); diff --git a/Moonlight.ApiServer/Startup.cs b/Moonlight.ApiServer/Startup.cs index 4cc307fd..20ff10c6 100644 --- a/Moonlight.ApiServer/Startup.cs +++ b/Moonlight.ApiServer/Startup.cs @@ -196,7 +196,7 @@ public static class Startup var logger = loggerFactory.CreateLogger("OAuth2 Refresh"); // We are handling this error more softly, because it will occur when a user hasn't logged in a long period of time - logger.LogDebug("An error occured while refreshing external oauth2 access: {e}", e); + logger.LogTrace("An error occured while refreshing external oauth2 access: {e}", e); return false; } } @@ -306,6 +306,14 @@ public static class Startup if (user == null) throw new HttpApiException("OAuth2 provider returned empty user", 500); + // Save new token + user.AccessToken = accessData.AccessToken; + user.RefreshToken = accessData.RefreshToken; + user.RefreshTimestamp = DateTime.UtcNow.AddSeconds(accessData.ExpiresIn); + + var userRepo = serviceProvider.GetRequiredService>(); + userRepo.Update(user); + return new Dictionary() { {"userId", user.Id} diff --git a/Moonlight.Client/Moonlight.Client.csproj b/Moonlight.Client/Moonlight.Client.csproj index 3e4f3a5d..10fffcf2 100644 --- a/Moonlight.Client/Moonlight.Client.csproj +++ b/Moonlight.Client/Moonlight.Client.csproj @@ -15,7 +15,7 @@ - +