Skip to content

ReactorServerHttpRequest.getUri() does not include scheme [SPR-15931] #20485

@spring-projects-issues

Description

@spring-projects-issues

Abhijit Sarkar opened SPR-15931 and commented

ServerRequest.uri() returns a relative URI that starts with //, thus making it impossible to extract the scheme. The scheme is required when working with OAuth that requires a redirect URL to be sent with the initial request.

Here's a sample OAuth call for Pinterest:

fun redirect(request: ServerRequest): Mono<ServerResponse> =
    UriComponentsBuilder.fromUriString("https://api.pinterest.com/oauth/")
            .queryParam("response_type", "code")
            .queryParam("scope", "read_public,write_public")
            .queryParam("state", state)
            .queryParam("client_id", clientId)
            .queryParam("redirect_uri", request.uri().resolve(URI.create("oauth/token"))
                    .let { uri -> (uri.scheme ?: "https").let { "$it:$uri" } })
            .build()
            .toUri()
            .also { logger.debug("Making request to: $it.") }
            .let { ServerResponse.permanentRedirect(it).build() }

fun accessToken(request: ServerRequest): Mono<ServerResponse> =
    request
            .also {
                logger.debug("Received access token: $it.")
                it.queryParam("state")
                        .filter { it == state }
                        .flatMap { request.queryParam("code") }
                        .ifPresent { cache.put("accessToken", it) }
            }
            .let { ServerResponse.noContent().build() }

Affects: 5.0 RC3

Issue Links:

Referenced from: commits 4a0784b, ec6475a

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions