Link to home
Start Free TrialLog in
Avatar of joduk777
joduk777

asked on

Help Converting PHP include_once to JQuery Post with inner class reference.

Hello, I am trying to perform single sign on using Jquery using a 3rd party SSO tool.  Unfortunately, the publisher (Wizkunde) only provides an example in PHP which I have included below.  I took my best shot at converting this to Jquery, but am stuck on the postData["key"] value.  Can someone please help?

This is the example published in the wizkunde help files:
<?php
include_once('Hmac.php');
$postData = array(
'email' => 'ron@wizkunde.nl',
'firstname' => 'Ron',
'lastname' => 'van der Molen',
'delivery' => array(
'firstname' => 'Ron',
'lastname' => 'van der Molen'
),
'invoice' => array(
'firstname' => 'Ron',
'lastname' => 'van der Molen'
)
);
$when = time();
$uri = 'http://<mydomain>/sso/login/login';

$hmacModel = new Wizkunde_Hmac('geheimesleutel', '300');
$hmacModel->setWhen(time());
$hmacModel->setUri($uri);

$postData['uri'] = $uri;
$postData['when'] = $when;
$postData['key'] = $hmacModel->createHash($postData);

header('Location: ' . $uri . '?' . http_build_query($postData));
?>

Open in new window



Here is the jquery I have pieced together:

<asp:Button ID="SSOButton" runat="server" Text="Button" />

    <script>
        $('#SSOButton').click( function() {

            var postDataArray = { "email": "ron@wizkunde.nl", "firstname": "Ron", "lastname": "van der Molen", "delivery": array = { "firstname": "Ron", "lastname": "van der Molen" }, "invoice": array = { "firstname": "Ron", "lastname": "van der Molen" } };
            var postData= jQuery.param(postDataArray);

            var CurrentTime = new Date($.now())
            var uri = "http://mydomain.com/b2bmagento/sso/login/login"

            postData["uri"] = uri
            postData["when"] = CurrentTime

            // It looks like I need to set the postData["key"] equal to the return value of createHash which exists in a new class Wizkunde_Hmac located at the uri.  I have no idea how to do this.

            postData["key"] = ""
               
            $.post(uri, postData, "json");

       }) 
</script>

Open in new window

Avatar of Rob
Rob
Flag of Australia image

Sorry if I've missed something but you can't convert PHP to jQuery as jQuery can only run on the client, whilst PHP only runs on the server.  Are you using ASP/c#/VB.net?  As that is what you'll need to convert the PHP to.
Avatar of joduk777
joduk777

ASKER

The code provided in PHP is a client side POST for Single Sign on to a remote server.  The publisher of the product has only provided examples of the client side request in PHP which I copied here.  My interest isn't to translate PHP to jquery, but to create a client side POST using Jquery that achieves the same as the documentation that was provided in PHP.  

As a last resort, I am open to making a POST in Jquery with embedded PHP if that is the only way to achieve this outcome, but I am thinking this can all be done in Jquery.  Thanks for the help.
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Slick has just reminded me that attempting to do this with the browser is counter intuitive because the user has access to everything in their browser. The reason we use php or asp for authentication it's it adds another layer of security that the user cannot see.
Wizkunde...

The first hint that you are trying to work with a piece of junk is the lack of support and apparently defective documentation that led you to believe you had code that would run on a client.

Security is not somwething to screw around with, if you do not have skills at a level to understand the code, then how are you going to respond when a hacker finds a hole.  Either use code you write yourself and understand or hire a professional with security experience to do the work and support it.

Cd&