Click here to Skip to main content
14,241,236 members
Rate this:
Please Sign up or sign in to vote.
This is my statrup Class

public partial class Startup
       public void Configuration(IAppBuilder app)
           HttpConfiguration config = new HttpConfiguration();

       //private void ConfigureAuth(IAppBuilder app)
       //    throw new NotImplementedException();

       public void ConfigureOAuth(IAppBuilder app)
           OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
               AllowInsecureHttp = true,
               TokenEndpointPath = new PathString("/token"),
               AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
               Provider = new SimpleAuthorizationServerProvider()

           // Token Generation
           app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());


This one is my AuthRepositry class
public class AuthRepository : IDisposable
       private MobileAppEntities _ctx;
       private UserManager<ApplicationUser> _userManager;// UserManager { get { return _userManager; } private set { } }
       public AuthRepository()
           _ctx = new MobileAppEntities();
           _userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(_ctx));
       public async Task<IdentityUser> FindUser(string userName, string password)
           IdentityUser user = await _userManager.FindAsync(userName, password);
           return user;
       public void Dispose()

This one Authorization Server Provider Class
public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
       private ApplicationUserManager _userManager;
       public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)

       public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)

           context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

           using (AuthRepository _repo = new AuthRepository())
               IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

               if (user == null)
                   context.SetError("invalid_grant", "The user name or password is incorrect.");

           var identity = new ClaimsIdentity(context.Options.AuthenticationType);
           identity.AddClaim(new Claim("sub", context.UserName));
           identity.AddClaim(new Claim("role", "user"));



What I have tried:

Every time when i am posting request from postman it gave error like that
"error": "unsupported_grant_type"
Updated 10-Dec-18 17:17pm
Vincent Maverick Durano 11-Dec-18 7:20am
Can you show us your CURL you used in Postman?
Aitzaz Ahsan 11-Dec-18 7:34am
you can see my postman request through link
Richard Deeming 11-Dec-18 8:42am
The error in your screen-shot doesn't match the error in your question.
Vincent Maverick Durano 11-Dec-18 19:50pm
As already mentioned, the error was different from the original question. For the error in the link, It seems like your user object is null. Check the username and password by debugging your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100