Skip to content

Conversation

marcusdacoregio
Copy link
Contributor

@marcusdacoregio marcusdacoregio commented Jul 29, 2024

Run ./gradlew publishToMavenLocal and try the Magic Link sample: https://github.com/marcusdacoregio/passwordless-spring-security

@marcusdacoregio marcusdacoregio self-assigned this Jul 29, 2024
@marcusdacoregio marcusdacoregio force-pushed the gh-15114-passwordless-ott branch 3 times, most recently from 92e918a to c70b2b2 Compare August 12, 2024 12:42
@marcusdacoregio marcusdacoregio marked this pull request as ready for review August 12, 2024 12:43
@marcusdacoregio marcusdacoregio added in: config An issue in spring-security-config type: enhancement A general enhancement labels Aug 12, 2024
@marcusdacoregio marcusdacoregio force-pushed the gh-15114-passwordless-ott branch 4 times, most recently from 3c46abf to ac04741 Compare August 12, 2024 18:08
Copy link
Contributor

@sjohnr sjohnr left a comment

Choose a reason for hiding this comment

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

@marcusdacoregio this looks great! I had a few minor comments for your consideration.

@marcusdacoregio marcusdacoregio force-pushed the gh-15114-passwordless-ott branch from ac04741 to 74dcab3 Compare August 14, 2024 20:22
@marcusdacoregio marcusdacoregio force-pushed the gh-15114-passwordless-ott branch 3 times, most recently from fdb949c to dfbe909 Compare August 20, 2024 12:44
Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

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

This is so cool, @marcusdacoregio! I've left my feedback inline.

// ...
.formLogin(Customizer.withDefaults())
.oneTimeTokenLogin((ott) -> ott
.showSubmitPage(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this would benefit from a more complete example, given that they will need to allow /my-ott-submit in authorizeHttpRequests. Also, a statement that this doesn't change the POST location.

* configured.
* @param show
*/
public OneTimeTokenLoginConfigurer<H> showSubmitPage(boolean show) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably call this generateSubmitPage or maybe showGeneratedSubmitPage (or showDefaultSubmitPage)

* Defaults to {@code POST /ott/generate}.
* @param generateUrl
*/
public OneTimeTokenLoginConfigurer<H> generateUrl(String generateUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could benefit from being called authenticationRequestUrl since it's conceptually similar to OAuth and SAML RP-initiated flows.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it feels odd to me that we'd depart from referring to this as an "authentication request", but then not depart from "loginProcessingUrl". Either they should both be contextual to this auth mechanism (generateTokenUrl and tokenProcessingUrl) or they should both align with other auth mechs (authenticationRequestUrl and loginProcessingUrl).

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to use naming that matches OTT rather than borrowing from other stack's terminology. The URL is not an authentication request. It requests generating a OTT and maps to OneTimeTokenService.generate, so I prefer this name.

Copy link
Contributor

@jzheaux jzheaux Aug 26, 2024

Choose a reason for hiding this comment

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

* Defaults to {@code POST /ott/generate}.
* @param generateUrl
*/
public OneTimeTokenLoginConfigurer<H> generateUrl(String generateUrl) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to use naming that matches OTT rather than borrowing from other stack's terminology. The URL is not an authentication request. It requests generating a OTT and maps to OneTimeTokenService.generate, so I prefer this name.

* @author Marcus da Coregio
* @since 6.4
*/
public final class RedirectGeneratedOneTimeTokenSuccessHandler implements GeneratedOneTimeTokenSuccessHandler {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how useful this is since nothing is done with the OneTimeToken. How would the user receive the token to consume it?

Perhaps a more useful implementation would be to set the OneTimeToken on a request attribute and then forward to a new URL. We could provide Spring MVC argument resolver to resolve the token to simplify processing this in Spring. I think all of this could be done in a future iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about a forward tho. If we forward from POST /ott/generate to /login/ott it will be a POST request, not a GET, I'm not sure how useful that is. Maybe the default implementation could store the OneTimeToken in the session and then redirect to the location.

Copy link
Member

@rwinch rwinch Aug 27, 2024

Choose a reason for hiding this comment

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

I think that the location that receives OTT would be in charge of doing something with it (e.g. sending it in an email, sending in a text message, placing it in session, etc) and then it would redirect to a new URL for the success page.

I'd like to reiterate that this can be done in a future iteration and does not need to be done now.

Copy link
Contributor Author

@marcusdacoregio marcusdacoregio Aug 27, 2024

Choose a reason for hiding this comment

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

Sure, we can continue the discussion on #15697

* @author Marcus da Coregio
* @since 6.4
*/
public final class RequestParameterOneTimeTokenGenerateRequestResolver implements OneTimeTokenGenerateRequestResolver {
Copy link
Member

Choose a reason for hiding this comment

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

Like the corresponding interface, I'm not sure that this is needed today.

@marcusdacoregio marcusdacoregio force-pushed the gh-15114-passwordless-ott branch from 2d33d68 to 28485be Compare September 3, 2024 12:46
@marcusdacoregio marcusdacoregio merged commit 00e4a8f into spring-projects:main Sep 3, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: config An issue in spring-security-config type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants