public LoginResponse UserLogin(JObject input) { LoginResponse objresponse = new LoginResponse(); try { string username = Convert.ToString(input["Username"]); string password = CommonMethods.Encrypt(Convert.ToString(input["Password"])); objresponse = objLoginBal.UserLogin(username, password); } catch (Exception ex) { objresponse.StatusId = 0; objresponse.StatusMessage = ex.Message; } return(objresponse); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { try { var form = await context.Request.ReadFormAsync(); string username = context.UserName; string password = CommonMethods.Encrypt(context.Password); var identity = new ClaimsIdentity(context.Options.AuthenticationType); LoginResponse objLoginResponse = new LoginResponse(); objLoginResponse = objLoginBal.UserLogin(username, password); if (objLoginResponse.StatusId == 1) { identity.AddClaim(new Claim(ClaimTypes.Role, objLoginResponse.RoleName)); identity.AddClaim(new Claim("username", username)); identity.AddClaim(new Claim(ClaimTypes.Name, objLoginResponse.Name)); AuthenticationProperties properties = CreateUserProperties(objLoginResponse); AuthenticationTicket ticket = new AuthenticationTicket(identity, properties); context.Validated(ticket); } else { context.SetError("invalid_grant", objLoginResponse.StatusMessage); return; } } catch (Exception ex) { context.SetError("invalid_grant", ex.Message); return; } }