Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.springframework.util.Assert;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UrlPathHelper;

/**
* A {@code Filter} for the OAuth 2.0 Device Authorization endpoint, which handles the
Expand Down Expand Up @@ -219,10 +220,16 @@ private void sendDeviceAuthorizationResponse(HttpServletRequest request, HttpSer
OAuth2DeviceCode deviceCode = deviceAuthorizationRequestAuthentication.getDeviceCode();
OAuth2UserCode userCode = deviceAuthorizationRequestAuthentication.getUserCode();

String relativeVerificationPath = this.verificationUri.startsWith("/")
? this.verificationUri.substring(1)
: this.verificationUri;

// Generate the fully-qualified verification URI
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder
.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
.replacePath(this.verificationUri);
.replacePath(UrlPathHelper.defaultInstance.getContextPath(request))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using UrlPathHelper, please create an internal method resolveVerificationUri(), that looks like:

then it can be used UriComponentsBuilder.fromUriString(resolveVerificationUri(request)). This will provide consistency between the 3x implementations (OAuth2AuthorizationEndpointFilter is implemented the same).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created - as requested - an internal method and added a test.

I used doFilterWhenDeviceAuthorizationRequestThenDeviceAuthorizationResponse as a base for my test. I am not sure whether the method name fits the project conventions for test method names and I am unsure about keeping all assertions of doFilterWhenDeviceAuthorizationRequestThenDeviceAuthorizationResponse or just using a reduced set of assertions.

.replaceQuery(null)
.pathSegment(relativeVerificationPath);
String verificationUri = uriComponentsBuilder.build().toUriString();
// @formatter:off
String verificationUriComplete = uriComponentsBuilder
Expand Down