internal static AppAuthenticationResult Create(TokenResponse response, TokenResponse.DateFormat dateFormat)
        {
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            var expiresOnString = response.ExpiresOn ?? response.ExpiresOn2;
            var expiresOn       = DateTimeOffset.MinValue;

            switch (dateFormat)
            {
            case TokenResponse.DateFormat.DateTimeString:
                expiresOn = DateTimeOffset.Parse(expiresOnString);
                break;

            case TokenResponse.DateFormat.Unix:
                var seconds = double.Parse(expiresOnString);
                expiresOn = Models.AccessToken.UnixTimeEpoch.AddSeconds(seconds);
                break;
            }

            var result = new AppAuthenticationResult()
            {
                AccessToken = response.AccessToken ?? response.AccessToken2,
                ExpiresOn   = expiresOn,
                Resource    = response.Resource,
                TokenType   = response.TokenType ?? response.TokenType2
            };

            return(result);
        }
        internal static AppAuthenticationResult Create(AuthenticationResult authResult)
        {
            if (authResult == null)
            {
                throw new ArgumentNullException(nameof(authResult));
            }

            var result = new AppAuthenticationResult()
            {
                AccessToken = authResult.AccessToken,
                ExpiresOn   = authResult.ExpiresOn
            };

            return(result);
        }
        // For unit testing
        internal static AppAuthenticationResult Create(string accessToken)
        {
            if (string.IsNullOrEmpty(accessToken))
            {
                throw new ArgumentNullException(nameof(accessToken));
            }

            var tokenObj = Models.AccessToken.Parse(accessToken);

            var result = new AppAuthenticationResult
            {
                AccessToken = accessToken,
                ExpiresOn   = Models.AccessToken.UnixTimeEpoch.AddSeconds(tokenObj.ExpiryTime)
            };

            return(result);
        }