Merge branch 'LoginRefactor' into new-songs-ui
This commit is contained in:
commit
66d9b34562
@ -2,6 +2,7 @@
|
|||||||
"AuthSettings": {
|
"AuthSettings": {
|
||||||
"JwtKey": "SuperSecretKeyAndHeresItsPadding",
|
"JwtKey": "SuperSecretKeyAndHeresItsPadding",
|
||||||
"JwtIssuer": "http://localhost:5000",
|
"JwtIssuer": "http://localhost:5000",
|
||||||
"JwtAudience": "http://localhost:5000"
|
"JwtAudience": "http://localhost:5000",
|
||||||
|
"AuthenticationRequired": false
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -182,7 +182,7 @@ public class AuthController(IAuthService authService, IUserDatumService userDatu
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> ChangePassword(ChangePasswordRequest changePasswordRequest)
|
public async Task<IActionResult> ChangePassword(ChangePasswordRequest changePasswordRequest)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
@ -232,7 +232,7 @@ public class AuthController(IAuthService authService, IUserDatumService userDatu
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> ResetPassword(ResetPasswordRequest resetPasswordRequest)
|
public async Task<IActionResult> ResetPassword(ResetPasswordRequest resetPasswordRequest)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
@ -260,7 +260,7 @@ public class AuthController(IAuthService authService, IUserDatumService userDatu
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public IActionResult GenerateOtp(GenerateOtpRequest generateOtpRequest)
|
public IActionResult GenerateOtp(GenerateOtpRequest generateOtpRequest)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
|
@ -16,7 +16,7 @@ public class CardsController(IAuthService authService, IOptions<AuthSettings> se
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> DeleteAccessCode(string accessCode)
|
public async Task<IActionResult> DeleteAccessCode(string accessCode)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
@ -45,7 +45,7 @@ public class CardsController(IAuthService authService, IOptions<AuthSettings> se
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> BindAccessCode(BindAccessCodeRequest bindAccessCodeRequest)
|
public async Task<IActionResult> BindAccessCode(BindAccessCodeRequest bindAccessCodeRequest)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
|
@ -18,7 +18,7 @@ public class DanBestDataController(IDanScoreDatumService danScoreDatumService, I
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> GetDanBestData(uint baid)
|
public async Task<IActionResult> GetDanBestData(uint baid)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
|
@ -16,7 +16,7 @@ public class FavoriteSongsController(IUserDatumService userDatumService, IAuthSe
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> UpdateFavoriteSong(SetFavoriteRequest request)
|
public async Task<IActionResult> UpdateFavoriteSong(SetFavoriteRequest request)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
@ -45,7 +45,7 @@ public class FavoriteSongsController(IUserDatumService userDatumService, IAuthSe
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> GetFavoriteSongs(uint baid)
|
public async Task<IActionResult> GetFavoriteSongs(uint baid)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
|
@ -15,7 +15,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public IActionResult GetMusicDetails()
|
public IActionResult GetMusicDetails()
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
@ -31,7 +31,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public IActionResult GetCostumes()
|
public IActionResult GetCostumes()
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
@ -47,7 +47,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public IActionResult GetTitles()
|
public IActionResult GetTitles()
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
@ -63,7 +63,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public IActionResult GetLockedCostumes()
|
public IActionResult GetLockedCostumes()
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
@ -79,7 +79,7 @@ public class GameDataController(IGameDataService gameDataService, IAuthService a
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public IActionResult GetLockedTitles()
|
public IActionResult GetLockedTitles()
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
|
@ -19,7 +19,7 @@ public class PlayDataController(IUserDatumService userDatumService, ISongBestDat
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<ActionResult<SongBestResponse>> GetSongBestRecords(uint baid)
|
public async Task<ActionResult<SongBestResponse>> GetSongBestRecords(uint baid)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
|
@ -17,7 +17,7 @@ public class PlayHistoryController(IUserDatumService userDatumService, ISongPlay
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<ActionResult<SongHistoryResponse>> GetSongHistory(uint baid)
|
public async Task<ActionResult<SongHistoryResponse>> GetSongHistory(uint baid)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
|
@ -17,7 +17,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<ActionResult<List<UserSetting>>> GetAllUserSetting()
|
public async Task<ActionResult<List<UserSetting>>> GetAllUserSetting()
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
@ -96,7 +96,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<ActionResult<UserSetting>> GetUserSetting(uint baid)
|
public async Task<ActionResult<UserSetting>> GetUserSetting(uint baid)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
@ -172,7 +172,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSetting)
|
public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSetting)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo is null)
|
if (tokenInfo is null)
|
||||||
|
@ -16,7 +16,7 @@ public class UsersController(IUserDatumService userDatumService, IAuthService au
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<User?> GetUser(uint baid)
|
public async Task<User?> GetUser(uint baid)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
@ -38,7 +38,7 @@ public class UsersController(IUserDatumService userDatumService, IAuthService au
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IEnumerable<User>> GetUsers()
|
public async Task<IEnumerable<User>> GetUsers()
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
@ -59,7 +59,7 @@ public class UsersController(IUserDatumService userDatumService, IAuthService au
|
|||||||
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
|
||||||
public async Task<IActionResult> DeleteUser(uint baid)
|
public async Task<IActionResult> DeleteUser(uint baid)
|
||||||
{
|
{
|
||||||
if (authSettings.LoginRequired)
|
if (authSettings.AuthenticationRequired)
|
||||||
{
|
{
|
||||||
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
|
||||||
if (tokenInfo == null)
|
if (tokenInfo == null)
|
||||||
|
@ -8,7 +8,7 @@ namespace TaikoLocalServer.Filters
|
|||||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||||
public class AuthorizeIfRequiredAttribute(IOptions<AuthSettings> settings) : Attribute, IAsyncAuthorizationFilter
|
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)
|
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
|
||||||
{
|
{
|
||||||
|
@ -87,9 +87,6 @@ try
|
|||||||
builder.Services.Configure<DataSettings>(builder.Configuration.GetSection(nameof(DataSettings)));
|
builder.Services.Configure<DataSettings>(builder.Configuration.GetSection(nameof(DataSettings)));
|
||||||
builder.Services.Configure<AuthSettings>(builder.Configuration.GetSection(nameof(AuthSettings)));
|
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
|
// Add Authentication with JWT
|
||||||
builder.Services.AddAuthentication(options =>
|
builder.Services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
|
@ -8,5 +8,5 @@ public class AuthSettings
|
|||||||
|
|
||||||
public string JwtAudience { get; set; } = string.Empty;
|
public string JwtAudience { get; set; } = string.Empty;
|
||||||
|
|
||||||
public bool LoginRequired { get; set; }
|
public bool AuthenticationRequired { get; set; }
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user