mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-09-30 18:29:36 +02:00
identity: make 2fa truly mandatory
This commit is contained in:
1 parent
26703bfd8e
commit
0ad00c9747
4 files changed
+15
-17
No files matched your search
@@ -29,6 +29,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Streetwriters.Common;
|
||||
using Streetwriters.Common.Enums;
|
||||
using Streetwriters.Common.Messages;
|
||||
using Streetwriters.Common.Models;
|
||||
using Streetwriters.Identity.Enums;
|
||||
@@ -172,6 +173,12 @@ namespace Streetwriters.Identity.Controllers
|
||||
var claims = await UserManager.GetClaimsAsync(user);
|
||||
var marketingConsentClaim = claims.FirstOrDefault((claim) => claim.Type == $"{client.Id}:marketing_consent");
|
||||
|
||||
if (!await UserManager.GetTwoFactorEnabledAsync(user))
|
||||
{
|
||||
await MFAService.EnableMFAAsync(user, MFAMethods.Email);
|
||||
user = await UserManager.GetUserAsync(User);
|
||||
}
|
||||
|
||||
return Ok(new UserModel
|
||||
{
|
||||
UserId = user.Id.ToString(),
|
||||
|
||||
@@ -74,21 +74,9 @@ namespace Streetwriters.Identity.Controllers
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public async Task<IActionResult> Disable2FA()
|
||||
public IActionResult Disable2FA()
|
||||
{
|
||||
var user = await UserManager.GetUserAsync(User);
|
||||
|
||||
if (!await UserManager.GetTwoFactorEnabledAsync(user))
|
||||
{
|
||||
return BadRequest("Cannot disable 2FA as it's not currently enabled");
|
||||
}
|
||||
|
||||
if (await MFAService.DisableMFAAsync(user))
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return BadRequest("Failed to disable 2FA.");
|
||||
return BadRequest("2FA is mandatory and cannot be disabled.");
|
||||
}
|
||||
|
||||
[HttpGet("codes")]
|
||||
|
||||
@@ -27,6 +27,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Streetwriters.Common;
|
||||
using Streetwriters.Common.Enums;
|
||||
using Streetwriters.Common.Models;
|
||||
using Streetwriters.Identity.Enums;
|
||||
using Streetwriters.Identity.Interfaces;
|
||||
@@ -109,6 +110,8 @@ namespace Streetwriters.Identity.Controllers
|
||||
var callbackUrl = Url.TokenLink(user.Id.ToString(), code, client.Id, TokenType.CONFRIM_EMAIL, Request.Scheme);
|
||||
await EmailSender.SendConfirmationEmailAsync(user.Email, callbackUrl, client);
|
||||
|
||||
await MFAService.EnableMFAAsync(user, MFAMethods.Email);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
userId = user.Id.ToString()
|
||||
|
||||
Reference in new issue
Block a user