Skip to Content
Sep 13, 2013 at 07:54 AM

How to Gateway Authentication using SAPUI5?



I am doing sample gateway application using sapui5 . In that I am passing Username and Password dynamically using Login form.

Previously I am using the below code to set the model.

var oModel = new sap.ui.model.odata.ODataModel(

"http://xxxx:8000/sap/opu/odata/sap/ZPROJ_APPRAISAL_FORM_SRV", true, myusername, mypassword);

In that I am passing username and password dynamically.But I am not able to get the error when I enter wrong Inputs.Next I changed my code like below to catch the error message when I enter wrong Input.

login : function(oEvent) {

  2. var serviceURI = "http://xxxx:8000/sap/opu/odata/sap/ZPROJ_APPRAISAL_FORM_SRV";
  3. var username = sap.ui.getCore().getControl("userid") .getValue();
  4. var password = sap.ui.getCore().getControl("pwdid") .getValue();
  5. var request = {
  6. headers : {
  7. "X-Requested-With" : "XMLHttpRequest",
  8. "Content-Type" : "application/atom+xml",
  9. "DataServiceVersion" : "2.0",
  10. "X-CSRF-Token" : "Fetch"
  11. },
  12. requestUri : serviceURI,
  13. method : "GET",
  14. user : username,
  15. password : password
  16. };
  17. OData.request(request, function(data) {
  18. alert("success");
  19. }, function(err) {
  20. alert('Error Code:'+ err.response.statusCode);
  21. });


Here, when I enter valid inputs it goes to server and fetch the data. But when I enter wrong inputs again it is displaying Gateway service Popup with username and Password on the login form. When i click on cancel button of that Popup I am getting the error code which is in error function.

Please find the below Images

Getting Login Screen like this when i enter wrong inputs to the service.

After click on Cancel Button I am getting the Error code like below

Now I want to prevent that POPUP which is coming before error message.

Please help me to solve this issue.




loginform.jpg (28.6 kB)
errorcode.jpg (21.5 kB)