Skip to content
Advertisement

OAuth issue in API gateway

I am facing the OAuth issue, details are below: I am having two microservices: registration-service(https://github.com/choudharylakshyaveer/registration-service) student-service(https://github.com/choudharylakshyaveer/student-service)

For these two I have added : cloud-config-server(https://github.com/choudharylakshyaveer/cloud-config-server) naminig-server(https://github.com/choudharylakshyaveer/naming-server) gateway(https://github.com/choudharylakshyaveer/api-gateway)

FrontEnd: is at react js: https://github.com/choudharylakshyaveer/chargie

For first time use, a new user need to be register that can be done from curl:

JavaScript

To login using the above registered user, below can be run from cUrl:

JavaScript

Once I log In and get the Bearer token, after that I am facing cors issue from the reactJs FE, bu same request is working fine from the Postman, below is request from postman:

JavaScript

Below is the code used to hit request from ReactJs FE:

JavaScript

And this request gives me CORS issue: enter image description here

Snippet of the ServerSecurityContextRepository’s overridden method used in SecurityContextRepository class of api-gateway:

JavaScript

Here when the request is coming from the Postman then below is receievd in the headers variable:

JavaScript

But when same request comes from Front end then below is receievd in the headers variable and it seems to be malformed:

JavaScript

So, Here I am not receiving proper Authorization header on backend’s headers variable so that I can take Bearer token to validate it.

Advertisement

Answer

Working after adding cors, complete code below for SecurityWebFilterChain’s method :

JavaScript
Advertisement