From 946834661740de6e18feb4b84bf86446788a7ea9 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 18 Apr 2022 23:16:46 +0200 Subject: [PATCH] Fix startup issue with jwt --- src/Kyoo.Authentication/AuthenticationModule.cs | 7 ++----- src/Kyoo.Authentication/Views/AuthApi.cs | 13 +++++++++++-- src/Kyoo.Core/CoreModule.cs | 1 + src/Kyoo.Host.Generic/PluginsStartup.cs | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Kyoo.Authentication/AuthenticationModule.cs b/src/Kyoo.Authentication/AuthenticationModule.cs index 0b87af6d..64930085 100644 --- a/src/Kyoo.Authentication/AuthenticationModule.cs +++ b/src/Kyoo.Authentication/AuthenticationModule.cs @@ -120,11 +120,8 @@ namespace Kyoo.Authentication FileProvider = provider }); }, SA.StaticFiles), - SA.New(app => - { - app.UseAuthentication(); - }, SA.Authentication), - SA.New(app => app.UseAuthorization(), SA.Authorization) + SA.New(app => app.UseAuthentication(), SA.Authentication), + // SA.New(app => app.UseAuthorization(), SA.Authorization) }; } } diff --git a/src/Kyoo.Authentication/Views/AuthApi.cs b/src/Kyoo.Authentication/Views/AuthApi.cs index 8c2bb376..787349de 100644 --- a/src/Kyoo.Authentication/Views/AuthApi.cs +++ b/src/Kyoo.Authentication/Views/AuthApi.cs @@ -161,14 +161,23 @@ namespace Kyoo.Authentication.Views } } + /// + /// Get authenticated user. + /// + /// + /// Get information about the currently authenticated user. This can also be used to ensure that you are + /// logged in. + /// + /// The currently authenticated user. + /// The given access token is invalid. [HttpGet("me")] [Authorize] [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetMe() { if (!int.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out int userID)) - return BadRequest("Invalid access token"); - return await _users.GetById(userID); + return Forbid(); + return await _users.Get(userID); } } } diff --git a/src/Kyoo.Core/CoreModule.cs b/src/Kyoo.Core/CoreModule.cs index c52dee27..a3ec6761 100644 --- a/src/Kyoo.Core/CoreModule.cs +++ b/src/Kyoo.Core/CoreModule.cs @@ -118,6 +118,7 @@ namespace Kyoo.Core /// public void Configure(IServiceCollection services) { + services.AddHttpContextAccessor(); services.AddTransient, JsonOptions>(); services.AddMvcCore() diff --git a/src/Kyoo.Host.Generic/PluginsStartup.cs b/src/Kyoo.Host.Generic/PluginsStartup.cs index 67e9f621..a753284f 100644 --- a/src/Kyoo.Host.Generic/PluginsStartup.cs +++ b/src/Kyoo.Host.Generic/PluginsStartup.cs @@ -161,7 +161,8 @@ namespace Kyoo.Host.Generic .OrderByDescending(x => x.Priority); using ILifetimeScope scope = container.BeginLifetimeScope(x => - x.RegisterInstance(app).SingleInstance().ExternallyOwned()); + x.RegisterInstance(app).SingleInstance().ExternallyOwned() + ); IServiceProvider provider = scope.Resolve(); foreach (IStartupAction step in steps) step.Run(provider);