neutrino36
(neutrino neutrino)
October 20, 2020, 9:58am
#1
Hello,
After I add it Generic REST API add-on in Cuba 7 I have this error in Postman (POST):
{
“error”: “unauthorized”,
“error_description”: “Bad credentials”
}
Until now, it worked. Did you make some changes?
I added these lines in webb-app.properties
cuba.rest.client.id=client
cuba.rest.client.secret={noop}secret
but is the same result (eather I make call in url or in body)
Regards,
-n
belyaev
(Andrey Belyaev)
October 20, 2020, 10:11am
#2
Hi,
What has changed? Have you updated the CUBA version? What is the auth header for your request?
neutrino36
(neutrino neutrino)
October 20, 2020, 10:14am
#3
Hi,
I make this request from Postman.
Should I add in Cuba something like this:
URL myURL = new URL(serviceURL);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
String userCredentials = "username:password";
String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userCredentials.getBytes()));
myURLConnection.setRequestProperty ("Authorization", basicAuth);
myURLConnection.setRequestMethod("POST");
myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length);
myURLConnection.setRequestProperty("Content-Language", "en-US");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true)
?
Yes, I updated the Cuba version to 7.2.8. Should I downgrade?
belyaev
(Andrey Belyaev)
October 20, 2020, 3:07pm
#4
Did you do a major update?
As for the code - don’t add to your program. When using postman, don’t forget to specify
POST /oauth/token
Authorization: Basic {here you should use Base64Encoded cuba.rest.client.id:cuba.rest.client.secret}
Content-Type: application/x-www-form-urlencoded
as specified in documentation . And it should work.
neutrino36
(neutrino neutrino)
October 20, 2020, 3:38pm
#5
Could you be more specific please?
I have choosen Basic Authorization.
However with or without these lines is the same thing.
cuba.rest.client.id=client
cuba.rest.client.secret={noop}secret
What means these lines and what changes did you make in REST Add on?
belyaev
(Andrey Belyaev)
October 20, 2020, 6:55pm
#6
Here is the header for the request:
And this is body
neutrino36
(neutrino neutrino)
October 20, 2020, 8:38pm
#7
How did you get Header value: c2Vzc…?
belyaev
(Andrey Belyaev)
October 21, 2020, 9:21am
#8
It is base64-encoded string “client:secret” - ARC client (I use it instead of Postman) generates it automatically when you define authorization header
neutrino36
(neutrino neutrino)
October 21, 2020, 9:54am
#9
Thank you! Finally works.
In order to make queries from fromtend (ReactJS) to Cuba Middleware it is necesarry authentication?
Or it is enough to use anonymousAllowed = true
in the rest-services.xml
method?
Please take a look here (maybe you give me a hint, please):
Hello Team, I struggle to make a REST querry from React Frontend, but is very hard to do it with only several documentation snippets. Could you help me with an example, please? In services.ts I added this service (based on session_planner example):...
Best Regards,
-n
belyaev
(Andrey Belyaev)
October 22, 2020, 10:15am
#10
You need to do it only once and after that, you can use a token in order to access REST endpoints. If you use CUBA SDK and generated REST client, it should happen transparently.
As for the anonymous access, I wouldn’t recommend using it for all REST API endpoints.
neutrino36
(neutrino neutrino)
October 22, 2020, 10:35am
#11
Can you give me an example, please?
I struggle a lot but it’s very difficult only with several code snippets.
What should I add in my code in order to run?
Ah, it’s running React app, it’s not Postman. What value do you have in .env.development.local file? It contains URL to the CUBA app. If your CUBA app is running on the default 8080 port, it should contain http://localhost:8080/app/rest/ URL.
belyaev
(Andrey Belyaev)
October 22, 2020, 1:14pm
#12
If you have the generated ReactJS client, it should be in the sources. I guess guys from the referenced thread will help you I guess.
neutrino36
(neutrino neutrino)
October 23, 2020, 2:00pm
#13
Hi Andrey,
Is theare any example somhere in the Cuba docs?
I saw that the key library is cuba.d.ts
.
albudarov
(Alexander Budarov)
October 23, 2020, 5:03pm
#14
There is a working CUBA PetClinic Live React Demo with nice examples of various browsers and editors:
https://demo10.cuba-platform.com/petclinic-front/index.html#/
Its source code is here: GitHub - cuba-guides/cuba-petclinic-online-demo
(check for frontend module)
This sample is launched without problem on my machine.