# Is there a .Net 4.8 example using Authorization Code Flow? Does IAppBuilder UseOktaMvc work in Web Forms, not Mvc?

**URL:** <https://devforum.okta.com/t/is-there-a-net-4-8-example-using-authorization-code-flow-does-iappbuilder-useoktamvc-work-in-web-forms-not-mvc/16328>\
**Category:** Questions\
**Created:** [September 24, 2021, 7:56pm UTC](https://devforum.okta.com/t/is-there-a-net-4-8-example-using-authorization-code-flow-does-iappbuilder-useoktamvc-work-in-web-forms-not-mvc/16328 "2021-09-24T19:56:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ljames](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@ljames](https://devforum.okta.com/u/ljames)\
**Post date:** [September 24, 2021, 7:56pm UTC](https://devforum.okta.com/t/is-there-a-net-4-8-example-using-authorization-code-flow-does-iappbuilder-useoktamvc-work-in-web-forms-not-mvc/16328/1 "2021-09-24T19:56:56Z")

</div>

I can find examples for .Net 4.8 and Implicit Flow. I can find examples for .Net Web Forms Mvc and Authoriztion Code Flow. Is there an example for .Net 4.8 and Authorization Code Flow?

Thanks, John

---

<div class="post-metadata">

**Author:** ![HeatherDowning](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/heatherdowning/32/3427_2.png) [@HeatherDowning](https://devforum.okta.com/u/HeatherDowning)\
**Post date:** [October 12, 2021, 8:26pm UTC](https://devforum.okta.com/t/is-there-a-net-4-8-example-using-authorization-code-flow-does-iappbuilder-useoktamvc-work-in-web-forms-not-mvc/16328/2 "2021-10-12T20:26:57Z")

</div>

Hello James!

I used the Auth Code flow with .NET 4.8 for a Web API call in this article I wrote on Alexa integration:

> **[User Account Linking in Alexa with ASP.NET Web API](https://developer.okta.com/blog/2019/04/23/user-account-linking-alexa-aspnet-web-api#add-secure-alexa-account-linking-and-user-management)**
>
> This post covers the steps to building on an existing REST API written in C# to support an Alexa skill and link accounts to existing users managed by Okta.

---

<div class="post-metadata">

**Author:** ![ljames](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@ljames](https://devforum.okta.com/u/ljames)\
**Post date:** [October 13, 2021, 2:45am UTC](https://devforum.okta.com/t/is-there-a-net-4-8-example-using-authorization-code-flow-does-iappbuilder-useoktamvc-work-in-web-forms-not-mvc/16328/3 "2021-10-13T02:45:25Z")

</div>

I started with this example from 2018, striped out all the stuff that is not needed for a Visual Studio Web Site, and updated the code to use updated packages.  
[Secure Your ASP.NET Web Forms Application with OpenIDConnect and Okta](https://developer.okta.com/blog/2018/08/29/secure-webforms-with-openidconnect-okta)

I am left with 3 packages that are not provided by Microsoft, IdentityModel, Newtonsoft.Json and Owin. Does this sound like a good solution for a production environment?

Here is what the code looks like using the new packages.

static readonly HttpClient client = new HttpClient();  
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);  
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);  
app.UseCookieAuthentication(new CookieAuthenticationOptions());  
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions  
{  
Authority = \_authority,  
ClientId = \_clientId,  
ClientSecret = \_clientSecret,  
RedirectUri = \_redirectUri,  
ResponseType = OpenIdConnectResponseType.CodeIdToken, // GrantType.Hybrid  
Scope = “openid profile email your\_own\_scopes”,  
TokenValidationParameters = new TokenValidationParameters { NameClaimType = “name” },

```
Notifications = new OpenIdConnectAuthenticationNotifications
{
    AuthorizationCodeReceived = async n => // Exchange code for access and ID tokens
    {
        // use auth server URL, client id, client secret and auth code to request access token
        var tokenResponse = await client.RequestAuthorizationCodeTokenAsync(new AuthorizationCodeTokenRequest
        {
            Address = _authority + "/v1/token",
            ClientId = _clientId,
            ClientSecret = _clientSecret,
            Code = n.Code,
            RedirectUri = _redirectUri,
            // CodeVerifier = "xyz" // optional PKCE parameter 
         });

        if (tokenResponse.IsError)
            throw new Exception(tokenResponse.Error);

        // use auth server URL and access token to request id token
        var userInfoResponse = await client.GetUserInfoAsync(new UserInfoRequest
        {
            Address = _authority + "/v1/userinfo",
            Token = tokenResponse.AccessToken
        });

        if (userInfoResponse.IsError)
            throw new Exception(userInfoResponse.Error);

        var claims = new List<Claim>(userInfoResponse.Claims)
        {
            new Claim("id_token", tokenResponse.IdentityToken),
            new Claim("access_token", tokenResponse.AccessToken)
        };

        n.AuthenticationTicket.Identity.AddClaims(claims);
        // validate claims and use them as needed
```

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 10, 2024, 1:02am UTC](https://devforum.okta.com/t/is-there-a-net-4-8-example-using-authorization-code-flow-does-iappbuilder-useoktamvc-work-in-web-forms-not-mvc/16328/4 "2024-02-10T01:02:40Z")

</div>

Closed on February 10, 2024, 1:02am UTC


