Seamless OpenId Connect / OAuth 2.0 security on HttpClient in .NET 6

Handling authentication and authorization when communicating with external services such as web APIs is a necessity in terms of security, but may be cumbersome, require a great deal of configuration and boiler-plate code, and is usually not the core of the business requirements that need to be solved.

But what if we can outsource the entire handling of the continuous process of authentication and authorization to external services with a simple one-time setup? This blog post aims to show how this can be done by configuring seamless OpenId Connect 2.0 / OAuth 2.0 flows on the HttpClient for communicating with external services over the HTTP protocol in .NET 6 / C#.