<?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: Authentication issues when using RESTful api C# for 4.2 BusinessObjects in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaa-p/13852241#M4881613</link>
    <description>&lt;P&gt;I found the issue. I noticed when replying previously that the 401 response included a referece to port 8080.&lt;/P&gt;&lt;P&gt;i.e this part:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Access-Control-Allow-Origin: http://servername:8080&lt;/LI-CODE&gt;&lt;P&gt;I tried the below to see if I got a response in the browser:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;http://servername:8080/biprws/logon/long&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;It returned the same response when using 6405.&lt;/P&gt;&lt;P&gt;Changing the port to 8080 in the baseurl fixed the issue and returns the token. There must be a port redirection happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Sep 2024 06:19:35 GMT</pubDate>
    <dc:creator>uhs</dc:creator>
    <dc:date>2024-09-03T06:19:35Z</dc:date>
    <item>
      <title>Authentication issues when using RESTful api C# for 4.2 BusinessObjects</title>
      <link>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaq-p/13851513</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I am trying to connect to the RESTful api using c#, but having some difficulties getting the syntax correct.&lt;/P&gt;&lt;P&gt;I'm currently receiving a 401 response error. I am an administrator and the RESTful base url is setup.&lt;/P&gt;&lt;P&gt;I have the required response body:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;attrs xmlns="http://www.sap.com/rws/bip"&amp;gt;
&amp;lt;attr name="password" type="string"/&amp;gt;
&amp;lt;attr name="clientType" type="string"/&amp;gt;
&amp;lt;attr name="auth" type="string" possibilities="secEnterprise,secLDAP,secWinAD,secSAPR3"&amp;gt;secEnterprise&amp;lt;/attr&amp;gt;
&amp;lt;attr name="userName" type="string"/&amp;gt;
&amp;lt;/attrs&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;The C# code I'm using is:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        public async Task&amp;lt;string&amp;gt; AuthenticateAsync()
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {
                // Construct the XML request body
                var requestBody = $@"
                    &amp;lt;attrs xmlns=""http://www.sap.com/rws/bip""&amp;gt; 
                        &amp;lt;attr name=""password"" type=""string""&amp;gt;{password}&amp;lt;/attr&amp;gt;
                        &amp;lt;attr name=""clientType"" type=""string""&amp;gt;SDK&amp;lt;/attr&amp;gt;
                        &amp;lt;attr name=""auth"" type=""string"" possibilities=""secEnterprise,secLDAP,secWinAD,secSAPR3""&amp;gt;secWinAD&amp;lt;/attr&amp;gt;
                        &amp;lt;attr name=""userName"" type=""string""&amp;gt;{username}&amp;lt;/attr&amp;gt;
                    &amp;lt;/attrs&amp;gt;";

                StringContent content = new StringContent(requestBody, System.Text.Encoding.UTF8, "application/xml");
             
                var response = await client.PostAsync($"{baseUrl}/logon/long", content);
                GD.Print("response", response);

                if (response.IsSuccessStatusCode)
                {
                    var responseData = await response.Content.ReadAsStringAsync();
                    var xmlDoc = new System.Xml.XmlDocument();
                    xmlDoc.LoadXml(responseData);

                    // Assuming the token is in a specific XML element
                    var tokenNode = xmlDoc.SelectSingleNode("//attr[@name='LogonToken']");
                    if (tokenNode != null)
                {
                        string logonToken = tokenNode.InnerText.Trim();
                        return logonToken;
                }
                    else
                    {
                        throw new Exception("Token not found in the response.");
                    }
                }
                else
                {
                    throw new Exception("Authentication failed: " + response.ReasonPhrase);
                }
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;At this stage I comment out what's in the if statement as I am only interested in the response.&lt;/P&gt;&lt;P&gt;I have tried it without the clientType as I am not entirely sure what that needs to be.&lt;/P&gt;&lt;P&gt;I was hoping someone could see something I've missed.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2024 12:07:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaq-p/13851513</guid>
      <dc:creator>uhs</dc:creator>
      <dc:date>2024-09-02T12:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication issues when using RESTful api C# for 4...</title>
      <link>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaa-p/13851643#M4881542</link>
      <description>&lt;P&gt;what base URL are you using?&amp;nbsp; it should be &amp;nbsp;&lt;SPAN&gt;http(s)://&amp;lt;server&amp;gt;:&amp;lt;RESTful port&amp;gt;/&lt;STRONG&gt;biprws&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You also missed the header&amp;nbsp; &amp;nbsp;"Accept"&amp;nbsp; application/xml&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2024 13:33:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaa-p/13851643#M4881542</guid>
      <dc:creator>ayman_salem</dc:creator>
      <dc:date>2024-09-02T13:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication issues when using RESTful api C# for 4...</title>
      <link>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaa-p/13852180#M4881600</link>
      <description>&lt;P&gt;Hi ayman_salem,&lt;BR /&gt;Thanks for reply.&lt;/P&gt;&lt;P&gt;The baseurl is in the form of &lt;SPAN&gt;http://&amp;lt;server&amp;gt;:6405/&lt;STRONG&gt;biprws&lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;I had added this syntax previously but didn't see a change:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
{
	// Add the Accept header to the request
    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
// code continued here...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This is the reponses I get both when hardcoding the credentials and baseurl and with variables :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;responseStatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: Apache-Coyote/1.1
  Access-Control-Allow-Credentials: true
  Access-Control-Allow-Origin: http://&amp;lt;servername&amp;gt;:8080
  Access-Control-Expose-Headers: X-SAP-LogonToken, X-SAP-PVL, WWW-Authenticate
  Date: Tue, 03 Sep 2024 05:22:23 GMT
  Content-Type: application/xml
  Content-Length: 431
}&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;responseStatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: Apache-Coyote/1.1
  Date: Tue, 03 Sep 2024 05:30:13 GMT
  Content-Type: application/xml
  Content-Length: 431
}&lt;/LI-CODE&gt;&lt;P&gt;The url to get the response works so assume the api is accepting requests&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;http://servername:6405/biprws/logon/long&lt;/LI-CODE&gt;&lt;P&gt;Is there a log file I can check for more debug information. I wonder if the requestBody syntax is not correct.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2024 05:39:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaa-p/13852180#M4881600</guid>
      <dc:creator>uhs</dc:creator>
      <dc:date>2024-09-03T05:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication issues when using RESTful api C# for 4.2 BusinessObjects</title>
      <link>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaa-p/13852241#M4881613</link>
      <description>&lt;P&gt;I found the issue. I noticed when replying previously that the 401 response included a referece to port 8080.&lt;/P&gt;&lt;P&gt;i.e this part:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Access-Control-Allow-Origin: http://servername:8080&lt;/LI-CODE&gt;&lt;P&gt;I tried the below to see if I got a response in the browser:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;http://servername:8080/biprws/logon/long&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;It returned the same response when using 6405.&lt;/P&gt;&lt;P&gt;Changing the port to 8080 in the baseurl fixed the issue and returns the token. There must be a port redirection happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2024 06:19:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/authentication-issues-when-using-restful-api-c-for-4-2-businessobjects/qaa-p/13852241#M4881613</guid>
      <dc:creator>uhs</dc:creator>
      <dc:date>2024-09-03T06:19:35Z</dc:date>
    </item>
  </channel>
</rss>

