Skip to content

Commit

Permalink
Merge pull request #317 in TSI/web-application from feature/TSI-3302 …
Browse files Browse the repository at this point in the history
…to develop

* commit '848b41d4bac19a08c20bbe8e0499a23e7a0ddaac':
  TSI-3302 : Forward on conditions to model-service
  • Loading branch information
majiccode committed Jun 8, 2018
2 parents 9513a46 + 848b41d commit 14a7bdc
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Sdl.Web.ModelService/ModelServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ private string PerformRequest(Uri requestUri)
SetCookie(request, PreviewSessionTokenCookie, cookies[PreviewSessionTokenCookie]);
}

// Forward all claims on to model-service
var forwardedClaimValues = AmbientDataContext.ForwardedClaims;
if (forwardedClaimValues != null && forwardedClaimValues.Count > 0)
{
Expand All @@ -252,10 +253,17 @@ private string PerformRequest(Uri requestUri)
{
byte[] cookieValue = claimsCookie.Value;
Cookie cookie = new Cookie(claimsCookie.Name, new System.Text.ASCIIEncoding().GetString(cookieValue));
SetCookie(request, cookie);
SetCookie(request, cookie.Name, cookie.Value);
}
}
}

// To support the TridionDocs module (should not require this when model-service is PCA plugin)
var conditions = claimStore.Get<string>(new Uri("taf:ish:userconditions"));
if (conditions != null)
{
SetCookie(request, "taf.ish.userconditions", Base64.Encode(conditions));
}
}

int attempt = 0;
Expand Down Expand Up @@ -291,13 +299,10 @@ private string PerformRequest(Uri requestUri)
private static void SetCookie(HttpWebRequest httpWebRequest, string name, string value)
{
// Quick-and-dirty way: just directly set the "Cookie" HTTP header
httpWebRequest.Headers.Add("Cookie", $"{name}={value}");
}

private static void SetCookie(HttpWebRequest httpWebRequest, Cookie cookie)
{
// Quick-and-dirty way: just directly set the "Cookie" HTTP header
httpWebRequest.Headers.Add("Cookie", $"{cookie}");
string headerValue = httpWebRequest.Headers["Cookie"] ?? "";
if (headerValue.Length > 0) headerValue += ";";
headerValue += $"{name}={value}";
httpWebRequest.Headers.Add("Cookie", headerValue);
}

private static string GetResponseBody(WebResponse webResponse)
Expand Down

0 comments on commit 14a7bdc

Please sign in to comment.