Skip to content

Instantly share code, notes, and snippets.

@michaelkc
Created December 5, 2014 13:46
Show Gist options
  • Save michaelkc/f797866d8e801c9b4c5b to your computer and use it in GitHub Desktop.
Save michaelkc/f797866d8e801c9b4c5b to your computer and use it in GitHub Desktop.
var wsTrustClient = new WsTrustClient("devtest-idp.vfltest.dk");
var audience = "https://devtest-ws-dli.vfltest.dk/UserServices/";
var token = (GenericXmlSecurityToken)wsTrustClient.GetSecurityToken(audience, "<service account>", "<service account password>");
var tokenXml = token.TokenXml.OuterXml;
var encodedToken = new DeflatedSamlTokenHeaderEncoder().Encode(tokenXml);
Console.WriteLine(tokenXml);
Console.WriteLine(encodedToken);
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://devtest-ws-dli.vfltest.dk/UserServices/api/users/mac/");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", encodedToken);
HttpResponseMessage response = client.GetAsync("").Result;
string content = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(response.StatusCode);
Console.WriteLine(content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment