cancel
Showing results for 
Search instead for 
Did you mean: 

Ui5 oData Https Basic Auth

adtoth
Participant
0 Kudos

Hi Experts,

We are developing an UI5(Fiori Like app) packed with phonegap. We want to set up basic Authentication for the app to connect to the oData provider (its not an SAP backend, just an own provider). But I cant send out the user/pw in the header. even I'm using the following:


var url = "https://urltotheserver";

  var oModel = new sap.ui.model.odata.ODataModel(url, true, "User", "Pw");

Do you have any suggestions? I want to avoid using proxy.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

jmoors
Active Contributor
0 Kudos

Might be due to cross domain issue, if setting in the header as per Dennis suggestion, you might want to try setting the bWithCredentials flag.

JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

{boolean}bWithCredentials?(optional, experimental) true when user credentials are to be included in a cross-origin request. Please note that this works only if all requests are asynchronous.
adtoth
Participant
0 Kudos

Thanks Jason, it was helpful, I think it will work, but now I have the following error:  A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header

I've added the following to the code:


var headers ={};

        headers.Authorization = "Access-Control-Allow-Origin: *.netlife.hu";

        headers.setHeader = "X-Requested-With: JSONHttpRequest";

        headers.setHeader = "Content-type: application/x-www-form-urlencoded";

var oModel = new sap.ui.model.odata.ODataModel(url, true, "Usr", "Pw", headers, false, true);

But I get this error.

Do you have any ideas?

jmoors
Active Contributor
0 Kudos

Hi David,

I don't you can use wildcards when using credentials. If you are using phonegap, perhaps you can use the whitelist to get around the cross domain issues?

http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html

Regards,

Jason

adtoth
Participant
0 Kudos

Hi Jason,

I've solved it already just forget to reply.

Works perfectly from the phone.

Thank you

Answers (1)

Answers (1)

former_member182862
Active Contributor
0 Kudos

HI David

Have you try


oModel = new sap.ui.model.odata.ODataModel(url, true, null, null, {Authorization: "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="});

where QWxhZGRpbjpvcGVuIHNlc2FtZQ== is encoded username:password string

Thanks

-D