コード例 #1
0
        /// <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();
        }
コード例 #2
0
            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));
            }
コード例 #3
0
        /// <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));
            }
        }
コード例 #4
0
 /// <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)));
 }
コード例 #5
0
 /// <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;
 }