1

I am using MobileFirst 6.3. I am not able to call window.plugins.XXX (i want to use SSLcertificateChecker as XXX) . But the window.plugins is coming as undefined.

I want to include SSLCertificateChecker phonegap plugin from https://github.com/EddyVerbruggen/SSLCertificateChecker-PhoneGap-Plugin into my worklight project.

  1. First i tried iOS. I am adding manually all files.

  2. Added

    <feature name="SSLCertificateChecker">
        <param name="ios-package" value="SSLCertificateChecker" />
    </feature> in config.xml
  1. Add a dependency to Security.framework and also copied SSLCertificateChecker.* to plugin folder

But during implementation window.plugins comes undefined. Not a able to proceed.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
ajaykumar
  • 646
  • 7
  • 17

1 Answers1

0

It should work by following the same instructions I have provided in this answer, just adjusted to yours.

Note: The same warnings I have written there apply here as well. Namely: on each build performed in MobileFirst Studio the file cordova_plugins.js is being re-generated, thus you will lose the required changes that you will perform in this file, and you will be required to re-do them over and over again.

One possible solution to that is to upgrade to the soon-to-be released MobileFirst Platform Foundation 7.1, which introduces support for another class of application type - Cordova applications, with MobileFirst SDK integrated as a plug-in, thus enabling you to use Cordova Plug-man (or any other method) to install 3rd party plug-ins as you would in any Cordova-based application. Cordova Plug-man is not supported in releases prior to 7.1. Otherwise, you'll just have to find build hacks around it.


Studio

config.xml

  1. Add the plug-in declaration to your-app\iphone\native\config.xml

index.html

  1. Add the following to the header element:

    <script type="text/javascript" src="js/SSLCertificateChecker.js"></script>
    

SSLCertificateChecker.js

  1. Make sure to place the SSLCertificateChecker.js file in the your-app\common\js folder.

  2. Edit the file.

    • Add at the top:

      cordova.define("nl.x-services.plugins.SSLCertificateChecker", function(require, exports, module) {
      
    • Add at the bottom: });

Build

  1. Build the project in MobileFirst Studio and open it in Xcode

Xcode

  1. In Build Phases add the required Security.framework (but it will most likely already be there)

  2. Right-click on the project root folder, select "Add Files to..." and copy over the provided .h and .m files

  3. Navigate to native\www\default\worklight\cordova_plugins.js and add the following. This is also the file you will have to re-edit each time you make a build in MobileFirst Studio...

    {
        "file": "../js/SSLCertificateChecker.js",
        "id": "nl.x-services.plugins.SSLCertificateChecker",
        "clobbers": [
            "window.plugins.sslCertificateChecker"
        ]
    },
    
  4. Run on iOS Simulator or device.

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Thanks Idan for quick and prompt reply. This works pretty good now. Used your above approach for iOS. and android too. For android, added the same in cordova_plugins.js. But this cordova_plugins needs to be edited everytime we do a build as you mentioned. Thanks! – ajaykumar Aug 04 '15 at 10:53
  • I wrote a blog post with a possible solution: https://developer.ibm.com/mobilefirstplatform/2015/08/03/integrating-3rd-party-cordova-plug-ins/ – Idan Adar Aug 04 '15 at 11:14
  • Your post will definitely help others as well during integration. Thanks for taking out your time for writing this. – ajaykumar Aug 04 '15 at 12:00
  • Hi Idan, We are facing a problem during deployment. As we are encrypting the web resources by setting the flag .. in application-descriptor, so we cannot edit the cordova_plugin.js .. We also need to encrypt the resources along with this plugin . Is there any tweak for this – ajaykumar Aug 05 '15 at 13:29
  • I'm sorry, but in this case I do not believe it will be possible to edit this file since it is inside a encrypted .zip file and you thus cannot reach it post-build. – Idan Adar Aug 05 '15 at 13:53
  • oopss! It is critical for us at this time to provide both solutions. Is their any other approach or any other way in Mobile First 6.3 to include this plugin for SSL pinning or any other cordova plugin for SSL pinning in MobileFirst 6.3. Can http://plugins.telerik.com/cordova/plugin/secure-http be configured in MobileFirst 6.3 however for this i could not see any manual installation also. Pls guide. – ajaykumar Aug 05 '15 at 14:06
  • There will be the same issue. – Idan Adar Aug 05 '15 at 14:13
  • As mentioned in the blost post, this is not well supported and the ant task is a workaround. Addition of the encryption is a problem. You can maybe open a PMR, but I am unclear on the support level here. Not sure 3rd party plugins are supported. – Idan Adar Aug 05 '15 at 14:17
  • I have implemented this by changing the approach. I did this by removing the plugin js file and picked only cordova.exec code and its related content from js and called within the page instead of the module export mechanism. Thus no need to override the cordova_plugins.js file as now there is a direct call to native code through application. Now plugin and encryption of web resources both works pretty gr8. – ajaykumar Aug 06 '15 at 11:55