SecurityToken.ValidTo Property

Definition

Obtient le dernier instant auquel ce jeton de sécurité est valide.Gets the last instant in time at which this security token is valid.

public:
 abstract property DateTime ValidTo { DateTime get(); };
public abstract DateTime ValidTo { get; }
member this.ValidTo : DateTime
Public MustOverride ReadOnly Property ValidTo As DateTime

Property Value

DateTime

DateTime qui représente le dernier instant auquel ce jeton de sécurité est valide.A DateTime that represents the last instant in time at which this security token is valid.

Examples

Les exemples de code utilisés dans les rubriques SecurityToken sont tirés de l’exemple Custom Token.The code examples that are used in the SecurityToken topics are taken from the Custom Token sample. Cet exemple fournit des classes personnalisées qui permettent le traitement de jetons Web simples (SWT).This sample provides custom classes that enable processing of Simple Web Tokens (SWT). Il comprend une implémentation d’une classe SimpleWebToken et d’une classe SimpleWebTokenHandler, ainsi que d’autres classes qui prennent en charge les jetons SWT.It includes an implementation of a SimpleWebToken class and a SimpleWebTokenHandler class, as well as other classes that support SWT tokens. Pour plus d’informations sur cet exemple et d’autres exemples disponibles pour WIF et sur l’emplacement de téléchargement, consultez exemple d’index de code WIF.For information about this sample and other samples available for WIF and about where to download them, see WIF Code Sample Index. Le code suivant illustre la substitution de la propriété ValidTo.The following code shows the override of the ValidTo property.

/// <summary>
/// Defines the set of constants for the Simple Web Token.
/// </summary>
public static class SimpleWebTokenConstants
{
    public const string Audience = "Audience";
    public const string ExpiresOn = "ExpiresOn";
    public const string Id = "Id";
    public const string Issuer = "Issuer";
    public const string Signature = "HMACSHA256";
    public const string ValidFrom = "ValidFrom";
    public const string ValueTypeUri = "http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0";     
}
public static DateTime SwtBaseTime = new DateTime( 1970, 1, 1, 0, 0, 0, 0 ); // per SWT psec

NameValueCollection _properties;
/// <summary>
/// Gets the time when the token expires.
/// </summary>
/// <value>The time up to which the token is valid.</value>
public override DateTime ValidTo
{
    get
    {
        string expiryTime = _properties[SimpleWebTokenConstants.ExpiresOn];
        return GetTimeAsDateTime( String.IsNullOrEmpty( expiryTime ) ? "0" : expiryTime );
    }
}
/// <summary>
/// Converts the time in seconds to a <see cref="DateTime"/> object based on the base time 
/// defined by the Simple Web Token.
/// </summary>
/// <param name="expiryTime">The time in seconds.</param>
/// <returns>The time as a <see cref="DateTime"/> object.</returns>
protected virtual DateTime GetTimeAsDateTime( string expiryTime )
{
    long totalSeconds = 0;
    if ( !long.TryParse( expiryTime, out totalSeconds ) )
    {
        throw new SecurityTokenException("Invalid expiry time. Expected the time to be in seconds passed from 1 January 1970.");
    }

    long maxSeconds = (long)( DateTime.MaxValue - SwtBaseTime ).TotalSeconds - 1;
    if ( totalSeconds > maxSeconds )
    {
        totalSeconds = maxSeconds;
    }

    return SwtBaseTime.AddSeconds( totalSeconds );
} 

Remarks

Les propriétés ValidFrom et ValidTo permettent de déterminer la période pendant laquelle un jeton SecurityToken est valide.Use the ValidFrom and ValidTo properties to determine the time period in which a SecurityToken token is valid. Les propriétés ValidFrom et ValidTo représentent respectivement le premier et le dernier instant auxquels le jeton de sécurité est valide.The ValidFrom and ValidTo properties represent the first and last instants in time in which the security token is valid, respectively.

Notes to Implementers

Vous devez substituer la propriété ValidTo.You must override the ValidTo property.

Applies to