public static async Task <NewUserMinimumParams> GetNewUserParams(this IKeeperEndpoint endpoint, string username) { var authRequest = new DomainPasswordRulesRequest { Username = username }; var payload = new ApiRequestPayload { Payload = ByteString.CopyFrom(authRequest.ToByteArray()) }; var rs = await endpoint.ExecuteRest("authentication/get_domain_password_rules", payload); return(NewUserMinimumParams.Parser.ParseFrom(rs)); }
/// <summary> /// Executes JSON request. /// </summary> /// <param name="endpoint">Keeper endpoint interface.</param> /// <param name="command">Keeper JSON command.</param> /// <param name="responseType">Keeper JSON response type.</param> /// <returns>Task returning Keeper JSON response.</returns> public static async Task <KeeperApiResponse> ExecuteV2Command(this IKeeperEndpoint endpoint, KeeperApiCommand command, Type responseType) { if (responseType == null) { responseType = typeof(KeeperApiResponse); } else if (!typeof(KeeperApiResponse).IsAssignableFrom(responseType)) { responseType = typeof(KeeperApiResponse); } command.locale = endpoint.Locale; command.clientVersion = endpoint.ClientVersion; byte[] rq; using (var ms = new MemoryStream()) { var cmdSerializer = new DataContractJsonSerializer(command.GetType(), JsonUtils.JsonSettings); cmdSerializer.WriteObject(ms, command); rq = ms.ToArray(); } var apiPayload = new ApiRequestPayload() { Payload = ByteString.CopyFrom(rq) }; #if DEBUG Debug.WriteLine("Request: " + Encoding.UTF8.GetString(rq)); #endif var rs = await endpoint.ExecuteRest("vault/execute_v2_command", apiPayload); #if DEBUG Debug.WriteLine("Response: " + Encoding.UTF8.GetString(rs)); #endif using (var ms = new MemoryStream(rs)) { var rsSerializer = new DataContractJsonSerializer(responseType, JsonUtils.JsonSettings); return((KeeperApiResponse)rsSerializer.ReadObject(ms)); } }