> ## Documentation Index
> Fetch the complete documentation index at: https://docs-staging-quickstart-revamp.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> This guide demonstrates how to integrate Auth0 with any new or existing ASP.NET OWIN application using the Microsoft.Owin.Security.OpenIdConnect Nuget package.

# Add Login to your ASP.NET OWIN Application

export const SignUpForm = () => {
  return <div className="flex flex-col gap-2 items-center h-full">
      <img noZoom src="/docs/img/quickstarts/action_hero_dashboard.svg" alt="Sign up for an Auth0 account" style={{
    width: "250px",
    height: "250px"
  }} />
      <span className="text-center" style={{
    width: "400px"
  }}>
        Sign up for an{" "}
        <a href="https://auth0.com/signup" target="_blank" rel="noopener noreferrer">
          Auth0 account
        </a>{" "}
        or{" "}
        <span className="font-semibold text-primary cursor-pointer" onClick={() => console.log("log in")}>
          log in
        </span>{" "}
        to your existing account to integrate directly with your own tenant.
      </span>
      <button onClick={() => console.log("sign up")} className="bg-primary dark:bg-primary-light text-white dark:text-black px-4 py-2 rounded-md mt-4 font-medium" style={{
    width: "140px"
  }}>
        Sign up
      </button>
    </div>;
};

export const SideMenuSectionItem = ({id, children}) => {
  return <div id={`side-menu-item-${id}`} className="recipe-side-menu-item flex flex-col w-full h-full">
      {children}
    </div>;
};

export const SideMenu = ({sections, children}) => {
  const [visibleSection, setVisibleSection] = useState(sections[0]?.id ?? null);
  const checkVisibility = () => {
    let currentVisible = null;
    const viewportHeight = window.innerHeight;
    const scrollY = window.scrollY;
    sections.forEach(({id}) => {
      const section = document.getElementById(id);
      if (section) {
        const rect = section.getBoundingClientRect();
        const sectionTop = rect.top + scrollY;
        const sectionBottom = sectionTop + rect.height;
        const multiplier = viewportHeight > 1600 ? 0.34 : 0.22;
        if (scrollY + viewportHeight * multiplier >= sectionTop && scrollY <= sectionBottom) {
          currentVisible = id;
        }
      }
    });
    if (currentVisible && currentVisible !== visibleSection) {
      setVisibleSection(currentVisible);
    }
  };
  useEffect(() => {
    const throttledCheck = () => {
      setTimeout(checkVisibility, 100);
    };
    checkVisibility();
    window.addEventListener("scroll", throttledCheck);
    return () => {
      window.removeEventListener("scroll", throttledCheck);
    };
  }, [sections, visibleSection]);
  useEffect(() => {
    sections.forEach(({id}) => {
      const section = document.getElementById(id);
      const sideMenuItem = document.getElementById(`side-menu-item-${id}`);
      if (section) {
        if (id === visibleSection) {
          section.classList.add("active-section");
        } else {
          section.classList.remove("active-section");
        }
      }
      if (sideMenuItem) {
        if (id === visibleSection) {
          sideMenuItem.classList.add("active-side-menu-item");
        } else {
          sideMenuItem.classList.remove("active-side-menu-item");
        }
      }
    });
  }, [visibleSection, sections]);
  return <div className="recipe-side-menu sticky px-2 py-1" style={{
    height: "calc(100vh - 7rem)",
    top: "7rem",
    scrollMarginTop: "var(--scroll-mt)"
  }}>
      {children.map(child => {
    if (child.props.id === visibleSection) {
      return child;
    }
    return null;
  })}
    </div>;
};

export const Section = ({id, title, stepNumber, children, isSingleColumn = false}) => {
  return <div id={id} className={`recipe-section flex flex-col transition-opacity duration-200`}>
      {}
      <Step title={title} stepNumber={stepNumber} titleSize="h3">
        {children}
      </Step>
    </div>;
};

