Client Example: With Final URI
The following shows how to create a client for handling SAML protocol with a final URI:
Copy
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form.HasKeys() && Request.Form.Keys.Cast<string>().Any(x => x == "ticket"))
{
var userId = Request.Form["userId"];
var nameQualifier = Request.Form["nameQualifier"];
var ticket = Request.Form["ticket"];
var result = Request.Form["result"];
var statusCode = Request.Form["statusCode"];
var statusSubCode = Request.Form["statusSubCode"];
var statusMessage = Request.Form["statusMessage"];
var clientId = ConfigurationManager.AppSettings["clientId"];
string baseuri = ConfigurationManager.AppSettings["apiBaseUri"];
// Login to CherwellApi
ServiceApi service = new ServiceApi(baseuri);
TokenResponse tokenResponse = service.ServiceToken("password", clientId, string.Empty,
userId, ticket, string.Empty,
"SAML");
// Create search results request
SearchResultsRequest searchResults = new SearchResultsRequest
{
BusObId = "6dd53665c0c24cab86870a21cf6434ae"
};
// create new instance of the Searches operations
SearchesApi searches = new SearchesApi(baseuri);
// Setup the default header for authorization
searches.Configuration.DefaultHeader.Add("Authorization", "Bearer " + tokenResponse.AccessToken);
SearchResultsResponse response = searches.SearchesGetSearchResultsAdHocV1(searchResults);
// display results indicating success
TotalRows.Text = "There are " + response.TotalRows + " incidents";
var dict = Request.QueryString.Keys.Cast<string>().ToDictionary(key => key, key => Request.QueryString[key]);
var json = new JavaScriptSerializer().Serialize(dict);
QueryParameters.Text = json;
}
else
{
// should be known if a user is attempting a SAML login to your system
// make SAML login request to the CherwellApi
Response.Redirect(ConfigurationManager.AppSettings["apiSamlLoginUri"]);
}
}