# Authorization Code Flow with PKCE utilizing package Auth0.AspNetCore.Authentication

**URL:** <https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314>\
**Category:** Get Help\
**Tags:** pkce, aspnet-core\
**Created:** [February 15, 2022, 4:26pm UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314 "2022-02-15T16:26:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![arshad.sarfarz.1979](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/arshad.sarfarz.1979/32/33801_2.png) [@arshad.sarfarz.1979](https://community.auth0.com/u/arshad.sarfarz.1979)\
**Post date:** [February 15, 2022, 4:26pm UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/1 "2022-02-15T16:26:39Z")

</div>

Our team would like to use Authorization Code Flow with PKCE for server side applications. Can we use the package Auth0.AspNetCore.Authentication for implementing Authorization Code Flow with PKCE in [ASP.NET](http://ASP.NET) Core MVC? I explored the SDK and was able to find use of Authorization Code when a ClientSecret is provided. But could not find an option to use PKCE.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 16, 2022, 12:29am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/3 "2022-02-16T00:29:21Z")

</div>

Hi @arshad.sarfarz.1979,

Welcome to the Auth0 Community!

First, I would like to emphasize that the [ASP.NET](http://ASP.NET) Core MVC SDK is for Regular Web Apps, which are **confidential clients**. This uses the [Authorization Code Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow) for authentication and can securely store secrets.

Whereas the [Authorization Code Flow with PKCE](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-proof-key-for-code-exchange-pkce) is used in Single Page Applications and Native Apps for authentication. This is needed because SPAs and Native Apps are **public clients** and cannot securely store secrets.

With that said, I can confirm that implementing the authorization code flow with PKCE with a Regular Web App will not work.

I have tested this myself and found that it throws a `401 Unauthorized error` with a Regular Web App and works when using a SPA or Native App.

Hoped this helps!

Please do not hesitate to reach out if you have additional questions.

Thank you.

---

<div class="post-metadata">

**Author:** ![arshad.sarfarz.1979](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/arshad.sarfarz.1979/32/33801_2.png) [@arshad.sarfarz.1979](https://community.auth0.com/u/arshad.sarfarz.1979)\
**Post date:** [February 16, 2022, 8:53pm UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/4 "2022-02-16T20:53:31Z")

</div>

Thanks @rueben.tiow for the information

---

<div class="post-metadata">

**Author:** ![Hawxy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hawxy/32/21395_2.png) [@Hawxy](https://community.auth0.com/u/Hawxy)\
**Post date:** [February 17, 2022, 2:02am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/5 "2022-02-17T02:02:41Z")

</div>

> [@rueben.tiow](#):
>
> With that said, I can confirm that implementing the authorization code flow with PKCE with a Regular Web App will not work.

It’s interesting that you say that, as the underlying OpenIdConnect integration in [ASP.NET](http://ASP.NET) Core will automatically use PKCE if the response type is set to `Code`:  
[OpenIdConnectOptions.UsePkce Property (Microsoft.AspNetCore.Authentication.OpenIdConnect) | Microsoft Learn](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.openidconnect.openidconnectoptions.usepkce?view=aspnetcore-6.0)  
That includes the Auth0 SDK.

Is there something different between PKCE in confidential/public clients?

---

<div class="post-metadata">

**Author:** ![Keanu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/keanu/32/33313_2.png) [@Keanu](https://community.auth0.com/u/Keanu)\
**Post date:** [February 17, 2022, 11:04am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/6 "2022-02-17T11:04:19Z")

</div>

I faced similar kind of issue last time, I am still searching for some proper solution[.](https://www.rapidfs.online/)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 4, 2022, 11:05am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/7 "2022-03-04T11:05:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [March 9, 2022, 6:06pm UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/8 "2022-03-09T18:06:54Z")

</div>



---

<div class="post-metadata">

**Author:** ![arshad.sarfarz.1979](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/arshad.sarfarz.1979/32/33801_2.png) [@arshad.sarfarz.1979](https://community.auth0.com/u/arshad.sarfarz.1979)\
**Post date:** [March 24, 2022, 1:39am UTC](https://community.auth0.com/t/authorization-code-flow-with-pkce-utilizing-package-auth0-aspnetcore-authentication/78314/9 "2022-03-24T01:39:56Z")

</div>

Hi @rueben.tiow ,  
As mentioned by @Hawxy, since the underlying OpenIdConnect integration supports PKCE, the package Microsoft.AspNetCore.Authentication.OpenIdConnect is actually using PKCE when the response type is set to Code. I checked the code in github for the library [GitHub - auth0/auth0-aspnetcore-authentication: SDK for integrating Auth0 in ASPNET Core](https://github.com/auth0/auth0-aspnetcore-authentication). This library sets the response type to Code when the method “WithAccessToken” is used. I inspected the authorize URL sent to Auth0 server and it contains the parameters “code\_challenge” and “code\_challenge\_method”.
