-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support of multiple schemas and IApiKeyProvider #12
Comments
Hi @maartenmensink, I really appreciate for taking your time out to test the library and raising issues. I have pushed changes to the master branch. I hope this will fix the issue. Please let me know if it passes your tests and you are happy with the implementation. If you are using NuGet package and not source code from github then I can push it to NuGet for you to try it out. private async Task<IApiKey> ValidateUsingApiKeyProviderAsync(string apiKey)
{
IApiKeyProvider apiKeyProvider = null;
if (Options.ApiKeyProviderType != null)
{
apiKeyProvider = ActivatorUtilities.GetServiceOrCreateInstance(Context.RequestServices, Options.ApiKeyProviderType) as IApiKeyProvider;
}
if (apiKeyProvider == null)
{
throw new InvalidOperationException($"Either {nameof(Options.Events.OnValidateKey)} delegate on configure options {nameof(Options.Events)} should be set or use an extention method with type parameter of type {nameof(IApiKeyProvider)}.");
}
try
{
return await apiKeyProvider.ProvideAsync(apiKey).ConfigureAwait(false);
}
finally
{
if (apiKeyProvider is IDisposable disposableApiKeyProvider)
{
disposableApiKeyProvider.Dispose();
}
}
} Please let me know you thoughts. Regards, |
You are welcome a nuget would be great. I can test the fix first if you would like. |
@maartenmensink I have uploaded it on NuGet. Version is 3.1.1 |
Hi @maartenmensink, has the new release fixed the issue for you? |
Assuming it is fixed, I am closing this issue. |
Sorry havent been able to find the time to test the fix but looking at the commit it will work! |
Hi,
Thanks for creating this library. I was testing the library and came across the following.
I am trying to add a second schema but due to a registration issue in the ApiKeyExtension the second provider overrides the first provider.
ApiKeyExtensions on line 384
This will cause ApiKeyHandlerBase:L193 to always return a instance to return. This will prevent it from reaching
if (apiKeyProvider == null)
and resolving a provider based on the type in the optionsapiKeyProvider = Context.RequestServices.GetService(Options.ApiKeyProviderType) as IApiKeyProvider;
The text was updated successfully, but these errors were encountered: