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

Only able to successfully call api '/raylight/v1/about' all other calls receive 401

uhs
Explorer
0 Likes
737

Hi all,

I'm only been able to call '/raylight/v1/about' with success. all other calls e.g /session return 401

I have been able to authenticate and return a token which I use in the subsequent calls. Below is a pared down version of the code in C#:

 

 

using (var client = new System.Net.Http.HttpClient())
{
    client.DefaultRequestHeaders.Clear();
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
    var response = await client.GetAsync("http://servername:8080/biprws/raylight/v1/session");
                
    GD.Print("response" + response);
    return "ok";
 }

 

 

I have administrator privileges. I was wondering if I needed to do some further setup in the system or the token format is not correct? The token is taken from this response:

 

 

 responseStatusCode: 200, ReasonPhrase: '', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Tue, 03 Sep 2024 06:13:08 GMT
  X-SAP-LogonToken: "everything between the double quotes is extracted"
  Vary: accept-encoding
  Transfer-Encoding: chunked
  Content-Type: application/xml
}

 

 

Any help would be appreciated.

update: I think I am missing something like this

 

client.DefaultRequestHeaders.Add("X-SAP-LogonToken", $"\"{token}\"");

 

or

 

client.DefaultRequestHeaders.Add("X-SAP-LogonToken", token});

 

instead or along with

 

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

 

Addendum update after solution:

In my case I removed:

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

and replaced with:

client.DefaultRequestHeaders.Add("X-SAP-LogonToken", token);

Thanks,

Paul

 

Accepted Solutions (1)

Accepted Solutions (1)

ayman_salem
Active Contributor
0 Likes

Yes, after you have logged in and received the LogonToken (response from the logon call)), you should include the token in the “X-SAP-LogonToken” header on every RESTful call.

uhs
Explorer
0 Likes
Thanks, that worked after removing the wrong header info and replacing with the correct reference. The world's my oyster.. Well until the next problem!

Answers (0)