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#  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 javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
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 = "";
            // 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");
            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");
            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.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)
2155 reads
Always Learning