public HttpResponseMessage Login(LoginEmployeeCommand command) { var result = _commandProcessor.Handle(command); if (result.Success) { return(new HttpResponseMessage(HttpStatusCode.OK)); } return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var lifetimeScope = OwinContextExtensions.GetAutofacLifetimeScope(context.OwinContext); var queryProcessor = lifetimeScope.Resolve <QueryProcessor>(); var commandProcessor = lifetimeScope.Resolve <CommandProcessor>(); await Task.CompletedTask; var loginCommand = new LoginEmployeeCommand(context.UserName, context.Password); var loginResult = commandProcessor.Handle(loginCommand); var identity = new ClaimsIdentity(context.Options.AuthenticationType); if (loginResult.Success) { identity.AddClaim(new Claim(ClaimTypes.Name, loginResult.Result.Name)); identity.AddClaim(new Claim(ClaimTypes.Role, loginResult.Result.EmployeeGroupId.ToString())); identity.AddClaim(new Claim("EmployerId", loginResult.Result.EmployerId.ToString())); context.Validated(identity); } else { context.SetError("invalid_grant", "Provided username and password are incorrect"); return; } //if (context.UserName == "admin" && context.Password == "admin") //{ // identity.AddClaim(new Claim(ClaimTypes.Role, "admin")); // identity.AddClaim(new Claim(ClaimTypes.Role, "admin2")); // identity.AddClaim(new Claim("username", "admin")); // identity.AddClaim(new Claim(ClaimTypes.Name, "Sourav Mondal")); //} //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, "Suresh Sha")); // context.Validated(identity); //} //else //{ // context.SetError("invalid_grant", "Provided username and password is incorrect"); // return; //} }