// POST: api/Authentication public IHttpActionResult Post(Authentication AuthData) { if (AuthData == null || !AuthData.IsComplete()) { return(BadRequest("Authentication data required but not provided")); } DataAccessSoapClient ws = new DataAccessSoapClient(); string token = ws.Login(AuthData.username, AuthData.password, new DataAccessWS.UserRole[2] { DataAccessWS.UserRole.BUYER, DataAccessWS.UserRole.SELLER }); if (string.IsNullOrEmpty(token)) { return(StatusCode(HttpStatusCode.Unauthorized)); } IdentityWSSoapClient idWS = new IdentityWSSoapClient(); IdentityData idData = idWS.GetIdentity(new IdentityWS.Security { BinarySecurityToken = token }); User user = ws.FindUserByUsername(idData.Username); return(Ok(new AuthToken { Token = token, Username = idData.Username, Role = idData.Role.ToString(), Id = user.Id })); }
private async Task <bool> authenticate(Message message) { string[] parts = message.Text.Split(new char[0]); if (parts.Length != 3) { await BotClient.SendTextMessageAsync(message.Chat.Id, "Authentication command format: /authenticate username password"); return(false); } else { DataAccessSoapClient ws = new DataAccessSoapClient(); string token = ws.Login(parts[1], parts[2], new DataAccessWS.UserRole[1] { DataAccessWS.UserRole.BUYER }); if (string.IsNullOrEmpty(token)) { await BotClient.SendTextMessageAsync(message.Chat.Id, "Invalid authentication data"); return(false); } else { await BotClient.SendTextMessageAsync(message.Chat.Id, "Auth token: " + token); return(true); } } }