SCORM Cloud + Angular 6

445 views Asked by At

I am establishing the communication between my angular application and scorm cloud service offered by rustici software. I have had follow the documentation, so far I get:

<rsp stat="fail">
    <err code="104" msg="The signature attached to the call does not match the signature generated on the server."/>
</rsp>

Here it is an example of the URL: http://cloud.scorm.com/api?method=rustici.registration.launch&appid=79V4XI0MTG&regid=1551368365666&redirecturl=closer&ts=20190228153925&sig=d6edc93e854d8e8276156759a84cc344

Which is obvious related to the way I am generating the signature parameter using the MD5 function, as stated in the documentation.

I have a hunch this problem is related to the way I generate the time parameter (ts), I do it so

TS: string = moment().add(5, 'hours').format('YYYYMMDDHHmmss');

If someone have achived this, would you be able to spare me some time.

1

There are 1 answers

0
Luis Pérez On

I manage to generate right md5 strings that match server side generated md5 using the following functions.

Documentation is explicit about sorting the parameters, so here its a function to do it.

    sortByKey(params) {
        let sortedObj = {}
        Object.keys(params).sort().forEach((key) => sortedObj[key] = params[key])
        return sortedObj;
    }

Later you have to concatenate and prepend the SECRET_KEY and finally apply md5 function, like this...

    getSig(params, secretKey) {
        let sortedParams = this.sortByKey(params);
        let concatenated = '';
        Object.keys(sortedParams).forEach((key) => {
            concatenated += (key + sortedParams[key]);
        });

        let sigString = secretKey + concatenated;
        return md5(sigString);
    }

Assuming you have the next parameters, the process goes as follows

// 1. For the given parameters, you have to sort them
method=rustici.registration.launch
regid=1551362579253
ts=20190228140259 
appid=79V4XI0MTG 
redirecturl=blank

// 2. The sorting results in
appid=79V4XI0MTG
method=rustici.registration.launch
redirecturl=blank
regid=1551362579253
ts=20190228140259

Note that ts param is in the format (YYYYMMDDHHmmss). Ex.: 20190228174550

// 3. Concatenate all sorted params
appid79V4XI0MTGmethodrustici.registration.launchredirecturlblankregid1551362579253ts20190228140259

// 4. Then prepend the secret_key to your concatenation
secret_key + appid79V4XI0MTGmethodrustici.registration.launchredirecturlblankregid1551362579253ts20190228140259

// 5. Finally apply md5 function
const sig = md5(secret_key + appid79V4XI0MTGmethodrustici.registration.launchredirecturlblankregid1551362579253ts20190228140259)

Construct the URL to make the request and you should be good to go.