Description | Custom AuthenticationHandler This code defines a custom authentication handler for a .NET Web API using access tokens. The handler is implemented by the CustomAuthenticationHandler class, which inherits from AuthenticationHandler<AuthenticationSchemeOptions> . Here's a breakdown of its functionality: Namespace and Imports : The code is organized under the DemoAccessTokenAuthInWebApi.Scheme namespace and uses various namespaces for authentication, Entity Framework Core, logging, and security. Constructor : The constructor initializes the handler with necessary services such as options, logger, URL encoder, and an instance of AuthDbContext , which is used for database interactions. HandleAuthenticateAsync Method : This method handles the authentication logic: It retrieves the authorization header from the incoming request. If the header is missing, it returns an authentication failure result. The token is extracted, decoded, and parsed to retrieve the user ID.