1
0
mirror of synced 2024-11-24 06:50:15 +01:00

Merge branch 'LoginRefactor' into new-songs-ui

This commit is contained in:
shiibe 2024-06-02 15:52:45 -04:00
commit 66d9b34562
13 changed files with 25 additions and 27 deletions

View File

@ -2,6 +2,7 @@
"AuthSettings": {
"JwtKey": "SuperSecretKeyAndHeresItsPadding",
"JwtIssuer": "http://localhost:5000",
"JwtAudience": "http://localhost:5000"
"JwtAudience": "http://localhost:5000",
"AuthenticationRequired": false
}
}

View File

@ -182,7 +182,7 @@ public class AuthController(IAuthService authService, IUserDatumService userDatu
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> ChangePassword(ChangePasswordRequest changePasswordRequest)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)
@ -232,7 +232,7 @@ public class AuthController(IAuthService authService, IUserDatumService userDatu
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> ResetPassword(ResetPasswordRequest resetPasswordRequest)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)
@ -260,7 +260,7 @@ public class AuthController(IAuthService authService, IUserDatumService userDatu
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public IActionResult GenerateOtp(GenerateOtpRequest generateOtpRequest)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)

View File

@ -16,7 +16,7 @@ public class CardsController(IAuthService authService, IOptions<AuthSettings> se
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> DeleteAccessCode(string accessCode)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)
@ -45,7 +45,7 @@ public class CardsController(IAuthService authService, IOptions<AuthSettings> se
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> BindAccessCode(BindAccessCodeRequest bindAccessCodeRequest)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)

View File

@ -18,7 +18,7 @@ public class DanBestDataController(IDanScoreDatumService danScoreDatumService, I
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> GetDanBestData(uint baid)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)

View File

@ -16,7 +16,7 @@ public class FavoriteSongsController(IUserDatumService userDatumService, IAuthSe
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> UpdateFavoriteSong(SetFavoriteRequest request)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
@ -45,7 +45,7 @@ public class FavoriteSongsController(IUserDatumService userDatumService, IAuthSe
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> GetFavoriteSongs(uint baid)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)

View File

@ -15,7 +15,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public IActionResult GetMusicDetails()
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
@ -31,7 +31,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public IActionResult GetCostumes()
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
@ -47,7 +47,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public IActionResult GetTitles()
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
@ -63,7 +63,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public IActionResult GetLockedCostumes()
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
@ -79,7 +79,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public IActionResult GetLockedTitles()
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)

View File

@ -19,7 +19,7 @@ public class PlayDataController(IUserDatumService userDatumService, ISongBestDat
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<ActionResult<SongBestResponse>> GetSongBestRecords(uint baid)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)

View File

@ -17,7 +17,7 @@ public class PlayHistoryController(IUserDatumService userDatumService, ISongPlay
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<ActionResult<SongHistoryResponse>> GetSongHistory(uint baid)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)

View File

@ -17,7 +17,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<ActionResult<List<UserSetting>>> GetAllUserSetting()
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
@ -96,7 +96,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<ActionResult<UserSetting>> GetUserSetting(uint baid)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
@ -172,7 +172,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSetting)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)

View File

@ -16,7 +16,7 @@ public class UsersController(IUserDatumService userDatumService, IAuthService au
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<User?> GetUser(uint baid)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)
@ -38,7 +38,7 @@ public class UsersController(IUserDatumService userDatumService, IAuthService au
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IEnumerable<User>> GetUsers()
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)
@ -59,7 +59,7 @@ public class UsersController(IUserDatumService userDatumService, IAuthService au
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> DeleteUser(uint baid)
{
if (authSettings.LoginRequired)
if (authSettings.AuthenticationRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo == null)

View File

@ -8,7 +8,7 @@ namespace TaikoLocalServer.Filters
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class AuthorizeIfRequiredAttribute(IOptions<AuthSettings> settings) : Attribute, IAsyncAuthorizationFilter
{
private readonly bool loginRequired = settings.Value.LoginRequired;
private readonly bool loginRequired = settings.Value.AuthenticationRequired;
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{

View File

@ -87,9 +87,6 @@ try
builder.Services.Configure<DataSettings>(builder.Configuration.GetSection(nameof(DataSettings)));
builder.Services.Configure<AuthSettings>(builder.Configuration.GetSection(nameof(AuthSettings)));
var loginRequired = builder.Configuration.GetSection("WebUiSettings").GetValue<bool>("LoginRequired");
builder.Services.Configure<AuthSettings>(options => { options.LoginRequired = loginRequired; });
// Add Authentication with JWT
builder.Services.AddAuthentication(options =>
{

View File

@ -8,5 +8,5 @@ public class AuthSettings
public string JwtAudience { get; set; } = string.Empty;
public bool LoginRequired { get; set; }
public bool AuthenticationRequired { get; set; }
}