cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Ajax get request with basic authentication issue

e_giunta
Participant
0 Likes
2,192

I have to develop a sapui5 application with the sap web ide: the user must be enabled to perform CRUD operations on the SAP Cloud Platform Identity Authentication (URL: "https: // <tenant-id> .accounts.ondemand.com / service / scim / Users ") via app and manage users. First I tested it on Postman successfully. Later I tried to make an AJAX call (directly on the controller.js) to get a json with all the users already registered on the SAP Identity Authentication. This is the code:

var username = "T000034";

var password = "012345";

var url = "https://<tenant-id>.accounts.ondemand.com/service/scim/Users";

$.ajax({

url: url,

async: true,

type:'GET',

dataType: 'json',

beforeSend: function(xhr) {

xhr.setRequestHeader("Authorization", "Basic "+btoa(username+':'+password));

},

success: function(json){ console.log(json); },

error: function(err) { console.log(err); } });

In the console after several attempts I get the following error:

"Failed to load resource: the server responded with a status of 401 (Unauthorized) extension_runnable_file.html? hc_orionpath =% 2Fs0*********03trial% 24s0*********03-OrionContent% 2Faaaaaa & origional-url = index.html & sap-ui-appCacheBuster = ..% 2F & sap-ui-xx-componentPreload = off: 1 Failed to load https: // <tenant-id > .accounts.ondemand.com / service / scim / Users:

Response for preflight has invalid HTTP status code 401. "


What's wrong? Any suggestions?

View Entire Topic
former_member221786
Active Participant

Hey Eugenio,

create a Destination for your purpose:

Than you should be able to get all users from Identity Authentication Service.

Hope this helps!

Greetings,
Sebastian

e_giunta
Participant
0 Likes

Hi Sebastian thanks for answer. In this case I have to add to neo-app.json the Identity Auth Service destination, right?

So then how can i do the AJAX call?

former_member221786
Active Participant

Hey Eugenio,

yes, you have to add the destination to you neo-app.json.

...
{
	"path": "/service/scim/Users",
	"target": {
		"type": "destination",
		"name": "Users"
	},
	"description": "Users from Identity Authentication Service"
}
...

I would suggest that you load the users in your manifest so that you don't have to make an seperate Ajax-Call:

... service...
...
"userService": {
	"uri": "/service/scim/Users",
	"type": "JSON",
	"settings": {
		"odataVersion": "2.0",
		"localUri": "localService/metadata.xml"
	}
}
...

... models ...
...
"userData": {
	"dataSource": "userService",
	"type": "sap.ui.model.json.JSONModel",
	"preload": true
}
...

Then you have the users in your JSONModel "userData"

Greetings,

Sebastian