/// <summary> /// Gets all authorization codes that matches the specified redirect uri and expires after the /// specified date. Called when authenticating an authorization code. /// </summary> /// <param name="redirectUri">The redirect uri.</param> /// <param name="expires">The expire date.</param> /// <returns>The authorization codes.</returns> public async Task<IEnumerable<IAuthorizationCode>> GetAuthorizationCodes(string redirectUri, DateTime expires) { var db = this.GetDatabase(); var min = expires.ToUnixTime(); var codes = new List<IAuthorizationCode>(); var keys = db.SortedSetRangeByScore(this.Configuration.AuthorizationCodePrefix, min, DateTimeMax); foreach (var key in keys) { var hashedId = key.ToString().Substring(this.Configuration.AuthorizationCodePrefix.Length + 1); var id = Encoding.UTF8.GetString(Convert.FromBase64String(hashedId)); if (id.Contains(redirectUri)) { var hashEntries = await db.HashGetAllAsync(key.ToString()); if (hashEntries.Any()) { var code = new RedisAuthorizationCode(hashEntries) { Id = hashedId }; codes.Add(code); } } } return codes; }
/// <summary>Generates a key.</summary> /// <param name="authorizationCode">The authorization code.</param> /// <returns>The key.</returns> protected string GenerateKey(RedisAuthorizationCode authorizationCode) { return this.Configuration.AuthorizationCodePrefix + ":" + authorizationCode.Id; }