Message
 
 
To
22/12/2016 08:19:47
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01645753
Message ID:
01645884
Views:
44
>>>>
>>>>I am getting Authorization Denied message. So something is wrong but not with your code. Thank you.
>>>
>>>Were you given credentials to access the service? A username and password? Normally, you have 3 choices to send them to the WebService
>>>
>>>1. As an header (through m.HttpRequest.SetRequestHeader);
>>>
>>>2. As a parameter (since you're using GET, that would be in the querystring, that is, value pairs after a ? in the URL);
>>>
>>>3. Or, more simply, as username and password parameters of the m.HttpRequest.Open method: m.HttpRequest.Open("GET", m.HttpResponseEndPoint, .F., m.UsertName, m.Password) - of course, m.UserName and m.Password being previously set.
>>
>>The way this Web API works is that, first I have to call a service and pass a user name and password. And I get a token in return (JSON) authorizing further calls to the Web API. I did the first call and verified that the returned token is valid. I can see it in the debugger.
>>Then, by design of this Web API, when I need to call another server (like get records from a table), I have to pass - in the Header - this token that I got with the first call. Here is the problem. When I add the value of this token (exact syntax specified by the developer is ("Authorization", "bearer " + _token) I get back the message that "Authorization has been denied for this request."
>>
>>Note that by design of this Web API, I don't need to pass user name and password on any further calls. And I see this code works in the sample C# example the developer of Web API provided.
>>
>>I think the problem is in the Header. That is I need to find out if the value I add to the Header goes to the "right" header.
>>
>>I am guessing that maybe when I add [ ("Authorization", "bearer " + _token) ] to the header, it does not set to the right header property. For example, if I use the wwHTTP class suggested by Thierry, and use the method AddHeader(), the value actually is assigned to the property named "cExtraheaders". Which does not work.
>
>Ok, I see two potential issues here: a) extraction of the correct value of the token from the JSON reply; b) the header may require some kind of encoding (base64, for instance). Can you paste here the C# code, with any sensitive information properly redacted?

This is the C# code that works:
var request = new RestRequest('\methodtogettable', Method.GET);
request.AddHeader("Authorization", "bearer " + _token);
var response = _client.Execute(request);
And I am communicating with the Web API developer over email and he didn't mention need for encoding at all.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View