Пример #1
0
        public PrivateApiResponse <T> SendRequestWithIdentityHeaderConvertJwt <T>(object content, Dictionary <string, object> headerValue, HttpMethod httpMethod, string contentType = "application/json")
        {
            string contentString = ConvertToJsonString(content);

            using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Send request that contains Jwt X-IDENTITY header with {InternalTestEndpoint}"))
            {
                var HrbcAuth     = InternalConnection.GetCookieValue("HRBCAUTH");
                var tokenHeader  = HrbcAuth.Split('.')[0];
                var tokenSecret  = HrbcAuth.Split('.')[2];
                var tokenhandler = new JwtSecurityTokenHandler();
                var tokenObj     = tokenhandler.ReadJwtToken(HrbcAuth);
                var newPayLoad   = tokenObj.Payload.ToDictionary(p => p.Key, p => p.Value);
                var curPayLoad   = new Dictionary <string, object>();

                foreach (var item in headerValue)
                {
                    curPayLoad[item.Key.ToString()] = item.Value;
                }

                newPayLoad["payload"] = curPayLoad;
                JwtPayload jwtPayload = new JwtPayload();

                foreach (var item in newPayLoad)
                {
                    jwtPayload.Add(item.Key, item.Value);
                }

                InternalConnection.DeleteAllCookies();
                InternalConnection.Headers.Clear();
                InternalConnection.Headers.Add("X-IDENTITY", $"{tokenHeader}.{jwtPayload.Base64UrlEncode()}.{tokenSecret}");
                return(ProcessResponseWithContent <T>(InternalConnection.SendAsync(InternalTestEndpoint, contentString, httpMethod, contentType).Result));
            }
        }