export const Content = ({title, children}) => {
  return <div className="recipe-content flex flex-col">
      {title && <h1 className="text-3xl">{title}</h1>}
      {children}
    </div>;
};

export const Recipe = ({children, isSingleColumn = false}) => {
  return <div className={`pl-4 recipe-container mx-auto grid grid-cols-1 gap-10 relative ${isSingleColumn ? "md:grid-cols-1" : "md:grid-cols-2"}`}>
      {children}
    </div>;
};

export const sections = [{
  id: "configure-auth0",
  title: "Configure Auth0"
}, {
  id: "configure-the-project",
  title: "Configure the project"
}, {
  id: "configure-the-middleware",
  title: "Configure the middleware"
}, {
  id: "add-login-to-your-application",
  title: "Add login to your application"
}, {
  id: "add-logout-to-your-application",
  title: "Add logout to your application"
}, {
  id: "show-user-profile-information",
  title: "Show user profile information"
}];

<Recipe>
  <Content>
    Auth0 allows you to quickly add authentication and gain access to user profile information in your application. This guide demonstrates how to integrate Auth0 with any new or existing ASP.NET OWIN application using the `Microsoft.Owin.Security.OpenIdConnect` Nuget package.

    <Section id={sections[0].id} title={sections[0].title} stepNumber="1">
      To use Auth0 services, you’ll need to have an application set up in the Auth0 Dashboard. The Auth0 application is where you will configure how you want authentication to work for the project you are developing.

      ### Configure an application

      Use the interactive selector to create a new Auth0 application or select an existing application that represents the project you want to integrate with. Every application in Auth0 is assigned an alphanumeric, unique client ID that your application code will use to call Auth0 APIs through the SDK.

      Any settings you configure using this quickstart will automatically update for your Application in the [Dashboard](https://manage.auth0.com/#/), which is where you can manage your Applications in the future.

      If you would rather explore a complete configuration, you can view a sample application instead.

      ### Configure Callback URLs

      A callback URL is a URL in your application that you would like Auth0 to redirect users to after they have authenticated. If not set, users will not be returned to your application after they log in.

      <Info>
        If you are following along with our sample project, set this to `http://localhost:3000/callback`.
      </Info>

      ### Configure Logout URLs

      A logout URL is a URL in your application that you would like Auth0 to redirect users to after they have logged out. If not set, users will not be able to log out from your application and will receive an error.

      <Info>
        If you are following along with our sample project, set this to `http://localhost:3000`.
      </Info>
    </Section>

    <Section id={sections[1].id} title={sections[1].title} stepNumber="2">
      ### Install from Nuget

      To integrate Auth0 with ASP.NET OWIN, you can use the `Microsoft.Owin.Security.OpenIdConnect` and `Microsoft.Owin.Security.Cookies` Nuget packages.

      ```text lines
      Install-Package Microsoft.Owin.Security.OpenIdConnect
      Install-Package Microsoft.Owin.Security.Cookies
      ```

      <Info>
        Issues occur when configuring the OWIN cookie middleware and System.Web cookies at the same time. To learn more, read [System.Web cookie integration issues doc](https://github.com/aspnet/AspNetKatana/wiki/System.Web-response-cookie-integration-issues) to mitigate these problems.
      </Info>

      ### Configure the credentials

      For the SDK to function properly, set the following properties in `Web.config`:

      * `auth0:Domain`: The domain of your Auth0 tenant. You can find this in the Auth0 Dashboard under your application's \*\*Settings \*\*in the Domain field. If you are using a [custom domain](/docs/customize/custom-domains), set this to the value of your custom domain instead.
      * `auth0:ClientId`: The ID of the Auth0 application you created in Auth0 Dashboard. You can find this in the Auth0 Dashboard under your application's \*\*Settings \*\*in the Client ID field.
    </Section>

    <Section id={sections[2].id} title={sections[2].title} stepNumber="3">
      To enable authentication in your ASP.NET OWIN application, go to the Configuration method of your Startup class and configure the cookie and OIDC middleware.

      It is essential that you register both the cookie middleware and the OpenID Connect middleware as both are required (in that order) for authentication to work. The OpenID Connect middleware handles the authentication with Auth0. Once users have authenticated, their identity is stored in the cookie middleware.

      In the code snippet, AuthenticationType is set to **Auth0**. Use AuthenticationType in the next section to challenge the OpenID Connect middleware and start the authentication flow. RedirectToIdentityProvider notification event constructs the correct logout URL.
    </Section>

    <Section id={sections[3].id} title={sections[3].title} stepNumber="4">
      To allow users to log in to your ASP.NET OWIN application, add a `Login` action to your controller.

      Call `HttpContext.GetOwinContext().Authentication.Challenge` and pass `"Auth0"` as the authentication scheme. This invokes the OIDC authentication handler that was registered earlier. Be sure to specify the corresponding `AuthenticationProperties`, including a `RedirectUri`.

      After successfully calling `HttpContext.GetOwinContext().Authentication.Challenge`, the user redirects to Auth0 and signed in to both the OIDC middleware and the cookie middleware upon being redirected back to your application. This will allow the users to be authenticated on subsequent requests.

      <Info>
        ##### Checkpoint

        Now that you have configured Login, run your application to verify that:

        * Navigating to your `Login` action will redirect to Auth0
        * Entering your credentials will redirect you back to your application.
      </Info>
    </Section>

    <Section id={sections[4].id} title={sections[4].title} stepNumber="5">
      From your controller's action, call `HttpContext.GetOwinContext().Authentication.SignOut` with the `CookieAuthenticationDefaults.AuthenticationType` authentication scheme to log the user out of your application.

      Additionally, if you want to log the user out from Auth0 (this might also log them out of other applications that rely on Single Sign-On), call `HttpContext.GetOwinContext().Authentication.SignOut` with the `"Auth0"` authentication scheme.

      <Info>
        ##### Checkpoint

        Now that you have configured Logout, run your application to verify that:

        * Navigating to your `Logout` action ensures the user is logged out.
        * During logout, you redirect to Auth0 and instantly redirect back to your application during log out.
      </Info>
    </Section>

    <Section id={sections[5].id} title={sections[5].title} stepNumber="6">
      After the middleware successfully retrieves the tokens from Auth0, it extracts the user's information and claims from the ID token and makes them available as `ClaimsIdentity`. Access the extracted information by using the `User` property on the controller.

      To create a user profile, retrieve a user's name, email address, and profile image from the `User` and pass it to the view from inside your controller.

      <Info>
        ##### Checkpoint

        Now that you have set up your action to render the user's profile, run your application to verify that:

        * Navigating to your `Profile` action after being successfully logged in, shows the user's profile.
      </Info>
    </Section>

    ## Next Steps

    Excellent work! If you made it this far, you should now have login, logout, and user profile information running in your application.

    This concludes our quickstart tutorial, but there is so much more to explore. To learn more about what you can do with Auth0, check out:

    * [Auth0 Dashboard](https://manage.auth0.com/) - Learn how to configure and manage your Auth0 tenant and applications
    * [Auth0 Marketplace](https://marketplace.auth0.com/) - Discover integrations you can enable to extend Auth0’s functionality
  </Content>

  <SideMenu sections={sections}>
    <SideMenuSectionItem id={sections[0].id}>
      <SignUpForm />
    </SideMenuSectionItem>

    <SideMenuSectionItem id={sections[1].id}>
      <CodeGroup>
        ```xml Web.config lines
        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <appSettings>
            <add key="auth0:Domain" value="{yourDomain}" />
            <add key="auth0:ClientId" value="{yourClientId}" />
          </appSettings>
        </configuration>
        ```

        ```cs AccountController.cs highlight={7-16} lines 
        using Microsoft.AspNetCore.Authentication;
        using Microsoft.AspNetCore.Authentication.Cookies;
        using Auth0.AspNetCore.Authentication;

        public class AccountController : Controller
        {
          public ActionResult Login(string returnUrl = "/")
          {
            HttpContext.GetOwinContext().Authentication.Challenge(
              new AuthenticationProperties
              {
                  RedirectUri = returnUrl ?? Url.Action("Index", "Home")
              },
              "Auth0"
            );
          }

          [Authorize]
          public ActionResult UserProfile()
          {
              var claimsIdentity = User.Identity as ClaimsIdentity;
              return View(new UserProfileViewModel()
              {
                  Name = claimsIdentity?
                    .FindFirst(c => c.Type == claimsIdentity.NameClaimType)?.Value,
                  EmailAddress = claimsIdentity?
                    .FindFirst(c => c.Type == ClaimTypes.Email)?.Value,
                  ProfileImage = claimsIdentity?
                    .FindFirst(c => c.Type == "picture")?.Value
              });
          }

          [Authorize]
          public void Logout()
          {
            HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
            HttpContext.GetOwinContext().Authentication.SignOut("Auth0");
          }
        }
        ```
      </CodeGroup>
    </SideMenuSectionItem>

    <SideMenuSectionItem id={sections[2].id}>
      <CodeGroup>
        ```xml Web.config lines
        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <appSettings>
            <add key="auth0:Domain" value="{yourDomain}" />
            <add key="auth0:ClientId" value="{yourClientId}" />
          </appSettings>
        </configuration>
        ```

        ```cs AccountController.cs highlight={7-16} lines 
        using Microsoft.AspNetCore.Authentication;
        using Microsoft.AspNetCore.Authentication.Cookies;
        using Auth0.AspNetCore.Authentication;

        public class AccountController : Controller
        {
          public ActionResult Login(string returnUrl = "/")
          {
            HttpContext.GetOwinContext().Authentication.Challenge(
              new AuthenticationProperties
              {
                  RedirectUri = returnUrl ?? Url.Action("Index", "Home")
              },
              "Auth0"
            );
          }

          [Authorize]
          public ActionResult UserProfile()
          {
              var claimsIdentity = User.Identity as ClaimsIdentity;
              return View(new UserProfileViewModel()
              {
                  Name = claimsIdentity?
                    .FindFirst(c => c.Type == claimsIdentity.NameClaimType)?.Value,
                  EmailAddress = claimsIdentity?
                    .FindFirst(c => c.Type == ClaimTypes.Email)?.Value,
                  ProfileImage = claimsIdentity?
                    .FindFirst(c => c.Type == "picture")?.Value
              });
          }

          [Authorize]
          public void Logout()
          {
            HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
            HttpContext.GetOwinContext().Authentication.SignOut("Auth0");
          }
        }
        ```
      </CodeGroup>
    </SideMenuSectionItem>

    <SideMenuSectionItem id={sections[3].id}>
      <CodeGroup>
        ```cs AccountController.cs highlight={7-16} lines 
        using Microsoft.AspNetCore.Authentication;
        using Microsoft.AspNetCore.Authentication.Cookies;
        using Auth0.AspNetCore.Authentication;

        public class AccountController : Controller
        {
          public ActionResult Login(string returnUrl = "/")
          {
            HttpContext.GetOwinContext().Authentication.Challenge(
              new AuthenticationProperties
              {
                  RedirectUri = returnUrl ?? Url.Action("Index", "Home")
              },
              "Auth0"
            );
          }

          [Authorize]
          public ActionResult UserProfile()
          {
              var claimsIdentity = User.Identity as ClaimsIdentity;
              return View(new UserProfileViewModel()
              {
                  Name = claimsIdentity?
                    .FindFirst(c => c.Type == claimsIdentity.NameClaimType)?.Value,
                  EmailAddress = claimsIdentity?
                    .FindFirst(c => c.Type == ClaimTypes.Email)?.Value,
                  ProfileImage = claimsIdentity?
                    .FindFirst(c => c.Type == "picture")?.Value
              });
          }

          [Authorize]
          public void Logout()
          {
            HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
            HttpContext.GetOwinContext().Authentication.SignOut("Auth0");
          }
        }
        ```

        ```xml Web.config lines
        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <appSettings>
            <add key="auth0:Domain" value="{yourDomain}" />
            <add key="auth0:ClientId" value="{yourClientId}" />
          </appSettings>
        </configuration>
        ```
      </CodeGroup>
    </SideMenuSectionItem>

    <SideMenuSectionItem id={sections[4].id}>
      <CodeGroup>
        ```cs AccountController.cs highlight={34-39} lines 
        using Microsoft.AspNetCore.Authentication;
        using Microsoft.AspNetCore.Authentication.Cookies;
        using Auth0.AspNetCore.Authentication;

        public class AccountController : Controller
        {
          public ActionResult Login(string returnUrl = "/")
          {
            HttpContext.GetOwinContext().Authentication.Challenge(
              new AuthenticationProperties
              {
                  RedirectUri = returnUrl ?? Url.Action("Index", "Home")
              },
              "Auth0"
            );
          }

          [Authorize]
          public ActionResult UserProfile()
          {
              var claimsIdentity = User.Identity as ClaimsIdentity;
              return View(new UserProfileViewModel()
              {
                  Name = claimsIdentity?
                    .FindFirst(c => c.Type == claimsIdentity.NameClaimType)?.Value,
                  EmailAddress = claimsIdentity?
                    .FindFirst(c => c.Type == ClaimTypes.Email)?.Value,
                  ProfileImage = claimsIdentity?
                    .FindFirst(c => c.Type == "picture")?.Value
              });
          }

          [Authorize]
          public void Logout()
          {
            HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
            HttpContext.GetOwinContext().Authentication.SignOut("Auth0");
          }
        }
        ```

        ```xml Web.config lines
        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <appSettings>
            <add key="auth0:Domain" value="{yourDomain}" />
            <add key="auth0:ClientId" value="{yourClientId}" />
          </appSettings>
        </configuration>
        ```
      </CodeGroup>
    </SideMenuSectionItem>

    <SideMenuSectionItem id={sections[5].id}>
      <CodeGroup>
        ```cs AccountController.cs highlight={18-32} lines 
        using Microsoft.AspNetCore.Authentication;
        using Microsoft.AspNetCore.Authentication.Cookies;
        using Auth0.AspNetCore.Authentication;

        public class AccountController : Controller
        {
          public ActionResult Login(string returnUrl = "/")
          {
            HttpContext.GetOwinContext().Authentication.Challenge(
              new AuthenticationProperties
              {
                  RedirectUri = returnUrl ?? Url.Action("Index", "Home")
              },
              "Auth0"
            );
          }

          [Authorize]
          public ActionResult UserProfile()
          {
              var claimsIdentity = User.Identity as ClaimsIdentity;
              return View(new UserProfileViewModel()
              {
                  Name = claimsIdentity?
                    .FindFirst(c => c.Type == claimsIdentity.NameClaimType)?.Value,
                  EmailAddress = claimsIdentity?
                    .FindFirst(c => c.Type == ClaimTypes.Email)?.Value,
                  ProfileImage = claimsIdentity?
                    .FindFirst(c => c.Type == "picture")?.Value
              });
          }

          [Authorize]
          public void Logout()
          {
            HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
            HttpContext.GetOwinContext().Authentication.SignOut("Auth0");
          }
        }
        ```

        ```xml Web.config lines
        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <appSettings>
            <add key="auth0:Domain" value="{yourDomain}" />
            <add key="auth0:ClientId" value="{yourClientId}" />
          </appSettings>
        </configuration>
        ```
      </CodeGroup>
    </SideMenuSectionItem>
  </SideMenu>
</Recipe>
