locked
Login using oauth 2 and owin RRS feed

  • Question

  • User-803397181 posted

    hi all,

    i have a multi-page web form application.

    i want to use token base authentication for login.

    i  use app.UseOAuthAuthorizationServer to configure the application to use token endpoint path.

    how can i implement login scenario?

    i successfully can get a bearer token. what should i do then?

    howto recognize current user in web form pages?

    thanks.

    Saturday, December 26, 2015 1:25 PM

Answers

  • User614698185 posted

    Hi Rainmater,

    OAuth doesn’t care where or how you manage your user account information. It’s ASP.NET Identity which is responsible for it.

    When the user clicks the Register button, the  Register  action of the Account controller creates the user by calling the ASP.NET Identity API, as below:

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Register(RegisterViewModel model)
    {
        if (ModelState.IsValid)
        {
            var user = new ApplicationUser() { UserName = model.UserName };
            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                await SignInAsync(user, isPersistent: false);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                AddErrors(result);
            }
        }
    
        // If we got this far, something failed, redisplay form
        return View(model);
    }

    For more information, please refer to the following documentations:

    http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity

    http://www.asp.net/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 28, 2015 8:48 AM