Skip to content

token_type_hint should be used as a hint only #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

rozagerardo
Copy link
Contributor

Issue #175
Added support to find an OAuth2Authorization based on a token, and using the TokenType parameter only as a hint instead of as a hard constraint.

TokenType.ACCESS_TOKEN,
TokenType.REFRESH_TOKEN,
new TokenType(OAuth2AuthorizationAttributeNames.STATE)));
if (tokenTypeHint != null && supportedTokenTypes.remove(tokenTypeHint)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TokenType is a hint; that means it will simply indicate with which supported token type we should start

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 6, 2021
@jgrandja jgrandja self-assigned this Jan 7, 2021
@jgrandja jgrandja added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 7, 2021
@jgrandja jgrandja added this to the 0.1.0 milestone Jan 7, 2021
Copy link
Collaborator

@jgrandja jgrandja left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @rozagerardo. Please see review comment.

@@ -63,6 +68,27 @@ public OAuth2Authorization findByToken(String token, @Nullable TokenType tokenTy
.orElse(null);
}

@Nullable
@Override
public OAuth2Authorization findByTokenWithHint(String token, @Nullable TokenType tokenTypeHint) {
Copy link
Collaborator

@jgrandja jgrandja Jan 7, 2021

Choose a reason for hiding this comment

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

Please remove findByTokenWithHint() and modify findByToken() instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to confirm we're on the same page here @jgrandja :

As you surely know, the findByToken() method is used in several other places apart from the classes involved in this endpoint (OAuth2AuthorizationCodeAuthenticationProvider, OAuth2ClientAuthenticationProvider, OAuth2RefreshTokenAuthenticationProvider, OAuth2AuthorizationEndpointFilter).

We probably don't want to change the behavior for these cases, so I'll need to add a boolean parameter to the findByToken() method, in order to indicate if we want the TokenType param to be used just as a hint, or as a strict constraint in the search.

I know it's not critical, but if so, should we also overload the method to make this parameter 'optional' (so that we don't have to change the existing method invocations)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably don't want to change the behavior for these cases

Agreed

so I'll need to add a boolean parameter to the findByToken() method, in order to indicate if we want the TokenType param to be used just as a hint, or as a strict constraint in the search

I would prefer to not add an extra parameter or overload the operation. I'd prefer to keep it simple. Given that TokenType is @Nullable, I'm tempted to completely ignore the token_type_hint request parameter and pass in null for the revocation (and introspection) flows. I think this will work. Can you please give this a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that would work, and the spec indicates this is a valid approach as well @jgrandja :

token_type_hint OPTIONAL. [...] An authorization server MAY ignore
this parameter, particularly if it is able to detect the
token type automatically.

Just a quick side note; IMO it would still make sense to define a way (that is, a method) to allow using the parameter as a hint (as part of the OAuth2AuthorizationService interface), and then rely on the implementation to decide how to implement that; for example, the in-memory implementation might simply call the findByToken with a null value (because the hint doesn't really represent a critical improvement in this case), a db implementation might want to benefit from this possibility.

Having said this, I don't think this is a critical decision (at least not at this point); I think ignoring the token_type_hint is ok, we can decide later on if it makes sense to actually support it.

Thus, I now made the changes, let me know if there is something else I should work on :)

BTW the build failed (for just one check), but it doesn't seem related to my change (in fact, the last commit contained just a minor formatting change):

Could not resolve org.springframework:spring-expression:5.3.1.
> Could not get resource 'https://repo.spring.io/libs-milestone/org/springframework/spring-expression/5.3.1/spring-expression-5.3.1.pom'.
> Could not GET 'https://repo.spring.io/libs-milestone/org/springframework/spring-expression/5.3.1/spring-expression-5.3.1.pom'.
> repo.spring.io

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can decide later on if it makes sense to actually support it

Agreed

@jgrandja jgrandja added the status: duplicate A duplicate of another issue label Jan 20, 2021
@jgrandja
Copy link
Collaborator

Thanks for the updates @rozagerardo ! This is now in master.

@jgrandja jgrandja closed this Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants