Tuesday, October 6, 2009

How to set basic authentication for php in flex 4

I have listed down the steps which will help you to use basic authentication for php services using Zend in FlashBuilder4

1. Have a function called initAcl($acl) in the php service similar to the one given below. All the functions inside the service which need authentication should be mentioned in this function( i.e., initAcl)

function initAcl(Zend_Acl $acl) {
$acl->allow('role1', null, 'function1');
$acl->allow('role2', null, array('function1', 'function2'));
return true;

Please find a sample service here

2. Have a security.xml file which specifies the user roles and has user name and passwords stored in it. Sample contents of the xml file is given below.

<role id='admin'>
<user name='user1' password='pwd'/>
<role id='hr'>
<user name='user2' password='pwd2'/>

3. Security.xml file can be placed anywhere (placing it outside the webroot is recommended. ) The path has to be specified in the gateway.php file . Also a small code has to be added in the gateway.php file as given below.

$auth = new Zend_Amf_Adobe_Auth("C:\wamp\security.xml");

Refer to this gateway.php file to know where exactly should the above code be added

4. below code has to be added in the mxml, where serviceName1 is the name of the service created.

Support for basic authentication in php is added in Beta 2 release of FlashBuilder 4.

1 comment:

  1. thank you so much for this info...
    so the scenario for making authenicated call is to store user info in object and use it whenever the service call is needed?

    Is there any detailed tutorial on this? Or sample app would be the best..

    Yhank you again