I have a asp.net application with a front end and a web api portion. I would like a mobile app to be able to use the protected web api endpoints. This means I need to log in and handle the auth token in the native mobile application.
Right now, the only way I can login to my asp.net application is by going through the default asp.net /Account/Login page. When I post to the login endpoint, the body that is returned just contains the html of my application. The token is then stored in cookies by asp.net.
Since I am trying to login from my native mobile app, I do not need the html response, and would not like to have to go through cookies to get my token.
Is it possible to create a separate login endpoint that only returns the token and/or user details, rather than the html content of my application? Is this a bad idea?
For reference, this is the default asp.net login handler i was referring to.
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); switch (result) { case SignInStatus.Success: return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return View(model); } }
[Authorize]attribute