使用android / ios中的Symfony进行身份验证

I have a PHP Symfony web application which uses form based authentication now I am try to access some of its data in Android native app. From my android native app first I need to authenticate which I am having trouble authenticating pragmatically against Symfony app.

After lot of debugging what I found is when I try to authenticate against Symfony from Android it always seems to redirect to login page which I was able to capture through Fiddler proxy. I have also tried changing security.yml to use basic auth for mobile but nothing seems to work.

Below is my security.yml

security:
acl:
    connection: default

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

encoders:
    Docova\DocovaBundle\Entity\UserAccounts: plaintext
providers:
    chain_provider:
        chain:
            providers: [docova_second, docova_main]
    docova_main:
        id: docova.security.user.provider
    docova_second:
       entity: { class: DocovaBundle:UserAccounts}
firewalls:
    login:
        pattern:  ^/demo/secured/login$
        security: false

    docova:
        pattern:     /.*
        form_login:
            login_path: %d.login_path%
            check_path: %d.check_path%
            default_target_path: %d.default_target_path%
            success_handler: docova.security.authentication.success_handler
        logout:
            path:   /Docova/logout
            target: /Docova
        anonymous: true
        security: true
        docova: true

    mobile:
        pattern:     /.*
        http_basic: ~

access_control:
    - { path: /Docova/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/Docova, roles: ROLE_USER }

Here is the java code used by android to authenticate using basic:

/*
 * Get input stream from requested url
 */
public InputStream getInputStream(String urlPath){
    InputStream is=null;
    HttpURLConnection httpConn = null;
    FileOutputStream fos=null;

        try {

        int responseCode;
            String responseContentType;
            urlPath = "http://linux.dlitools.com/Symfony/web/app.php/Docova/mobileAuthenticateUser.xml";
            URL url = new URL(urlPath);
            httpConn = (HttpURLConnection) url.openConnection();
            httpConn.setRequestMethod("GET");
            httpConn.setDoInput(true);

            //prepare login string for basic auth
            String authString = username + ":" + password;
            // encode base 64 for basic auth
            String encoded=Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP);

            //set required properties for basic
            httpConn.setRequestProperty("Authorization", "Basic " + encoded);
            httpConn.setDoOutput(true);
            httpConn.setRequestProperty("Content-type", "text/xml"); 

            //open connection and get input stream
            httpConn.connect(); 
            is = httpConn.getInputStream();

            int lenghtOfFile = httpConn.getContentLength(); 
            responseContentType=httpConn.getContentType(); //***** need to find out more on this ******
            responseCode= httpConn.getResponseCode();

            if (!responseContentType.equals("text/xml") ){
                is=null;
            }

            Log.d(TAG, "The response Content Type is: " + responseContentType);
            Log.d(TAG, "The response code is: " + responseCode);
            Log.d(TAG, "getXmlInputStream() : END");
    }catch(Exception e){
            errorMsg=errorMsg+"

 Exception happend: "+" " +  e.toString() ;

        }

    return is;
}

I would appreciate if someone can point me in the right direction ... is there a setting that need to be turned on in Symfony security or some config which will allow basic authentication for mobile apps such as Android.

Thnx.

In the docs there is a thorough example of implementing WSSE as a custom auth provider. Take a look at Custom Authentication Provider. I have implemented this in the past, but I found implementing the FOSOAuthServerBundle more convenient. But give either one a shot, they should both do what you want to do.