/// <summary> /// Instantiates a new HashedApiKeyAttribute. /// </summary> /// <param name="options">The options.</param> /// <param name="header">The header.</param> /// <param name="key">The key.</param> public HashedApiKeyAttributeImpl( IOptions <ApiKeyOptions> options, string header, string key) { this.header = header; this.key = key; hashedKey = options.Value.Secrets.FirstOrDefault(op => op.Key == key); }
/// <summary> /// Checks that the Api Key is valid. /// </summary> /// <param name="hashedKey">The hashed key.</param> /// <param name="hashWithPrefix">The hash with prefix.</param> /// <returns></returns> private static bool ApiKeyIsValid(HashedApiKey hashedKey, string hashWithPrefix) => new HashManager(hashWithPrefix.ThrowIfNull(nameof(hashWithPrefix)).Split('=')[0]) .MatchesHashed(hashedKey.Value, hashWithPrefix.Split('=')[1], hashedKey.Secret);