This document contains examples of typical use cases for the Single Sign-On API. These examples demonstrate calls to the SOAP interface and are provided as is.
Full API documentation is available here.
The following examples demonstrate calls to the Single Sign-On API in C#.
These examples assume the use of a generated XML web service client. To generate such a client, a tool such as WSDL.exe can be used. A detailed description on this tool can be found on MSDN, but all you will need to do is point it at your site's Single Sign-On API endpoint. A detailed description of how to generate a web service client is beyond the scope of this document.
// Instantiate the web service proxy
iSAMSSingleSignOnAPI service = new iSAMSSingleSignOnAPI();
// User to authenticate with
string username = "Testing";
// Corresponding password to authenticate with
string password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);
string token = authenticationResponse.Message;
// Create a new LoginCustomer instance containing the new customer's details
LoginCustomer customer = new LoginCustomer {
Email = "[email protected]",
Password = "fourscoreand7",
FirstName = "Abraham",
LastName = "Lincoln",
InterestGroups = new string[] { "Emancipation" }
};
// Call the web service to create the customer
CustomerLoginResponse createResponse =
service.Create(token, customer);
// Check for success and respond accordingly
if (createResponse.Success) {
Console.WriteLine("ID: {0}", createResponse.Customer.ID);
// Output: "ID: Vsk6JBlJj3sNwKfGDY2w4w=="
} else {
Console.WriteLine("Failed to create customer {0}.", customer.Email);
}
// Instantiate the web service proxy iSAMSSingleSignOnAPI service = new iSAMSSingleSignOnAPI(); // User to authenticate with string username = "Testing"; // Corresponding password to authenticate with string password = "Sup94zex"; // Authenticate ApiResponse authenticationResponse = service.Authenticate(username, password); string token = authenticationResponse.Message; // Customer credentials string customerEmail = "[email protected]"; string customerPassword = "fourscoreand7"; // Call the web service to log the customer in CustomerLoginResponse loginResponse = service.Login(token, customerEmail, customerPassword); // Check if the login succeeded if (loginResponse.Success) { // Customer details are correct and customer has been validated. Console.WriteLine(loginResponse.Customer.ID); // Output: "61Nw9xiBhidVuBxatswjwQ==" } else { // Incorrect customer login details. The login has failed Console.WriteLine("Failed to log customer in."); }
// Instantiate the web service proxy
iSAMSSingleSignOnAPI service = new iSAMSSingleSignOnAPI();
// User to authenticate with
string username = "Testing";
// Corresponding password to authenticate with
string password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);
string token = authenticationResponse.Message;
// An encrypted customer ID is required to retrieve a customer's details. This
// is obtained through the Create() or Login() methods.
string customerID = "qLOi5H8lZ5YiUIBCh0Nh2A==";
// Retrieve customer data from the web service
CustomerLoginResponse retrieveResponse =
service.Retrieve(token, customerID);
// Process the retrieved customer details
LoginCustomer retrievedCustomer = retrieveResponse.Customer;
if (retrieveResponse.Success) {
Console.WriteLine("Email: {0}", retrievedCustomer.Email);
Console.WriteLine("FirstName: {0}", retrievedCustomer.FirstName);
Console.WriteLine(String.Join(",", retrievedCustomer.InterestGroups));
} else {
Console.WriteLine("Failed to retrieve customer: {0}.", customerID);
}
// Instantiate the web service proxy
iSAMSSingleSignOnAPI service = new iSAMSSingleSignOnAPI();
// User to authenticate with
string username = "Testing";
// Corresponding password to authenticate with
string password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);
string token = authenticationResponse.Message;
// An encrypted customer ID is required to subscribe a customer to an
// interest group. This is obtained through the Create() or Login() methods
string customerID = "LlxPGvjw94VwY102vJW2nA==";
// Call web service to subscribe the customer to an interest group
CustomerLoginResponse response =
service.Subscribe(token, customerID, "Amendments");
// Check for success and process result
if (response.Success) {
Console.WriteLine(String.Join(",", response.Customer.InterestGroups));
// Output: "Emancipation,Amendments"
} else {
Console.WriteLine("Failed to subscribe to interest group.");
}
// Instantiate the web service proxy
iSAMSSingleSignOnAPI service = new iSAMSSingleSignOnAPI();
// User to authenticate with
string username = "Testing";
// Corresponding password to authenticate with
string password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.Authenticate(username, password);
string token = authenticationResponse.Message;
// An encrypted customer ID is required to unsubscribe a customer from an
// interest group. This is obtained through the Create() or Login() methods
string customerID = "gp+nkltxJ9tIn3hpj8ft/Q==";
// Call web service to unsubscribe the customer from an interest group
CustomerLoginResponse response =
service.Unsubscribe(token, customerID, "Emancipation");
// Check for success and process result
if (response.Success) {
Console.WriteLine(String.Join(",", response.Customer.InterestGroups));
// Output: "Constitutional Amendments"
} else {
Console.WriteLine("Failed to unsubscribe from interest group.");
}