/// <summary> /// Constructor. /// </summary> /// <param name="storage">Configuration storage.</param> /// <param name="endpoint">Keeper Endpoint.</param> public AuthSync(IConfigurationStorage storage, IKeeperEndpoint endpoint = null) { Storage = storage ?? new InMemoryConfigurationStorage(); Endpoint = endpoint ?? new KeeperEndpoint(Storage.LastServer, Storage.Servers); Cancel(); }
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)); } }
/// <summary> /// Executes Keeper JSON command. Generic version. /// </summary> /// <typeparam name="TC">Keeper Protobuf Request Type.</typeparam> /// <typeparam name="TR">Keeper Protobuf Response Type.</typeparam> /// <param name="endpoint">Keeper endpoint interface.</param> /// <param name="request">Keeper Protobuf Request.</param> /// <returns>Task returning Protobuf Response.</returns> public static async Task <TR> ExecuteV2Command <TC, TR>(this IKeeperEndpoint endpoint, TC request) where TC : KeeperApiCommand where TR : KeeperApiResponse { return((TR)await endpoint.ExecuteV2Command(request, typeof(TR))); }
/// <summary> /// Constructor. /// </summary> /// <param name="authUi">User Interface.</param> /// <param name="storage">Configuration storage.</param> /// <param name="endpoint">Keeper Endpoint.</param> public Auth(IAuthUI authUi, IConfigurationStorage storage, IKeeperEndpoint endpoint = null) { Storage = storage ?? new InMemoryConfigurationStorage(); Endpoint = endpoint ?? new KeeperEndpoint(Storage.LastServer, Storage.Servers); Ui = authUi; }