I have a wcf service that queries ADFS for SAML token. This is a common snippet from web to query ADFS and get back the SAML token. However it always ends up breaking at the line return channel.Issue(rst); . Error is ID3082: The request scope is not valid or is unsupported. At least at an high level i am not able to figure out whether the error is at the ADFS server end or with the way WCF service is configured or with code. Please help.
public SecurityToken GetSamlToken()
{
using (var factory = new WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
new EndpointAddress(new Uri("https://serv/adfs/services/trust/13/usernamemixed"))))
{
factory.Credentials.UserName.UserName = "username";
factory.Credentials.UserName.Password = "password";
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
factory.TrustVersion = TrustVersion.WSTrust13;
WSTrustChannel channel = null;
try
{
string KeyType;
var rst = new RequestSecurityToken
{
RequestType = WSTrust13Constants.RequestTypes.Issue,
AppliesTo = new EndpointAddress("net.tcp://localhost:xxxx/Service1/mex"),
KeyType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.KeyTypes.Bearer,
};
channel = (WSTrustChannel)factory.CreateChannel();
return channel.Issue(rst);
}
finally
{
if (channel != null)
{
channel.Abort();
}
factory.Abort();
}
}
}
The issue was with the
AppliesTo = new EndpointAddress("net.tcp://localhost:xxxx/Service1/mex")
I replaced it with a relying party uri and it issues me the token. The only issue here being the confusing error messages.