public void ApiKey_ExecutionRequestValidationShouldSucceedIfGoodToken()
        {
            Prepare();
            ServiceProxySystem.Register <ApiKeyRequiredEcho>();

            string methodName = MethodBase.GetCurrentMethod().Name;
            IApplicationNameProvider nameProvider = new TestApplicationNameProvider(methodName);
            IApiKeyProvider          keyProvider  = new LocalApiKeyProvider();

            string           className = "ApiKeyRequiredEcho";
            string           method    = "Send";
            string           data      = ApiParameters.ParametersToJsonParamsArray("some random data").ToJson();
            ExecutionRequest er        = new ExecutionRequest(className, method, "json")
            {
                JsonParams     = data,
                ApiKeyResolver = new ApiKeyResolver(keyProvider, nameProvider),
                Request        = new ServiceProxyTestHelpers.FormUrlEncodedTestRequest()
            };

            er.ApiKeyResolver.SetKeyToken(er.Request.Headers, ApiParameters.GetStringToHash(className, method, data));

            ValidationResult result = er.Validate();

            Expect.IsTrue(result.Success);
        }
Ejemplo n.º 2
0
        protected override string Post(ServiceProxyInvokeEventArgs invokeArgs, HttpWebRequest request)
        {
            string baseAddress = invokeArgs.BaseAddress;
            string className   = invokeArgs.ClassName;
            string methodName  = invokeArgs.MethodName;

            object[] parameters = invokeArgs.PostParameters;
            if (className.Equals("securechannel", StringComparison.InvariantCultureIgnoreCase) && methodName.Equals("invoke", StringComparison.InvariantCultureIgnoreCase))
            {
                // the target is the SecureChannel.Invoke method but we
                // need the actual className and method that is in the parameters
                // object
                string   actualClassName  = (string)parameters[0];
                string   actualMethodName = (string)parameters[1];
                string   jsonParams       = (string)parameters[2];
                HttpArgs args             = new HttpArgs();
                args.ParseJson(jsonParams);

                if (TypeRequiresApiKey || MethodRequiresApiKey(actualMethodName))
                {
                    ApiKeyResolver.SetKeyToken(request, ApiParameters.GetStringToHash(actualClassName, actualMethodName, args["jsonParams"]));
                }
            }
            return(base.Post(invokeArgs, request));
        }
Ejemplo n.º 3
0
        public bool IsValidRequest(ExecutionRequest request)
        {
            Args.ThrowIfNull(request, "request");
            string stringToHash = ApiParameters.GetStringToHash(request);
            string token        = request.Context.Request.Headers[CustomHeaders.KeyToken];
            bool   result       = false;

            if (!string.IsNullOrEmpty(token))
            {
                result = IsValidKeyToken(stringToHash, token);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public bool IsValidRequest(ExecutionRequest request)
        {
            Args.ThrowIfNull(request, "request");

            string className    = request.ClassName;
            string methodName   = request.MethodName;
            string stringToHash = ApiParameters.GetStringToHash(className, methodName, request.JsonParams);

            string token  = request.Context.Request.Headers[Headers.KeyToken];
            bool   result = false;

            if (!string.IsNullOrEmpty(token))
            {
                result = IsValidKeyToken(stringToHash, token);
            }

            return(result);
        }