Skip to content

Commit

Permalink
Merge pull request #409 from gaepdit/388-filter-account-authenticatio…
Browse files Browse the repository at this point in the history
…n-by-domain

388 filter account authentication by domain
  • Loading branch information
tom-karasch authored May 31, 2024
2 parents 60acc32 + a24a37b commit 57dea71
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions FMS.Domain/Entities/Users/ApplicationUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ApplicationUser : IdentityUser<Guid>
/// In ASP.NET Core, the OpenID Connect middleware converts some of the claim types when it populates the
/// Claims collection for the user principal:
/// oid -> http://schemas.microsoft.com/identity/claims/objectidentifier
///
/// <para>ID token claims reference: https://learn.microsoft.com/en-us/entra/identity-platform/id-token-claims-reference#use-claims-to-reliably-identify-a-user</para>
/// </summary>
[PersonalData]
public string ObjectId { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions FMS/Pages/Account/ExternalLogin.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public async Task<IActionResult> OnGetCallbackAsync(string returnUrl = null, str
return RedirectToLoginPageWithError("Error loading detailed work account information.");
}

if (!preferredUserName.IsValidEmailDomain())
{
_logger.LogWarning("User {UserName} with invalid email domain attempted signin", preferredUserName);
return RedirectToPage("./Unavailable");
}

// Determine if a user account already exists.
var user = await _userManager.FindByNameAsync(preferredUserName);

Expand Down
8 changes: 8 additions & 0 deletions FMS/Pages/Users/UserDomainValidation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace FMS.Domain.Entities.Users
{
public static class UserDomainValidation
{
public static bool IsValidEmailDomain(this string email) =>
email.EndsWith("@dnr.ga.gov", System.StringComparison.CurrentCultureIgnoreCase);
}
}

0 comments on commit 57dea71

Please sign in to comment.