Fix startup issue with jwt

This commit is contained in:
Zoe Roux 2022-04-18 23:16:46 +02:00
parent 673cb48b75
commit 9468346617
No known key found for this signature in database
GPG Key ID: 54F19BB73170955D
4 changed files with 16 additions and 8 deletions

View File

@ -120,11 +120,8 @@ namespace Kyoo.Authentication
FileProvider = provider
});
}, SA.StaticFiles),
SA.New<IApplicationBuilder>(app =>
{
app.UseAuthentication();
}, SA.Authentication),
SA.New<IApplicationBuilder>(app => app.UseAuthorization(), SA.Authorization)
SA.New<IApplicationBuilder>(app => app.UseAuthentication(), SA.Authentication),
// SA.New<IApplicationBuilder>(app => app.UseAuthorization(), SA.Authorization)
};
}
}

View File

@ -161,14 +161,23 @@ namespace Kyoo.Authentication.Views
}
}
/// <summary>
/// Get authenticated user.
/// </summary>
/// <remarks>
/// Get information about the currently authenticated user. This can also be used to ensure that you are
/// logged in.
/// </remarks>
/// <returns>The currently authenticated user.</returns>
/// <response code="403">The given access token is invalid.</response>
[HttpGet("me")]
[Authorize]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<User>> 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);
}
}
}

View File

@ -118,6 +118,7 @@ namespace Kyoo.Core
/// <inheritdoc />
public void Configure(IServiceCollection services)
{
services.AddHttpContextAccessor();
services.AddTransient<IConfigureOptions<MvcNewtonsoftJsonOptions>, JsonOptions>();
services.AddMvcCore()

View File

@ -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<IServiceProvider>();
foreach (IStartupAction step in steps)
step.Run(provider);