This topic has not yet been rated - Rate this topic

ClientCredentialsSecurityTokenManager.CreateSecurityTokenProvider Method

Creates a security token provider.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
public override SecurityTokenProvider CreateSecurityTokenProvider(
	SecurityTokenRequirement tokenRequirement
)
ExceptionCondition
ArgumentNullException

tokenRequirement is null.

The SecurityTokenProvider class is responsible for obtaining tokens for a given ServiceModelSecurityTokenRequirement. Optionally token providers support renewing and canceling tokens as well.

The following code shows how to override this method.

internal class MyClientCredentialsSecurityTokenManager : 
    ClientCredentialsSecurityTokenManager
{
    MyClientCredentials credentials;

    public MyClientCredentialsSecurityTokenManager(
        MyClientCredentials credentials): base(credentials)
    {
        this.credentials = credentials;
    }

    public override SecurityTokenProvider CreateSecurityTokenProvider(
        SecurityTokenRequirement requirement)
    {
        SecurityTokenProvider result = null;
        if (requirement.TokenType == SecurityTokenTypes.X509Certificate)
        {
            MessageDirection direction = requirement.GetProperty
                <MessageDirection>(ServiceModelSecurityTokenRequirement.
                MessageDirectionProperty);
            if (direction == MessageDirection.Output)
            {
                if (requirement.KeyUsage == SecurityKeyUsage.Signature)
                {
                    result = new X509SecurityTokenProvider(
                        this.credentials.ClientSigningCertificate);
                }
                else
                {
                    result = new X509SecurityTokenProvider(this.credentials.
                        ServiceEncryptingCertificate);
                }
            }
            else
            {
                if (requirement.KeyUsage == SecurityKeyUsage.Signature)
                {
                    result = new X509SecurityTokenProvider(this.
                        credentials.ServiceSigningCertificate);
                }
                else
                {
                    result = new X509SecurityTokenProvider(credentials.
                        ClientEncryptingCertificate);
                }
            }
        }
        else
        {
            result = base.CreateSecurityTokenProvider(requirement);
        }

        return result;
    }

    public override SecurityTokenAuthenticator 
        CreateSecurityTokenAuthenticator(SecurityTokenRequirement 
        tokenRequirement, out SecurityTokenResolver outOfBandTokenResolver)
    {
        return base.CreateSecurityTokenAuthenticator(tokenRequirement, 
            out outOfBandTokenResolver);
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.