cancel
Showing results for 
Search instead for 
Did you mean: 

How to Gateway Authentication using SAPUI5?

former_member184238
Participant
0 Kudos

Hi,

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) {

  1.      jQuery.sap.require("sap.ui.model.odata.datajs");
  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.

Thanks&Regards

Sridevi

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member258330
Participant
0 Kudos

To avoid User and Passowrd Autentication, you need to go SICF tcode and find the service there. In it, put user and Password that will be used. Only that.

I Used it always for SAPUI5 app and WebDynpro App.

Att.

Former Member
0 Kudos

Hi Sridevi,


I would do it this way :


var sUrl = "http://xxxx:8000/sap/opu/odata/sap/ZPROJ_APPRAISAL_FORM_SRV";

  var oModel = new sap.ui.model.odata.ODataModel(sUrl, true, username, password);

  sap.ui.core.BusyIndicator.show(0);// shows a busy indicator while loading the data

  oModel.read(

  "/", // the path : would put "/" or "" if it doesn't work

  null, // context : null by default

  [], // urlParameters : empty array as we don't need any here

  true, // asynchronous request : true

  function(oData, response) { // onSuccess function called when everything is ok

  // handle your data here and don't forget the hide the busyIndicator

  sap.ui.core.BusyIndicator.hide();

  },

  function(oError) { // onError function called when there was an error

  // Here you can handle the error you got, for example, you can show a dialog with the error msg

  jQuery.sap.require("sap.ui.commons.MessageBox");

  sap.ui.commons.MessageBox.show(

  oError.message,

  sap.ui.commons.MessageBox.Icon.ERROR,

  "Name of your App"

  );

  // Finally hide the busyIndicator

  sap.ui.core.BusyIndicator.hide();

  }

  );

For more infos about the sap.ui.model.odata.ODataModel constructor and the read() function you can check this link : OpenUI5 SDK - Demo Kit.

Hope this helps!

Regards,

Mehdi

former_member191810
Participant
0 Kudos

Hi.

1. Have you tried changing OData URL from http:// to https://?. If it fails, please try adding:

var sServiceUrl = "proxy/https/...


2. Why don't try with POST method?

Former Member
0 Kudos

Hi Raul,

As I understand that for using Proxy with a URL, my server should support Reverse Proxy. Unfortunatly my server is not supporting reverse proxy so I cant use this method. And I am using GET because I have to get some data from the Server.

Fahad

RoyF
Advisor
Advisor
0 Kudos

Hi Sridevi

sending the user/password this way is unsecure , as it passes in the url. it's rather a testing feature.

If you are working from the browser , then you can leave user/password out, the browser will get 401 status code and will automatically open the browser authentication dialog box.

then your user can enter his credentials and  be authenticated.

From app code you don't need to do anything special for this to work.

BTW, this kind of questions on SAP UI5 is better asked in SAPUI5 comunity forum

Best Regards

Roy

Former Member
0 Kudos

Hi,

I have the same problem, how can we avoind the authentication Pop up.

Best regards.

Fahad

former_member184238
Participant
0 Kudos

Hi,

I didn't find that solution . 

When we are using Basic Authentication or merge authentication the browser send that popup by default. If we want to prevent that popup we have to change the authentication method in back end.

Thanks&Regards

Sridevi

RoyF
Advisor
Advisor
0 Kudos

Hi Sridevi,

When the browser gets 401 it will pop up the authentication user/pass dialog

and any client script can't help you on that, as the browser enforce that.

To avoid that you should consider having some deployment on the server, like server form login.

Fiori had their application deployed on the server and then the login could rely on server side code.

Best Regards

Roy

Former Member
0 Kudos

Hi Roy,

Even if the user id and password is right which means I am not getting 401, still browser is showing pop up.

Fahad