public async Task <AuthenticationInfo> TempAuthenticate([FromBody] dynamic model) { try { var protocol = (string)model.protocol; var cookie = (string)model.cookie; //read/decode request var req = _auto.Value.DecodeRequest(cookie, protocol); if (!_auto.Value.IsProtocolAllowed(protocol)) { throw new Exception("Stronger protocol is required for this operation"); } if (_auto.Value.HasReqExpired(req)) { throw new Exception("Request has expired"); } var user = req.GetValue("user").ToString(); var admin = req.GetValue("admin").ToString(); var adminPass = req.GetValue("pass").ToString(); var role = req.GetValue("role").ToString(); var adminCookie = _impl.AuthenticateUser(admin, adminPass, null, null); //cleanup try { var expired = _impl.ListExpiredTempUsers(); foreach (var expiredUser in expired) { _impl.DeleteUser(adminCookie, expiredUser, null); //also remove any user options _options.Value.DeleteUserOption(adminCookie, expiredUser); } } catch { } var ai = _impl.TempAuthenticate(adminCookie, user, role); //automate var autoCookie = _auto.Value.Automate(ai.Cookie); System.Diagnostics.Debug.Assert(autoCookie == ai.Cookie);//client relies on the fact they are equal var cmd = req.GetValue("cmd").ToString(); var cmdParams = req.GetValue("p").ToString(); await _auto.Value.QueueCommand(autoCookie, autoCookie, cmd, cmdParams); return(ai); } catch (Exception ex) { throw Error(ex); } }