|
|
@ -12,13 +12,14 @@ namespace AuthStudy.WebApp.Controllers
|
|
|
|
[ApiController]
|
|
|
|
[ApiController]
|
|
|
|
public class AccountsController : ControllerBase
|
|
|
|
public class AccountsController : ControllerBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public AccountsController()
|
|
|
|
private ILogger<AccountsController> _logger;
|
|
|
|
|
|
|
|
public AccountsController(ILogger<AccountsController> logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//多特性是and特性内逗号分隔是or
|
|
|
|
//多特性是and特性内逗号分隔是or
|
|
|
|
//[Authorize]
|
|
|
|
[Authorize]
|
|
|
|
//[Authorize(AuthenticationSchemes = AuthenticationSchemeList.BaseBrowserScheme)]
|
|
|
|
//[Authorize(AuthenticationSchemes = AuthenticationSchemeList.BaseBrowserScheme)]
|
|
|
|
//[Authorize(AuthenticationSchemes = AuthenticationSchemeList.BrowserScheme)]
|
|
|
|
//[Authorize(AuthenticationSchemes = AuthenticationSchemeList.BrowserScheme)]
|
|
|
|
//[Authorize(AuthenticationSchemes = AuthenticationSchemeList.BasicScheme)]
|
|
|
|
//[Authorize(AuthenticationSchemes = AuthenticationSchemeList.BasicScheme)]
|
|
|
@ -27,12 +28,22 @@ namespace AuthStudy.WebApp.Controllers
|
|
|
|
[HttpGet]
|
|
|
|
[HttpGet]
|
|
|
|
public async Task<IActionResult> GetAll()
|
|
|
|
public async Task<IActionResult> GetAll()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var dd = await HttpContext.AuthenticateAsync();
|
|
|
|
var authenticateResult = await HttpContext.AuthenticateAsync();
|
|
|
|
|
|
|
|
if (authenticateResult.Succeeded)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation("认证成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Response.StatusCode = 401;
|
|
|
|
|
|
|
|
_logger.LogInformation("认证失败");
|
|
|
|
|
|
|
|
return new ContentResult() { StatusCode = 401,Content=authenticateResult.Failure?.Message};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//输出认证信息
|
|
|
|
//输出认证信息
|
|
|
|
foreach (var claim in User.Claims)
|
|
|
|
foreach (var claim in User.Claims)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine($"{claim.Type}={claim.Value}");
|
|
|
|
_logger.LogInformation($"{claim.Type}={claim.Value}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<AccountVM> accounts = new()
|
|
|
|
List<AccountVM> accounts = new()
|
|
|
|