/* * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ using System; using Amazon.CognitoIdentityProvider; using Amazon.CognitoIdentityProvider.Model; namespace Amazon.Extensions.CognitoAuthentication { public class CognitoUserSession { /// /// The ID token associated with the current user session. /// public string IdToken { get; set; } /// /// The access token associated with the current user session. /// public string AccessToken { get; set; } /// /// The refresh token associated with the current user session. /// public string RefreshToken { get; set; } /// /// The expiration time associated with the current session's tokens. ExpirationTime /// can only be configured through the constructor, and once set it cannot be changed. /// public DateTime ExpirationTime { get; private set; } /// /// The issue time associated with the current session's tokens. IssueTime /// can only be configured through the constructor, and once set it cannot be changed. /// public DateTime IssuedTime { get; private set; } /// /// Creates an instance of CognitoUserSession /// /// The ID token for the current user session /// The access token for the current user session /// The refresh token for the current user session /// The time the tokens were issued /// The time the tokens expire public CognitoUserSession(string idToken, string accessToken, string refreshToken, DateTime issuedTime, DateTime expirationTime) { this.IdToken = idToken; this.AccessToken = accessToken; this.RefreshToken = refreshToken; this.IssuedTime = issuedTime.ToUniversalTime(); this.ExpirationTime = expirationTime.ToUniversalTime(); } /// /// Determines if the tokens for a user are still valid /// /// Returns a boolean whether the user's tokens are still valid public bool IsValid() { DateTime currentTimeStamp = DateTime.UtcNow; return (currentTimeStamp.CompareTo(ExpirationTime) < 0); } } }