Pearson
Always Learning

The following is freely available sample code in a few commonly used software languages showing how to send a request to the LearningStudio legacy Inbound SSO service.

Java  Python  Ruby  PHP  C#  VB.net  Perl

This code sample requires JDK 6 or higher.

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.util.Date;
import java.io.*;
import java.net.*;
 
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.HttpsURLConnection;
 
import org.apache.commons.codec.binary.Base64;
 
/**
 * Very basic class that demonstrates how to make a Direct Course Launch (DCL) request
 * to the LearningStudio Inbound SSO service for a given user and course section
 */
public class InboundSSO {
 
        public static void main ( final String [] args ) throws Exception
	{
            // Setup Variables
            String clientString= "<client_string>";
            String systemID = "<system_id>";
            String sharedSecret = "<shared_secret>";
            String loginID = "<login_id>";
            String callNumber = "<call_number>";
            String host = "https://custom.ws.ecollege.com";
 
            // Get the UTC Date Timestamp
            Date now = new Date();
            DateFormat gmtFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            TimeZone gmtTime = TimeZone.getTimeZone("GMT");
            gmtFormat.setTimeZone(gmtTime);
            String timestamp = gmtFormat.format(now)+ "Z";
            System.out.println( timestamp );
 
            // Setup the Secret Key; used to generate the MAC
            String algorithmKey = timestamp + sharedSecret;
 
            // Setup the route and query string portion of the request
            String route = String.format("/sso/%s/tokenurl.rails?u=%s&amp;c=%s", clientString, loginID, callNumber);
 
            // Generate the MAC
            SecretKeySpec sks = new SecretKeySpec(algorithmKey.getBytes("UTF-8"), "HmacSHA1");
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(sks);
            byte[] hashBytes = mac.doFinal(route.getBytes("UTF-8"));
 
            // Convert the MAC to a Base64 string and remove the new line Base64 always adds
            String hmac = Base64.encodeBase64String(hashBytes);
            hmac = hmac.replaceAll("\r\n", "");
            System.out.println( hmac );
 
            // Setup the HTTP Request
            URL sso = new URL(host + route);
            HttpsURLConnection httpConn = (HttpsURLConnection)sso.openConnection();            
            httpConn.setRequestMethod("GET");
            httpConn.setRequestProperty("ECLG_SSO-SystemID", systemID);
            httpConn.setRequestProperty("ECLG_SSO-Timestamp", timestamp);
            httpConn.setRequestProperty("ECLG_SSO-MAC", hmac);
 
            // Send the HTTP Request to the LearningStudio Inbound SSO Service
            InputStreamReader reader = new InputStreamReader(httpConn.getInputStream());
            BufferedReader in = new BufferedReader(reader);
 
            // Get the Response
            String inputLine;
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);
 
            in.close();
            httpConn.disconnect();
        }
}
</call_number></login_id></shared_secret></system_id></client_string>
2497 reads
Always Learning
Pearson