SecurityToken.ValidFrom 속성

정의

이 보안 토큰이 유효한 기간의 시작 시간을 가져옵니다.

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

속성 값

DateTime

이 보안 토큰이 유효한 기간의 시작 시간을 나타내는 DateTime입니다.

예제

에 사용 되는 코드 예제는 SecurityToken 항목에서 수행 되는 Custom Token 샘플. 이 샘플의 간단한 웹 토큰 (SWT) 처리를 사용 하도록 설정 하는 사용자 지정 클래스를 제공 합니다. 여기에는 클래스 및 SimpleWebTokenHandler 클래스의 SimpleWebToken 구현뿐만 아니라 SWT 토큰을 지원하는 다른 클래스도 포함됩니다. 이 샘플 및 사용할 수 있는 다른 샘플에 대 한 WIF에 대 한 다운로드 위치에 대 한, 참조 WIF 코드 샘플 인덱스합니다. 다음 코드는 속성의 재정의를 ValidFrom 보여줍니다.

/// <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 from when the token is valid.
/// </summary>
/// <value>The time from when the token is valid.</value>
public override DateTime ValidFrom
{
    get 
    {
        string validFrom = _properties[SimpleWebTokenConstants.ValidFrom];
        return GetTimeAsDateTime( String.IsNullOrEmpty( validFrom ) ? "0" : validFrom );
    }
}
/// <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 );
}

설명

ValidFrom 토큰이 유효한 기간을 확인하려면 ValidToSecurityToken 속성을 사용합니다. ValidFromValidTo 속성은 각각 보안 토큰이 유효한 기간의 시작 시간과 종료 시간을 나타냅니다.

구현자 참고

속성을 재정의 ValidFrom 해야 합니다.

적용 대상