static void Main(string[] args)
        {
            try
            {
                // TODO: Add logic to get the logged on user's refresh token
                // from secured storage.

                bool b2b = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("b2b"));

                UserOperations userOperations = new UserOperations();

                if (!b2b)
                {
                    _tokens = GetOauthTokens_AuthCode(_storedRefreshToken, _clientId);

                    PrintTokens(_tokens.AccessToken, _tokens.RefreshToken, _tokens.Expiration);
                    userOperations.CreateUser(_tokens.AccessToken);
                    userOperations.GetUsers(_tokens.AccessToken);
                }
                else
                {
                    _b2bTokens = GetToken(_storedRefreshToken, _clientId);

                    PrintTokens(_b2bTokens.AccessToken, _b2bTokens.RefreshToken, _b2bTokens.Expiration);
                    userOperations.GetUsers(_b2bTokens.AccessToken);
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("\n" + e.Message);
            }
        }
        private static CodeGrantOauth GetOauthTokens_AuthCode(string refreshToken, string clientId)
        {
            CodeGrantOauth auth = new CodeGrantOauth(clientId);

            if (string.IsNullOrEmpty(refreshToken))
            {
                auth.GetAccessToken();
            }
            else
            {
                auth.RefreshAccessToken(refreshToken);

                // Refresh tokens can become invalid for several reasons
                // such as the user's password changed.

                if (!string.IsNullOrEmpty(auth.Error))
                {
                    auth = GetOauthTokens_AuthCode(null, clientId);
                }
            }

            // TODO: Store the new refresh token in secured storage
            // for the logged on user.

            if (!string.IsNullOrEmpty(auth.Error))
            {
                throw new Exception(auth.Error);
            }
            else
            {
                _storedRefreshToken = auth.RefreshToken;
                _tokenExpiration    = DateTime.Now.AddSeconds(auth.Expiration);
            }

            return(auth);
        }