ASPC.Marvel.CrimeAPI.SharePointHighTrustContext.RenewAccessTokenIfNeeded C# (CSharp) Метод

RenewAccessTokenIfNeeded() приватный статический Метод

Renews the access token if it is not valid.
private static RenewAccessTokenIfNeeded ( DateTime>.Tuple &accessToken, Func tokenRenewalHandler ) : void
accessToken DateTime>.Tuple The access token to renew.
tokenRenewalHandler Func The token renewal handler.
Результат void
        private static void RenewAccessTokenIfNeeded(ref Tuple<string, DateTime> accessToken, Func<string> tokenRenewalHandler)
        {
            if (IsAccessTokenValid(accessToken))
            {
                return;
            }

            DateTime expiresOn = DateTime.UtcNow.Add(TokenHelper.HighTrustAccessTokenLifetime);

            if (TokenHelper.HighTrustAccessTokenLifetime > AccessTokenLifetimeTolerance)
            {
                // Make the access token get renewed a bit earlier than the time when it expires
                // so that the calls to SharePoint with it will have enough time to complete successfully.
                expiresOn -= AccessTokenLifetimeTolerance;
            }

            accessToken = Tuple.Create(tokenRenewalHandler(), expiresOn);
        }