/// <summary>
        /// Initializes this <see cref="RefreshTokenFileStorage"/> and reads all <see cref="RefreshTokenJson"/> from the home directory.
        /// </summary>
        /// <param name="homeDirectory">home directory path</param>
        public void Initialize(string homeDirectory)
        {
            _homeDirectory = homeDirectory;

            if (!Directory.Exists(homeDirectory))
            {
                Directory.CreateDirectory(homeDirectory);
                File.WriteAllText(_homeDirectory + "ID.config", 0 + "");
            }

            _refreshTokens = new List <IRefreshToken>();

            //load all client accounts:
            foreach (string file in Directory.EnumerateFiles(_homeDirectory, "*.json"))
            {
                string           json = File.ReadAllText(file);
                RefreshTokenJson rtj  = JsonSerializer.DeserializeJson <RefreshTokenJson>(json);
                if (rtj != null)
                {
                    _refreshTokens.Add(rtj);
                }
            }
        }
        public void CreateRefreshToken(string refreshToken, string subject, string clientId, long validUntil, string scope, bool isInvalidated)
        {
            if (String.IsNullOrWhiteSpace(refreshToken))
            {
                throw new Exception("refresh token is not set");
            }
            if (HasRefreshToken(refreshToken))
            {
                throw new Exception("Refresh token is already existing");
            }
            else
            {
                IRefreshToken data = new RefreshTokenJson();
                data.RefreshToken  = refreshToken;
                data.Subject       = subject;
                data.ClientId      = clientId;
                data.ValidUntil    = validUntil;
                data.Scope         = scope;
                data.IsInvalidated = isInvalidated;

                _refreshTokens.Add(data);
                SaveToDisk(data);
            }
        }