mirror of
https://github.com/bitwarden/server
synced 2025-12-19 17:53:44 +00:00
feat: add SSO request validation and organization identifier lookup - Implement SsoRequestValidator to validate SSO requirements - Add UserSsoOrganizationIdentifierQuery to fetch organization identifiers - Create SsoOrganizationIdentifier custom response for SSO redirects - Add feature flag (RedirectOnSsoRequired) for gradual rollout - Register validators and queries in dependency injection - Create RequestValidationConstants to reduce magic strings - Add comprehensive test coverage for validation logic - Update BaseRequestValidator to consume SsoRequestValidator
72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using System.Reflection;
|
|
using AutoFixture;
|
|
using AutoFixture.Xunit2;
|
|
using Bit.Identity.IdentityServer;
|
|
using Duende.IdentityServer.Validation;
|
|
|
|
namespace Bit.Identity.Test.AutoFixture;
|
|
|
|
internal class ValidatedTokenRequestCustomization : ICustomization
|
|
{
|
|
public ValidatedTokenRequestCustomization()
|
|
{
|
|
}
|
|
|
|
public void Customize(IFixture fixture)
|
|
{
|
|
fixture.Customize<ValidatedTokenRequest>(composer => composer
|
|
.With(o => o.RefreshToken, () => null)
|
|
.With(o => o.ClientClaims, [])
|
|
.With(o => o.Options, new Duende.IdentityServer.Configuration.IdentityServerOptions()));
|
|
}
|
|
}
|
|
|
|
public class ValidatedTokenRequestAttribute : CustomizeAttribute
|
|
{
|
|
public ValidatedTokenRequestAttribute()
|
|
{
|
|
}
|
|
|
|
public override ICustomization GetCustomization(ParameterInfo parameter)
|
|
{
|
|
return new ValidatedTokenRequestCustomization();
|
|
}
|
|
}
|
|
|
|
internal class CustomValidatorRequestContextCustomization : ICustomization
|
|
{
|
|
public CustomValidatorRequestContextCustomization()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Specific context members like <see cref="CustomValidatorRequestContext.RememberMeRequested" />,
|
|
/// <see cref="CustomValidatorRequestContext.TwoFactorRecoveryRequested"/>, and
|
|
/// <see cref="CustomValidatorRequestContext.SsoRequired" /> should initialize false,
|
|
/// and are made truthy in context upon evaluation of a request. Do not allow AutoFixture to eagerly make these
|
|
/// truthy; that is the responsibility of the <see cref="Bit.Identity.IdentityServer.RequestValidators.BaseRequestValidator{T}" />.
|
|
/// ValidationErrorResult and CustomResponse should also be null initially; they are hydrated during the validation process.
|
|
/// </summary>
|
|
public void Customize(IFixture fixture)
|
|
{
|
|
fixture.Customize<CustomValidatorRequestContext>(composer => composer
|
|
.With(o => o.RememberMeRequested, false)
|
|
.With(o => o.TwoFactorRecoveryRequested, false)
|
|
.With(o => o.SsoRequired, false)
|
|
.With(o => o.ValidationErrorResult, () => null)
|
|
.With(o => o.CustomResponse, () => null));
|
|
}
|
|
}
|
|
|
|
public class CustomValidatorRequestContextAttribute : CustomizeAttribute
|
|
{
|
|
public CustomValidatorRequestContextAttribute()
|
|
{
|
|
}
|
|
|
|
public override ICustomization GetCustomization(ParameterInfo parameter)
|
|
{
|
|
return new CustomValidatorRequestContextCustomization();
|
|
}
|
|
}
|