title: How to expose /Token End point from Startup.Auth.cs with Identity v2
body: <p>I am working with ASP.NET Identity 2 and trying to enable Token Authentication. From the Identity 2 sample there is nothing about Token Authentication so I setup myself by looking at different post. I am following the last answer of this post <a href="https://stackoverflow.com/questions/21077447/app-useoauthbearertokens-with-asp-net-identity-2-0s-dbcontext-middleware/21861080#21861080">app.UseOAuthBearerTokens with ASP.NET Identity 2.0&#39;s DbContext middleware?</a></p>
  
  <p>and able to setup each and everything but now when I try to reach this end point on browser <code>http://localhost:6722/token</code> getting 404 error. Any idea?</p>
  
  <p>Update:</p>
  
  <p>Here is my ApplicationOAuthProvider.cs</p>
  
  <pre><code>public class ApplicationOAuthProvider&lt;TUserManager, TUser, TKey&gt; : OAuthAuthorizationServerProvider
          where TUserManager : UserManager&lt;TUser, TKey&gt;
          where TUser : class, IUser&lt;TKey&gt;
          where TKey : IEquatable&lt;TKey&gt;
      {
          private readonly string _publicClientId;
  
  
          public ApplicationOAuthProvider(string publicClientId)
          {
              if (publicClientId == null)
              {
                  throw new ArgumentNullException("publicClientId");
              }
  
  
              _publicClientId = publicClientId;
          }
  
          public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
          {
              var userManager = context.OwinContext.Get&lt;TUserManager&gt;(_publicClientId);
  
              TUser user = await userManager.FindAsync(context.UserName, context.Password);
  
              if (user == null)
              {
                  context.SetError("invalid_grant", "The user name or password is incorrect.");
                  return;
              }
  
              ClaimsIdentity oAuthIdentity = await userManager.CreateIdentityAsync(user,
              context.Options.AuthenticationType);
              ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user,
              CookieAuthenticationDefaults.AuthenticationType);
              AuthenticationProperties properties = CreateProperties(user.UserName);
              AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
              context.Validated(ticket);
              context.Request.Context.Authentication.SignIn(cookiesIdentity);
          }
  
          public override Task TokenEndpoint(OAuthTokenEndpointContext context)
          {
              foreach (KeyValuePair&lt;string, string&gt; property in context.Properties.Dictionary)
              {
                  context.AdditionalResponseParameters.Add(property.Key, property.Value);
              }
  
              return Task.FromResult&lt;object&gt;(null);
          }
  
          public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
          {
              // Resource owner password credentials does not provide a client ID.
              if (context.ClientId == null)
              {
                  context.Validated();
              }
  
              return Task.FromResult&lt;object&gt;(null);
          }
  
          public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
          {
              if (context.ClientId == _publicClientId)
              {
                  Uri expectedRootUri = new Uri(context.Request.Uri, "/");
  
                  if (expectedRootUri.AbsoluteUri == context.RedirectUri)
                  {
                      context.Validated();
                  }
              }
  
              return Task.FromResult&lt;object&gt;(null);
          }
  
          public static AuthenticationProperties CreateProperties(string userName)
          {
              IDictionary&lt;string, string&gt; data = new Dictionary&lt;string, string&gt;
              {
                  {
                      "userName", userName
                  }
              };
              return new AuthenticationProperties(data);
          }
      }
  </code></pre>
  
  <p>Here is my Startup.Oauth.cs</p>
  
  <pre><code> public partial class Startup
      {
  
          static Startup()
          {
              PublicClientId = "self";
              OAuthOptions = new OAuthAuthorizationServerOptions
              {
                  TokenEndpointPath = new PathString("/Token"),
                  Provider = new ApplicationOAuthProvider&lt;ApplicationUserManager, User, int&gt;(PublicClientId),
                  AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
                  AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                  AllowInsecureHttp = false
              };
  
          }
          public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
          public static string PublicClientId { get; private set; }
  
  
          // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
          public void ConfigureAuth(IAppBuilder app)
          {
              // Configure the db context, user manager and role manager to use a single instance per request
              app.CreatePerOwinContext(ApplicationDb.Create);
              app.CreatePerOwinContext&lt;ApplicationUserManager&gt;(ApplicationUserManager.Create);
              app.CreatePerOwinContext&lt;ApplicationRoleManager&gt;(ApplicationRoleManager.Create);
  
              // Enable the application to use a cookie to store information for the signed in user
              // and to use a cookie to temporarily store information about a user logging in with a third party login provider
              // Configure the sign in cookie
              app.UseCookieAuthentication(new CookieAuthenticationOptions
              {
                  AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                  LoginPath = new PathString("/Account/Login"),
                  Provider = new CookieAuthenticationProvider
                  {
                      // Enables the application to validate the security stamp when the user logs in.
                      // This is a security feature which is used when you change a password or add an external login to your account.  
                      OnValidateIdentity = SecurityStampValidator.OnValidateIdentity&lt;ApplicationUserManager, User, int&gt;(
                          validateInterval: TimeSpan.FromMinutes(30),
                          regenerateIdentityCallback: (manager, user) =&gt; user.GenerateUserIdentityAsync(manager),
                          getUserIdCallback: (claim) =&gt; int.Parse(claim.GetUserId()))
  
                  }
              });
  
  
  
              app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  
              // Enable the application to use bearer tokens to authenticate users
              app.UseOAuthBearerTokens(OAuthOptions);
              // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
              app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
  
              // Enables the application to remember the second login verification factor such as phone or email.
              // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
              // This is similar to the RememberMe option when you log in.
              app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
  
  
  
              // Uncomment the following lines to enable logging in with third party login providers
              //app.UseMicrosoftAccountAuthentication(
              //    clientId: "",
              //    clientSecret: "");
  
              //app.UseTwitterAuthentication(
              //   consumerKey: "",
              //   consumerSecret: "");
  
              //app.UseFacebookAuthentication(
              //   appId: "",
              //   appSecret: "");
  
              //app.UseGoogleAuthentication();
          }
      }
  </code></pre>
  
  <p>And I am trying to access /Token end point directly from the browser and it throws 404 error.</p>