Skip to content

Commit

Permalink
Allow AC to send magic links (#507)
Browse files Browse the repository at this point in the history
* Added check for admin console.

Co-authored-by: Oleksii Holub <[email protected]>
  • Loading branch information
jrmccannon and Tyrrrz authored Mar 20, 2024
1 parent c4058bb commit 076420b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Service/MagicLinks/MagicLinkService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.Extensions.Caching.Memory;
using Passwordless.Common.MagicLinks.Models;
using Passwordless.Common.Services.Mail;
using Passwordless.Service.EventLog.Loggers;
Expand All @@ -10,7 +9,6 @@ namespace Passwordless.Service.MagicLinks;

public class MagicLinkService(
TimeProvider timeProvider,
IMemoryCache cache,
ITenantStorage tenantStorage,
IFido2Service fido2Service,
IMailProvider mailProvider,
Expand All @@ -24,6 +22,7 @@ private async Task EnforceQuotaAsync(MagicLinkTokenRequest request)

// Applications created less than 24 hours ago can only send magic links to the admin email address
if (accountAge < TimeSpan.FromHours(24) &&
!IsAdminConsole(account) &&
!account.AdminEmails.Contains(request.EmailAddress.Address, StringComparer.OrdinalIgnoreCase))
{
throw new ApiException(
Expand Down Expand Up @@ -64,6 +63,10 @@ private async Task EnforceQuotaAsync(MagicLinkTokenRequest request)
}
}

private static bool IsAdminConsole(PerTenant account) =>
string.Equals(account.Tenant, "admin", StringComparison.OrdinalIgnoreCase)
|| string.Equals(account.Tenant, "adminconsole", StringComparison.OrdinalIgnoreCase);

public async Task SendMagicLinkAsync(MagicLinkTokenRequest request)
{
await EnforceQuotaAsync(request);
Expand Down

0 comments on commit 076420b

Please sign in to comment.