title: .NET C# implement custom OAuth token function OWIN OAuth
body: <p>I'm trying to implement my own token function and cant get it to work. the <code>/Token</code> function provided by <code>owin oAuth</code> works fine but mine does not.</p>
  
  <p>I know my code is probably wrong but if someone could help I would really appreciate it.</p>
  
  <pre><code>public async Task&lt;string&gt; CustomToken() {
  
      using (var context = new ApplicationDbContext()) {
  
      ApplicationUser user = context.ApplicationUsers.FirstOrDefault();
      ClaimsIdentity oAuthIdentity = await UserManager.CreateIdentityAsync(user, OAuthDefaults.AuthenticationType);
      AuthenticationProperties properties = ApplicationOAuthProvider.CreateProperties(user.UserName);
      AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
  
      AuthenticationManager.SignIn(oAuthIdentity);
  
      return UserManager.GenerateUserTokenAsync("CustomLogin", user.Id).Result;
      }
  }
  </code></pre>