WCF Data Services 5 Authentication datajs and phonegap

Sep 19, 2012 at 2:03 AM

I have an WCF Data Service in .NET and I am consuming this service with datajs in Phonegap. I am trying to implement authentication as decribed here: http://goo.gl/0xQvC, and sending credentials with OData.read method (datajs), but when I read credentials with HttpContext.Current.Request.Headers["Authorization"], I found they are empty. What I am doing wrong?

Service Code:

[ServiceBehavior( IncludeExceptionDetailInFaults = true )]
    public class TeyunaDataService : DataService< Meteora.TeyunaServices.Models.TeyunaContext >
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("Clientes", EntitySetRights.AllRead );
            config.SetEntitySetAccessRule("Transacciones", EntitySetRights.All);

            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            config.UseVerboseErrors = true;
        }

        public TeyunaDataService()
        {
            this.ProcessingPipeline.ProcessingRequest += new EventHandler<DataServiceProcessingPipelineEventArgs>(OnRequest);
        }

        void OnRequest(object sender, DataServiceProcessingPipelineEventArgs e)
        {
            var auth = HttpContext.Current.Request.Headers["Authorization"]; //This is empty                
        }
    }
}

Javascript Client code:

OData.read({ requestUri: url, user: "pruebausr", password: "passprb" },    
    function (data, request) {
        // ... code to procesing data (It works fine)

    },  function(err) {
            $.mobile.hidePageLoadingMsg();
            alert("Error al obtener clientes. " + err.message);
    }
);
Service web.config here: https://gist.github.com/3746043

I am using: WCF Data Services 5. IIS Express.

Sep 24, 2012 at 7:17 PM
Edited Sep 24, 2012 at 7:18 PM

Hi Japonte,

   Can you share a network trace of the request and the response?  By the way, I noticed in your web.config that you are using forms authentication instead of basic http authentication (which uses the Authorizaton header directly).  That may be the reason why the header no longer has the value that you expect because ASP.Net form authentication module has preprocessed the result to create an object that represents the user principal.  You can find more details on how forms authentication work here http://msdn.microsoft.com/en-us/library/7t6b43z4(v=VS.100).aspx.

Regards,

Alex Trigo.