Skip to content

Outdated UriComponentsBuilder method in One-Time Token Login example #18367

@hardik-xi11

Description

@hardik-xi11

UriComponentsBuilder only has formUri() and fromUriString() available for a using it with a url

The UriComponentsBuilder only has the following methods available and we must use either fromUri() or fromUriString() to pass in an url to the builder.

Image

Current Behavior
In the documentation it currently states we should be using .fromHttpUrl() for passing in the request url to the builder but that method does not exist here.

Currently we must use the following implementation to pass a request url to the builder

UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(request.getRequestURL().toString())
                .replacePath(request.getContextPath())
                .replaceQuery(null)
                .fragment(null)
                .path("/login/ott")
                .queryParam("token", oneTimeToken.getTokenValue());

Steps to Reproduce

  1. Go to the Spring Security One-Time Token Login documentation.
  2. Follow the example for MagicLinkOneTimeTokenGenerationSuccessHandler.
  3. Observe the compilation error on the line:
    UriComponentsBuilder.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
  • If you are using Intellij you will automatically see the infamous red squiggly line under .fromHttpUrl()

Suggested Fix

  • Update the MagicLinkOneTimeTokenGenerationSuccessHandler example in the documentation to use fromUriString() and request.getRequestURL() to ensure the code is copy-paste compatible for users

Context

  • I was trying to learn about OTT using the docs but the wrong implementation made it difficult to understand when i was getting an error with my configuration

  • I am trying to create a web app with pasword-less authentication using one time token generation

  • I'm not aware of any other alternatives or workarounds but would love to know more about this from someone who has the knowledge!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions