OAuth 2.0 credential for accessing protected resources using an access token. This class will get the access token from "gcloud auth print-access-token".
Inheritance: ICredential, IHttpExecuteInterceptor, IHttpUnsuccessfulResponseHandler
        public void TestGetAccessTokenForRequestAsync()
        {
            AuthenticateWithSdkCredentialsExecutor activeUserCred = new AuthenticateWithSdkCredentialsExecutor();
            string accessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;

            TokenResponse activeToken = ActiveUserConfig.GetActiveUserToken(_cancelToken).Result;
            // The access token returned by GetAccessTokenForRequestAsync should be the same as that of active user config.
            Assert.IsTrue(
                Equals(activeToken.AccessToken, accessToken),
                "GetAccessTokenForRefreshAsync returns the wrong access token.");

            // The next call to GetAccessTokenForRequestAsync should returns the same token.
            accessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;
            Assert.IsTrue(
                Equals(activeToken.AccessToken, accessToken),
                "GetAccessTokenForRefreshAsync returns the wrong access token.");
        }
        public void TestGetAccessTokenExpiredByTime()
        {
            AuthenticateWithSdkCredentialsExecutor activeUserCred = new AuthenticateWithSdkCredentialsExecutor();
            TokenResponse activeToken = ActiveUserConfig.GetActiveUserToken(_cancelToken).Result;

            // Force the access token to expire.
            activeToken.ExpiredTime = DateTime.UtcNow.AddSeconds(-100);
            Assert.IsTrue(activeToken.IsExpired, "TokenResponse should be expired");

            string newAccessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;
            Assert.IsFalse(
                Equals(activeToken.AccessToken, newAccessToken),
                "GetAccessTokenForRefreshAsync should returns a new access token when the old one expired due to time.");

            // The next call to GetAccessTokenForRequestAsync should returns the same token.
            string anotherNewAccessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;
            Assert.IsTrue(
                Equals(anotherNewAccessToken, newAccessToken),
                "GetAccessTokenForRefreshAsync should returns a new access token when the old one expired due to time.");
        }
        public void TestRefreshTokenAsync()
        {
            AuthenticateWithSdkCredentialsExecutor activeUserCred = new AuthenticateWithSdkCredentialsExecutor();
            string currentAccessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;

            bool refreshed = activeUserCred.RefreshTokenAsync(_cancelToken).Result;
            Assert.IsTrue(refreshed, "RefreshTokenAsync should return true.");

            string refreshedAccessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;
            Assert.IsTrue(
                !Equals(currentAccessToken, refreshedAccessToken),
                "A different token should be returned when RefreshTokenAsync is called again.");

            refreshed = activeUserCred.RefreshTokenAsync(_cancelToken).Result;
            Assert.IsTrue(refreshed, "RefreshTokenAsync should return true.");

            string refreshedAccessTokenTwo = activeUserCred.GetAccessTokenForRequestAsync().Result;
            Assert.IsTrue(
                !Equals(refreshedAccessToken, refreshedAccessTokenTwo),
                "A different token should be returned when RefreshTokenAsync is called again.");
            Assert.IsTrue(
                !Equals(currentAccessToken, refreshedAccessTokenTwo),
                "A different token should be returned when RefreshTokenAsync is called again.");
        }