#Change initial Spring OAuth2 redirection

1 messages · Page 1 of 1 (latest)

rustic otter
#

Hello. I'm running a Spring Boot application that uses OAuth2 to authenticate users behind a Spring Cloud Gateway, hence I need to change the url of basically every redirection that happens to go through the gateway, as in production there will be no direct access to the application from the internet.

I've found spring.security.oauth2.client.registration.github.redirect-uri and already set that accordingly, which works fine.
My issue currently is that when visiting myGateway/protectedResource I get redirected to myApp/oauth2/authorization/github, which I need to change to myGateway/oauth2/authorization/github.

Does anyone know how I can change this?

regal falconBOT
#

<@&1004656351647117403> please have a look, thanks.

regal falconBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

regal fog
#

Is the redirect uri configurable for myApp?

rustic otter
#

What do you mean by that?
Inside of myApp, I have set spring.security.oauth2.client.registration.github.redirect-uri to myGateway/login/oauth2/code/github, which works properly. I need to change the initial redirect though.

Hopfully the attached screenshot should clear things up. myGateway is at localhost:8081, which is effectively routing all traffic to myApp, running at localhost:9091. You can see that with a request to myGateway/protectedResource (in this case /admin), I get redirected to myApp/oauth2/authorization/github as the very first step, however I want this redirection to go to myGateway, and so become http://localhost:8081/oauth2/authorization/github

regal fog
#

Mmh and you see this redirect happen at the myApp server?

#

(like, is there a log entry for it)

#

Oh, you probably need to configure the login URL as well

#

(I had to look for the correct term)

rustic otter
#

Ok, I've changed the authorization endpoint's baseUri to be kt authorizationEndpoint().baseUri("http://localhost:8081/oauth2/authorization") , which does work, and the first request now redirects me to http://localhost:8081/oauth2/authorization/github as expected.

The new issue though, is that myApp/oauth2/authorization/github returns a 404 from myApp. Is this because Spring is trying to listen at http://localhost:8081/oauth2/authorization/github now rather than keeping its old endpoints?

regal fog
#

Possibly. Is there a reason you're not handling oauth at the gateway instead?

rustic otter
#

Not really, I just created the gateway last, once I already had oauth working in myApp. I didn't realise that was a thing I could actually do

rustic otter
#

I suppose I'll have to bite the bullet and look into that then, thanks for the help @regal fog. I'll close in a second