JWT Call (Secured Request):

URL:  http://example.com/Plugins/XcellenceIt.Plugin.Misc.NopRestApi/RemoteService/WebService.svc/SecureApi

  • Note: You do not need to pass the method name in URL when using SecureApi method, as the method name will be passed as a part of Pay load inside Secured Token.
  • Please refer to the example.html file included in the plug-in which has implemented the same using Java Script.
  • Request parameters always need to pass in body. (Version-2.7.0)



Request Parameters:


           var header = {
                   "alg": "HS256",
                   "typ": "JWT"
               };
               var tNow = KJUR.jws.IntDate.getNow();
               var tEnd = KJUR.jws.IntDate.getNow() + 60 * 5;
               // dynamically pass these data using a function
               var data = {
                   "appId": "Test",
                   "iat": tNow,
                   // iat (issued at time) should be set to time when request has been generated
                   "exp": tEnd,
                   // exp (expiration) should not be more than 5 minutes from now, this is to prevent Replay Attacks
                   "method": "Login",
                   "StoreId": "1",
                   "UserName": "admin@yourStore.com",
                   "apiSecretKey": "m110k118e115r106v100d108s113y97",
                   "Password": "admin",
                   "IsGuestCustomerId": "1"
               };

You need to send the parameters in data as per the requirement of method, also you need to change the URL as shown in below figure then only you will get the Response.

                       var targetEle = $("#data");
               $.ajax(
                   {
                       type: "POST",
                       // Please modify URL to point to your store API service
                       url: "http://localhost:15637/api/client/SecureApi",
                       // Use apiSecretKey(Generated API key)
                       data: '{"token":"' + encodedHeader + "." + encodedData + "." + signature + '"}',
                       contentType: "application/json; charset=utf-8",
                       dataType: "json",
                       success: function (data) {
                           targetEle.html("<pre>" + JSON.stringify(data, null, '\t') + "</pre>");
                       },
                       error: function (xhr, ajaxOptions, thrownError) {
                           targetEle.html("<pre>" + xhr.responseText + "</pre>");
                       }
                   });


Response:

{
 "indent_size": "4",
 "indent_char": " ",
 "max_preserve_newlines": "5",
 "preserve_newlines": true,
 "keep_array_indentation": false,
 "break_chained_methods": false,
 "indent_scripts": "normal",
 "brace_style": "collapse",
 "space_before_conditional": true,
 "unescape_strings": false,
 "jslint_happy": false,
 "end_with_newline": false,
 "wrap_line_length": "0",
 "indent_inner_html": false,
 "comma_first": false,
 "e4x": false
}