If you refer to the this topic (WCF Security: Getting the password of the user) by Rory Primrose, he achieves similar to what you're enquiring about with providing a custom validator, the important extension method being CreateSecurityTokenManager
:
public class PasswordServiceCredentials : ServiceCredentials
{
public PasswordServiceCredentials()
{
}
private PasswordServiceCredentials(PasswordServiceCredentials clone)
: base(clone)
{
}
protected override ServiceCredentials CloneCore()
{
return new PasswordServiceCredentials(this);
}
public override SecurityTokenManager CreateSecurityTokenManager()
{
// Check if the current validation mode is for custom username password validation
if (UserNameAuthentication.UserNamePasswordValidationMode == UserNamePasswordValidationMode.Custom)
{
return new PasswordSecurityTokenManager(this);
}
Trace.TraceWarning(Resources.CustomUserNamePasswordValidationNotEnabled);
return base.CreateSecurityTokenManager();
}
}
To use this custom service credential, you will need to specify the type attribute on the <ServiceCredentials>
's ConfigurationElement
in your configuration, like:
<serviceCredentials type="your.assembly.namespace.PasswordServiceCredentials,
your.assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" >
</serviceCredentials>
Likewise, you could set this type
attribute programatically, but I'm not familiar with how.