1

Here i wrote sesssion Based Authentication Using OAuthAuthorizationServerProvider This is My code

public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
    {
        var identity = new ClaimsIdentity(context.Options.AuthenticationType);
        if (context.UserName == "admin" && context.Password == "admin")
        {
            identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
            identity.AddClaim(new Claim("username", "admin"));
            identity.AddClaim(new Claim(ClaimTypes.Name, "MD"));
            context.Validated(identity);
        }
        else if (context.UserName == "user" && context.Password == "user")
        {
            identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
            identity.AddClaim(new Claim("username", "user"));
            identity.AddClaim(new Claim(ClaimTypes.Name, "MD"));
            context.Validated(identity);
        }
        else
        {
            context.SetError("invalid_grant", "Provided username and password is incorrect");
            return;
        }

Please Help me How can i implement Logout functionality

ems ems
  • 13
  • 2
  • which `DefaultAuthenticationTypes` are you using? its a `ExternalBearer` or `ApplicationCookie` or `ExternalCookie`? – er-sho Dec 17 '18 at 10:00
  • Bearer Authentication – ems ems Dec 17 '18 at 10:04
  • Have a look on answer here => https://stackoverflow.com/questions/26182660/how-to-logout-user-in-owin-asp-net-mvc5 – er-sho Dec 17 '18 at 10:08
  • @er-shoaib I had used this code var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignOut(); return Ok(); But its not Deleting Token – ems ems Dec 17 '18 at 10:17
  • You will get some [info](https://stackoverflow.com/a/24611815/5514820) here that why your code not deleting token. – er-sho Dec 17 '18 at 10:19

0 Answers0