<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Ajax get request with basic authentication issue in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaa-p/590394#M136705</link>
    <description>&lt;P&gt;Hi &lt;A href="https://answers.sap.com/users/7022/sebastiankielhorn.html"&gt;Sebastian&lt;/A&gt; thanks for answer. In this case I have to add to neo-app.json the Identity Auth Service destination, right?&lt;/P&gt;
  &lt;P&gt;So then how can i do the AJAX call?&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jun 2018 08:35:56 GMT</pubDate>
    <dc:creator>e_giunta</dc:creator>
    <dc:date>2018-06-14T08:35:56Z</dc:date>
    <item>
      <title>Ajax get request with basic authentication issue</title>
      <link>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaq-p/590392</link>
      <description>&lt;P&gt;&lt;/P&gt;
  &lt;P&gt;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: // &amp;lt;tenant-id&amp;gt; .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: &lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;var username = "T000034";&lt;/P&gt;
  &lt;P&gt; var password = "012345"; &lt;/P&gt;
  &lt;P&gt;var url = "https://&amp;lt;tenant-id&amp;gt;.accounts.ondemand.com/service/scim/Users"; &lt;/P&gt;
  &lt;P&gt;$.ajax({ &lt;/P&gt;
  &lt;P&gt; url: url, &lt;/P&gt;
  &lt;P&gt; async: true, &lt;/P&gt;
  &lt;P&gt; type:'GET', &lt;/P&gt;
  &lt;P&gt; dataType: 'json', &lt;/P&gt;
  &lt;P&gt; beforeSend: function(xhr) { &lt;/P&gt;
  &lt;P&gt; xhr.setRequestHeader("Authorization", "Basic "+btoa(username+':'+password)); &lt;/P&gt;
  &lt;P&gt; }, &lt;/P&gt;
  &lt;P&gt; success: function(json){ console.log(json); }, &lt;/P&gt;
  &lt;P&gt; error: function(err) { console.log(err); } });&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;In the console after several attempts I get the following error: &lt;/P&gt;
  &lt;P&gt;"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 &amp;amp; origional-url = index.html &amp;amp; sap-ui-appCacheBuster = ..% 2F &amp;amp; sap-ui-xx-componentPreload = off: 1 Failed to load https: // &amp;lt;tenant-id &amp;gt; .accounts.ondemand.com / service / scim / Users: &lt;/P&gt;
  &lt;P&gt;Response for preflight has invalid HTTP status code 401. " &lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;P&gt;What's wrong? Any suggestions?&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 15:07:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaq-p/590392</guid>
      <dc:creator>e_giunta</dc:creator>
      <dc:date>2018-06-13T15:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Ajax get request with basic authentication issue</title>
      <link>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaa-p/590393#M136704</link>
      <description>&lt;P&gt;Hey Eugenio,&lt;/P&gt;
  &lt;P&gt;create a Destination for your purpose:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/158558-xxx.png" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Than you should be able to get all users from Identity Authentication Service.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Hope this helps!&lt;/P&gt;
  &lt;P&gt;Greetings,&lt;BR /&gt;Sebastian&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 16:10:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaa-p/590393#M136704</guid>
      <dc:creator>former_member221786</dc:creator>
      <dc:date>2018-06-13T16:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Ajax get request with basic authentication issue</title>
      <link>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaa-p/590394#M136705</link>
      <description>&lt;P&gt;Hi &lt;A href="https://answers.sap.com/users/7022/sebastiankielhorn.html"&gt;Sebastian&lt;/A&gt; thanks for answer. In this case I have to add to neo-app.json the Identity Auth Service destination, right?&lt;/P&gt;
  &lt;P&gt;So then how can i do the AJAX call?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 08:35:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaa-p/590394#M136705</guid>
      <dc:creator>e_giunta</dc:creator>
      <dc:date>2018-06-14T08:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Ajax get request with basic authentication issue</title>
      <link>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaa-p/590395#M136706</link>
      <description>&lt;P&gt;Hey Eugenio,&lt;/P&gt;
  &lt;P&gt;yes, you have to add the destination to you neo-app.json.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;...
{
	"path": "/service/scim/Users",
	"target": {
		"type": "destination",
		"name": "Users"
	},
	"description": "Users from Identity Authentication Service"
}
...&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I would suggest that you load the users in your manifest so that you don't have to make an seperate Ajax-Call:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;... 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
}
...&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Then you have the users in your JSONModel "userData"&lt;/P&gt;
  &lt;P&gt;Greetings,&lt;/P&gt;
  &lt;P&gt;Sebastian&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 08:53:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/ajax-get-request-with-basic-authentication-issue/qaa-p/590395#M136706</guid>
      <dc:creator>former_member221786</dc:creator>
      <dc:date>2018-06-14T08:53:18Z</dc:date>
    </item>
  </channel>
</rss>

