aspnetcore-authentication-apikey icon indicating copy to clipboard operation
aspnetcore-authentication-apikey copied to clipboard

Nullability - IApiKeyProvider.ProvideAsync should return Task<IApiKey?>

Open skyflyer opened this issue 1 year ago • 5 comments
trafficstars

Hello!

Thanks for the library 🙏!

Would you agree that it would be proper that the method declaration (ProvideAsync) in the IApiKeyProvider interface should return nullable value since it is explicitly checked in the handler? That way, no compiler warnings would be present (or escape hatches with !) 😄

skyflyer avatar Feb 22 '24 12:02 skyflyer

@skyflyer when the user is not authenticated by your implementation, it must return

return await Task.FromResult<IApiKey>(null);

renerlemes avatar Jun 09 '24 12:06 renerlemes

Sure, but the compiler will warn, because you're returning null when the interface definition does not define that a return type is nullable. That's all I'm saying. :)

skyflyer avatar Jun 09 '24 15:06 skyflyer

I didn't really understand your question, I understood that you wanted to know how to return the value. Reading better now, I understand and agree that it should be nullable.

Sorry 😄

renerlemes avatar Jun 09 '24 16:06 renerlemes