Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Avoid hardcode URL for userAuthorizationUri and accessTokenUri #671

Open
kakawait opened this issue Jan 8, 2016 · 14 comments
Open

Avoid hardcode URL for userAuthorizationUri and accessTokenUri #671

kakawait opened this issue Jan 8, 2016 · 14 comments

Comments

@kakawait
Copy link

kakawait commented Jan 8, 2016

On my project we have an UAA on same domain than OAuth2 Sso (via @EnableOauth2Sso).

Moreover to easily deploy application on every possible environment we try to do not have any absolute URLs.

Thus I want to know if is possible and not a no-sense to be able to configure OAuth2 client properties:

  • security.oauth2.client.accessTokenUri
  • security.oauth2.client.userAuthorizationUri

as path (!= absolute URL). Even more URI as describe on RFC is different than URL, path is an URI but when setting path I have following error:

java.lang.IllegalArgumentException: [/my/custom/path] is not a valid HTTP URL
    at org.springframework.web.util.UriComponentsBuilder.fromHttpUrl(UriComponentsBuilder.java:267) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter.redirectUser(OAuth2ClientContextFilter.java:99) ~[spring-security-oauth2-2.0.8.RELEASE.jar:na]
    at org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter.doFilter(OAuth2ClientContextFilter.java:70) ~[spring-security-oauth2-2.0.8.RELEASE.jar:na]

Because URI is used as URL.

We should:

  • support URI (or create a interceptor that allow user to customize the way to use the properties)
  • or rename security.oauth2.client.userAuthorizationUri and security.oauth2.client.accessTokenUri as security.oauth2.client.userAuthorizationUrl and security.oauth2.client.accessTokenUrl
@kakawait kakawait changed the title Relative path support for userAuthorizationUri and accessTokenUri Support userAuthorizationUri and accessTokenUri as URI or rename to *Url Jan 15, 2016
@kakawait
Copy link
Author

If you think my point of view is correct I can create PR

@kakawait
Copy link
Author

Today to avoid using hardcode/absolute hostname I have to do following modification:

  • Rewrite OAuth2ClientContextFilter to support URI in favor to URL! By supporting URI you can now use relative path (supported by header Location and browser)
userAuthorizationUri: /uaa/oauth/authorize
  • For accessTokenUri I just have a trick by setting following thing on Zuul
accessTokenUri: http://localhost:${server.port}/uaa/oauth/token

Thus Oauth2RestTemplate will use Zuul to call AuthorizationService. It could be better to add LoadBalancerd capability to Oauth2RestTemplate for replacing following tricks by

accessTokenUri: http://authorization-service/uaa/oauth/token

@kakawait kakawait changed the title Support userAuthorizationUri and accessTokenUri as URI or rename to *Url No absolute URL for userAuthorizationUri and accessTokenUri Mar 25, 2016
@kakawait kakawait changed the title No absolute URL for userAuthorizationUri and accessTokenUri Avoid hardcode URL for userAuthorizationUri and accessTokenUri Mar 25, 2016
@dsyer
Copy link
Contributor

dsyer commented Apr 5, 2016

I'm not sure we can handle any of the zuul or load balancer features here, so maybe you could move the discussion to spring-cloud/spring-cloud-security?

@kakawait
Copy link
Author

kakawait commented Apr 6, 2016

@dsyer There is a way to transfer issue between project?

@dsyer
Copy link
Contributor

dsyer commented Apr 6, 2016

No, but you can paste a link in the other project's issue and it will show up here automatically.

@dsyer
Copy link
Contributor

dsyer commented Apr 7, 2016

Let's leave this one open to cover the changes you are asking for in OAuth2ClientContextFilter (to support relative URLs). The token endpoint would have to be covered in the client, so I don't think it makes sense here (but might in a Spring Cloud setting).

@kakawait
Copy link
Author

kakawait commented Apr 7, 2016

But should I open an issue on spring-cloud/spring-cloud-security too? Maybe I will wait you completely finish analysis of https://github.com/kakawait/uaa-behind-zuul-sample before opening something new

@dsyer
Copy link
Contributor

dsyer commented Apr 7, 2016

But should I open an issue on spring-cloud/spring-cloud-security too?

Yes, please, I think that's where the change would have to be made in Spring Cloud.

@jgrandja
Copy link
Contributor

@dsyer Is there a change required here? Or is it just in Spring Cloud? Given that the discussion started with @EnableOauth2Sso.

@dsyer
Copy link
Contributor

dsyer commented May 11, 2016

Yes, some change would be here since it relates to the client filter. (And @EnableOAuth2Sso is a Spring Boot feature now.)

@rwinch
Copy link
Contributor

rwinch commented May 13, 2016

This might be resolved by using https://jira.spring.io/browse/SPR-13614

@dsyer dsyer modified the milestones: 2.0.10, 2.1.0 May 13, 2016
@hsjankie
Copy link

hsjankie commented Nov 22, 2016

@dsyer Was the relative url change added yet, it would help a lot in our setup.

@dsyer
Copy link
Contributor

dsyer commented Nov 22, 2016

There's no change here. If there was you would see the status updated.

@jgrandja jgrandja modified the milestones: 2.1.1, 2.1.0 Mar 3, 2017
@kakawait
Copy link
Author

kakawait commented Mar 17, 2017

@hsjankie @jgrandja @dsyer I found a solution for accessTokenUri by simply enhance the used RestTemplate with Ribbon, please check here spring-attic/spring-cloud-security#61 (comment)

That was way more elegant than loopback trick that I experimented on my POC

@jgrandja jgrandja modified the milestones: 2.1.1, 2.1.2 May 29, 2017
@jgrandja jgrandja modified the milestones: 2.1.2, 2.2.0.M1 Jun 29, 2017
@jgrandja jgrandja modified the milestones: 2.2.0.RC1, 2.2.0 Jul 14, 2017
@jgrandja jgrandja removed this from the 2.2.1 milestone Sep 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

5 participants