Pass variable from VueJS to Controller of another application - spring-boot

i have to application:
Back-end : with spring boot run on localhost:8080
Front-end : contain vueJs run on localhost:8081
i want to pass a variable from my front-end vueJs and read it in the back end spring boot, any help? thx

Just do an XHR request like you would to contact any server.

Sharing data between Frontend and Backend requires a communication channel. Most popular way is to write a GET/POST API into the server and make a REST call from the client.
You need to write an API in spring boot server (Ex: http://localhost:8080/INeedData )
Make XHR or Axios or HTTP GET/POST request from VueJS passing the variable as Body to the API
Refer:
https://www.journaldev.com/21127/spring-boot-rest-example
https://alligator.io/vuejs/rest-api-axios/

Related

CAMUNDA API REST Authentication

I am trying to connect from my javascript front to the REST API of my camunda orchestration which is deployed as part of a spring boot application.
the called url is :
GET http://localhost:8081/oms-orchestrator-ms/api/engine/engine/default/history/process-instance
i get an 401 error for non authenticated queries which is normal
First question : is it the right way to query the Engine Rest API for process definition/ instances and history?
In order to make it work , i add the JSESSIONID cookie as header to my requests,
how can i use the basic auth to query the orchestrator api instead of using the cookie?
Thanks for your Help
the /api path is part of the cockpits REST backend which is secured by the same rules as the cockpit webapp.
You can additionally deploy the rest api (camunda-bpm-spring-boot-starter-rest if you are using spring boot). This will add an almost identical REST api for the engine under the path /rest. This one is open by default and can be secured manually if required (and advised for prod environments).

Keycloak: Spring Boot project as bearer and reusing token from user

I am building an application with an angular frontend and spring boot on the backend. I was able to configure the angular and spring part.
So, the frontend requests a token and sends it with every request to the java backend. This works just fine.
My java backend is now in the need to reuse the client token to request data from another service, which uses the same mechanism.
What is the right way to go forward? Requesting an own token for my service or using the existing token from the authenticated user?
I have not found a way to do this.
Works as pointed out by ravthiru
While calling your 3rd service you can use the same token , Add your third service as bearer-only Client.

Browser not sending jsession id with requests

I am writing an Angular4 app with Spring Boot backend. I am using a SessionScoped bean to store the logged in user (I know this is not RESTful and stuff and I am ok with it for now) and RestControllers for the endpoints.
Logging in and querying data with Postman works nicely, but it does not work from my angular app, so I debugged it a little and saw that I get jsessionid-s in the response-headers, but they are not appended in the requests.
What might be the problem? How can I use Angular with Spring Boot and session scoped beans?
It depends on how your are calling the backend.
If you are using angular-cli and the proxying the calls to spring boot it should work out of the box since same domain requests always pass cookies.
This is the preferred way because usually this is how you then deploy it live using a nginx location block to get all /api/ calls go to spring and everything else to angular.
https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md
If you have the api on a different host you will need to pass withCredentials: true to all requests going to the backend to force the request to include the cookies.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
this.http.post('http://localhost:3000/api/thing', { withCredentials: true }).subscribe()

Call A Rest API that is secured with spring security

How do i call an api from an app secured by spring security.
I have a api provider completely secured with spring security.
Now i want to allow other clients/service to consume my rest from their apps. eg using jquery, php, etc. But my app is secured.
Your assistance will be highly appreciated.
A REST API is a set of URLs. You access these URLs secured by Spring in the same way you'd access any secured Web app.
That is, use a Web client, establish a session by using the authentication method configured, and send the HTTP method request you want.

How force PUT request from a POST with Spring?

I have a service with routes on PUT and I want to make a SDK implementing those routes in Unity3D. The problem is WWW don't accept PUT request.
The service is based on Spring Framework.
From the SDK, I try to call the route in POST with an additional parameter _method set to PUT but it doesn't work.
There is a way to simulate a PUT request with a POST call in Spring Framework?
Thanks in advance for your help.
Have you configured HiddenHttpMethodFilter filter in your springframework, its required at server side to convert post request with _method parameter to put request

Resources