public HttpResponseMessage auth(LoginRequestAuth login) { ActiveDirectoryUser user = null; if (login == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } try { var domName = ActiveDirectoryService.Get_correct_DomainName(login.domain); var res = ActiveDirectoryService.User_Logon(login.username, login.password, domName); if (res.Autenticated) { if (login.includeDomainUserData) { try { user = ActiveDirectoryService.User_Info(login.username, domName); } catch (Exception ex) { res.ErrorMessage = "No fué posible obtener datos del usuario en el dominio. Razon = " + ex.Message; } } List <ActiveDirectoryGroup> userGroups = null; if (login.includeGroups) { try { userGroups = ActiveDirectoryService.GetGroupsFromUser(login.username, domName); } catch (Exception ex) { res.ErrorMessage = "No fué posible obtener los grupos usuario en el dominio. Razon = " + ex.Message; } } var jwt = TokenGenerator.GenerateTokenJwt_LDAP(login.username, user, userGroups); res.Token = jwt; } var resp = apiHelper.fromObject <LoogonUserResult>(res); return(resp); } catch (Exception ex) { return(apiHelper.fromEx(ex)); } }
public IActionResult auth(LoginRequestAuth login) { ActiveDirectoryUser user = null; if (login == null) { return(BadRequest(new ApiErrorResponse(HttpStatusCode.BadRequest, "Los parámetros del loging no son opcionales"))); } try { var res = ActiveDirectoryService.User_Logon(login.username, login.password, login.domain); if (res.Autenticated) { if (login.includeDomainUserData) { try { user = ActiveDirectoryService.User_Info(login.username, login.domain); } catch (Exception ex) { res.ErrorMessage = "No fué posible obtener datos del usuario en el dominio. Razon = " + ex.Message; } } List <ActiveDirectoryGroup> userGroups = null; if (login.includeGroups) { try { userGroups = ActiveDirectoryService.GetGroupsFromUser(login.username, login.domain); } catch (Exception ex) { res.ErrorMessage = "No fué posible obtener los grupos usuario en el dominio. Razon = " + ex.Message; } } var jwt = TokenGenerator.GenerateTokenJwt_LDAP(login.username, user, userGroups); res.Token = jwt; } return(Ok(res)); } catch (Exception ex) { var msg = apiHelper.getMessageException(ex); return(BadRequest(new ApiErrorResponse(HttpStatusCode.InternalServerError, msg))); } }
public IActionResult authTest(LoginRequestAuth login) { ActiveDirectoryUser user = null; if (login == null) { return(BadRequest(new ApiErrorResponse(HttpStatusCode.BadRequest, "Los parámetros del loging no son opcionales"))); } try { //var res = ActiveDirectoryService.User_Logon(login.username, login.password, login.domain); var res = new LoogonUserResult(); res.Autenticated = true; if (res.Autenticated) { if (login.includeDomainUserData) { try { //user = ActiveDirectoryService.User_Info(login.username, login.domain); user = new ActiveDirectoryUser(); user.Company = "contoso"; user.Country = "arg"; user.FirstName = login.username; user.LoginName = login.username; user.EmailAddress = login.username + "@contoso.co"; } catch (Exception ex) { res.ErrorMessage = "No fué posible obtener datos del usuario en el dominio. Razon = " + ex.Message; } } List <ActiveDirectoryGroup> userGroups = null; if (login.includeGroups) { try { userGroups = new List <ActiveDirectoryGroup>(); ActiveDirectoryGroup g = new ActiveDirectoryGroup(); g.CN = "co"; g.Description = "co"; g.Name = "contoso"; userGroups.Add(g); } catch (Exception ex) { res.ErrorMessage = "No fué posible obtener los grupos usuario en el dominio. Razon = " + ex.Message; } } var jwt = TokenGenerator.GenerateTokenJwt_test(login.username, user, userGroups); res.Token = jwt; } return(Ok(res)); } catch (Exception ex) { var msg = apiHelper.getMessageException(ex); return(BadRequest(new ApiErrorResponse(HttpStatusCode.InternalServerError, msg))); } }