# Using C# Extension Methods for Auth0 Authentication

**URL:** <https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417>\
**Category:** Blog Discussions\
**Tags:** csharp, dotnet, aspnet-core, .net\
**Created:** [December 28, 2020, 3:20pm UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417 "2020-12-28T15:20:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertino.calcaterra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/robertino.calcaterra/32/66825_2.png) [@robertino.calcaterra](https://community.auth0.com/u/robertino.calcaterra)\
**Post date:** [December 28, 2020, 3:20pm UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/1 "2020-12-28T15:20:59Z")

</div>

How to use C# extension methods to simplify Auth0 configuration for [ASP.NET](http://ASP.NET) web applications.  
[Read more](https://auth0.com/blog/using-csharp-extension-methods-for-auth0-authentication/)

Brought for you by @andrea.chiarelli

 ![Using C# Extension Methods for Auth0 Authentication](https://global.discourse-cdn.com/auth0/original/3X/4/9/496d3d27dda4c3d943060160f200faeb82255e2f.jpeg)

---

<div class="post-metadata">

**Author:** ![robertino.calcaterra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/robertino.calcaterra/32/66825_2.png) [@robertino.calcaterra](https://community.auth0.com/u/robertino.calcaterra)\
**Post date:** [December 28, 2020, 4:55pm UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/2 "2020-12-28T16:55:22Z")

</div>

Please let us know if you have any questions! 💬

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [December 28, 2020, 5:35pm UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/3 "2020-12-28T17:35:07Z")

</div>

Do you know other ways to simplify Auth0 dev experience in .NET? Share it with us!

---

<div class="post-metadata">

**Author:** ![nicholas.winston](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nicholas.winston/32/26583_2.png) [@nicholas.winston](https://community.auth0.com/u/nicholas.winston)\
**Post date:** [December 31, 2020, 8:12am UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/4 "2020-12-31T08:12:04Z")

</div>

Hi,  
I’ve written an article on Web Authentication. JSON Web Token (JWT) and its authentication into your Angular 8 project with a secure backend API running on Node.JS.  
[https://www.c-sharpcorner.com/article/json-web-auth-using-angular-8-and-nodejs/](https://www.c-sharpcorner.com/article/json-web-auth-using-angular-8-and-nodejs/)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 4, 2021, 9:57am UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/5 "2021-01-04T09:57:37Z")

</div>

Hey there Nicholas!

We have special place for such content. Can I ask you to create a topic in `Show Your Auth0` category where we highlight such things? It will be easier for everyone to find it there. Once you create it please delete the reply here. Thank you!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [February 5, 2021, 1:58pm UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/6 "2021-02-05T13:58:07Z")

</div>

This topic was automatically closed 27 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 15, 2021, 3:58pm UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/7 "2021-12-15T15:58:31Z")

</div>



---

<div class="post-metadata">

**Author:** ![SidK](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sidk/32/37366_2.png) [@SidK](https://community.auth0.com/u/SidK)\
**Post date:** [August 12, 2022, 11:08am UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/8 "2022-08-12T11:08:21Z")

</div>

Can you elaborate the use of ‘CookieAuthenticationDefaults’ here as authentication will not happen through cookie, right ?  
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;  
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;  
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [August 16, 2022, 8:54am UTC](https://community.auth0.com/t/using-c-extension-methods-for-auth0-authentication/55417/10 "2022-08-16T08:54:56Z")

</div>

Hi @SidK, 👋  
Thank you for joining the Auth0 Community.

Your question is a bit tricky and would require a specific article 🙂. I’ll try to explain in a few words here.

The reason for this has to do with [authentication schemes](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/#authentication-scheme), that is, a mechanism that specifies how to perform the different authentication steps.

Focusing on our case, when your user authenticates with Auth0 using OpenID Connect, your application receives an ID token. This token grants that the user is authenticated and optionally provides some user information.  
However, how does your application know that your user is authenticated **before** getting the token? How does your application know your user is authenticated each time it requests a new page?

You may think to check the existence of the ID token in each request. But this would require you to add the token to each request and check it opportunely, with all the potential security issues. The easiest way is to use a well-known and ready-to-use approach: the cookie scheme. This allows your application to automatically check the existence of the authentication cookie without requiring you to implement anything specific.

In other words, after your application receives the ID token from Auth0, an authentication cookie is created and sent to the browser. This cookie will be sent back to your application along with each request. This is why you have the cookie scheme configuration.

To answer your question “_authentication will not happen through cookie, right?_”, well, yes and no. You are combining two authentication schemes. The user is authenticated through OpenID Connection but each subsequent request is authenticated through the authentication cookie.

I hope this helps clarify.

By the way, bear in mind that you no longer need to build your own extension method to use Auth0. The [Auth0 SDK for ASP.NET Core Authentication](https://auth0.com/blog/exploring-auth0-aspnet-core-authentication-sdk/) does it for you.
