Posts

API Authorization for HTTP triggered Azure Functions with OIDC and OAuth 2.0

(Source code updated Feb. 16, 2022, to .NET 6 and Azure Functions v4) I implemented a sample serverless API as an HTTP triggered Azure Function that is protected to ensure that only authorized apps can access that API. The sample Azure Function works when used with an authorization server that supports OpenID Connect (OIDC) and OAuth 2.0 protocols. Service providers that support compatible authorization servers include Auth0 , okta and many others. The complete sample code is in GitHub here . What follows is my high-level description of the concepts and API-side implementation of the mechanisms used to protect an API implemented as an HTTP triggered Azure Function using the OAuth 2.0 Client Credentials Flow. Here’s the breakdown of what follows: What’s in the sample code. Some context, a high-level description of the OIDC and OAuth 2.0 flows used. How to make a call to a protected API. How the code that protects the API is called within an HTTP triggered Azure Function. Th...

My C# Null-Conditional and Null-Coalescing Operator Friends

The null-conditional operator introduced in C# 6.0 makes me happy. Yes I know C# 7.0 is out now in VS 2017, but I've been on client projects using VS 2013 for a while now so C# 6.0 still seems exciting and fresh to me. Today I ran across this line in my code that uses the ternary operator. Now the ternary operator has been a friend of mine since I learned C. So at least I didn't have to use an if-else statement. string name = source != null  ? source.DisplayName : string.Empty; When I saw this code today, it occurred to me that I can rewrite it using my new friend the null-conditional operator and combine it with an old C# friend of mine the null-coalescing operator : string name = source?.DisplayName ?? string.Empty;​ Of course in the rewrite if source.DisplayName is null then name will be set to empty string. While it would be set to null in the code that uses the ternary operator. Hey look I fixed a bug too! So the null-conditional operator is my ...