Skip to content

Commit

Permalink
Add to see if request is internal
Browse files Browse the repository at this point in the history
  • Loading branch information
dtagt committed Feb 14, 2024
1 parent fc0fdb2 commit 212001c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Valghalla.Application/Saml/ISaml2AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface ISaml2AuthService
void SaveClientSession();
Task<string> GetLoginRedirectUrlAsync(CancellationToken cancellationToken);
Task<string> LogoutAsync(bool profileDeleted, CancellationToken cancellationToken);
Task<string> SetupAssertionConsumerServiceAsync(Func<ClaimsPrincipal, ClaimsPrincipal> transform, CancellationToken cancellationToken);
Task<string> SetupAssertionConsumerServiceAsync(Func<ClaimsPrincipal, ClaimsPrincipal> transform, bool isInternal, CancellationToken cancellationToken);
Task<string> SetupLogoutResponseAsync(string logoutPath, CancellationToken cancellationToken);
}
}
2 changes: 1 addition & 1 deletion Valghalla.External.API/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<IActionResult> LoginAsync(CancellationToken cancellationToken)
[HttpPost("AssertionConsumerService")]
public async Task<IActionResult> SetupAssertionConsumerServiceAsync(CancellationToken cancellationToken)
{
var redirectUrl = await saml2AuthService.SetupAssertionConsumerServiceAsync(TransformClaims, cancellationToken);
var redirectUrl = await saml2AuthService.SetupAssertionConsumerServiceAsync(TransformClaims, false, cancellationToken);
saml2AuthService.SaveClientSession();

return Redirect(redirectUrl);
Expand Down
10 changes: 6 additions & 4 deletions Valghalla.Integration/Saml/Saml2AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task<string> LogoutAsync(bool profileDeleted, CancellationToken can
return binding.RedirectLocation.OriginalString;
}

public async Task<string> SetupAssertionConsumerServiceAsync(Func<ClaimsPrincipal, ClaimsPrincipal> transform, CancellationToken cancellationToken)
public async Task<string> SetupAssertionConsumerServiceAsync(Func<ClaimsPrincipal, ClaimsPrincipal> transform, bool isInternal, CancellationToken cancellationToken)
{
var saml2Config = await GetSaml2ConfigurationAsync(cancellationToken);
var binding = new Saml2PostBinding();
Expand All @@ -138,7 +138,7 @@ public async Task<string> SetupAssertionConsumerServiceAsync(Func<ClaimsPrincipa

binding.Unbind(HttpContext.Request.ToGenericHttpRequest(), saml2AuthnResponse);

await CreateSession(saml2AuthnResponse, transform);
await CreateSession(saml2AuthnResponse, transform, isInternal);

var relayStateQuery = binding.GetRelayStateQuery();

Expand Down Expand Up @@ -208,7 +208,7 @@ public async Task<string> SetupLogoutResponseAsync(string logoutPath, Cancellati
}
}

private async Task CreateSession(Saml2AuthnResponse saml2AuthnResponse, Func<ClaimsPrincipal, ClaimsPrincipal> transform)
private async Task CreateSession(Saml2AuthnResponse saml2AuthnResponse, Func<ClaimsPrincipal, ClaimsPrincipal> transform, bool isInternal)
{
if (HttpContext.Request.Cookies.Any())
{
Expand All @@ -218,7 +218,9 @@ private async Task CreateSession(Saml2AuthnResponse saml2AuthnResponse, Func<Cla

await saml2AuthnResponse.CreateSession(HttpContext, claimsTransform: (claimsPrincipal) =>
{
CheckJobRoleDefinition(claimsPrincipal);
if(isInternal)
CheckJobRoleDefinition(claimsPrincipal);

CheckAssurance(claimsPrincipal);
return transform(claimsPrincipal);
});
Expand Down
2 changes: 1 addition & 1 deletion Valghalla.Internal.API/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<IActionResult> LoginAsync(CancellationToken cancellationToken)
[HttpPost("AssertionConsumerService")]
public async Task<IActionResult> SetupAssertionConsumerServiceAsync(CancellationToken cancellationToken)
{
var redirectUrl = await saml2AuthService.SetupAssertionConsumerServiceAsync(TransformClaims, cancellationToken);
var redirectUrl = await saml2AuthService.SetupAssertionConsumerServiceAsync(TransformClaims, true, cancellationToken);
return Redirect(redirectUrl);
}

Expand Down

0 comments on commit 212001c

Please sign in to comment.