Skip to content

AbstractOAuth2Token modifications: #6808

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

Closed
wants to merge 1 commit into from
Closed

AbstractOAuth2Token modifications: #6808

wants to merge 1 commit into from

Conversation

ch4mpy
Copy link
Contributor

@ch4mpy ch4mpy commented Apr 22, 2019

To illustrate
#6807

Make it possible to inject granted-authorities converter in JwtAuthenticationConverter constructor

JwtGrantedAuthoritiesConverter modifications (which currently is both a granted-authority and a scope converter.):

  • rename to JwtScopesGrantedAuthoritiesConverter because it extracts authorities from token scopes only
  • extract a TokenAttributesScopesConverter and use it as collaborator
  • make prefix scope authorities configurable (so that it can be removed)
  • add constructors to inject scopes converter and scope authorities prefix
  • modify default constructor so that it uses a TokenAttributesScopesConverter extracting scopes from "scope" and "scp" claims and adding "SCOPE_" prefix (keep current behavior)

TokenAttributesScopesConverter behavior modification: scan and merge all "claims to scan" (instead of first found only)

  * remove issuedAt and expiresAt properties (redundancyand potential incoherence with claims)
  * promote claims (AKA attributes) as abstracted member
Copy link
Contributor

@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.

@ch4mpy There is a significant amount of changes in this PR which complicates the process and requires quite a bit of time for review. As well, the changes here touch on a few core OAuth2 classes which is very risky.

This PR cannot be accepted for a number of reasons as I've detailed in my comments. On a go forward basis, please keep PR's as minimal as possible to help with the review process. You may need to split a PR into multiple PR's to keep the changes contained. However, if this is the case, than submit one first and allow the process to go through before you submit the next one. This will help us significantly and ultimately save everyone time.

*
* @param tokenValue the token value
*/
protected AbstractOAuth2Token(String tokenValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This type of change can only be applied in a major release - please see Semantic Versioning - otherwise, this breaks compatibility.

public @Nullable Instant getExpiresAt() {
return this.expiresAt;
}
public abstract @Nullable Instant getExpiresAt();
Copy link
Contributor

Choose a reason for hiding this comment

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

If the expires_in is provided in the Access Token Response it should be supplied via the constructor. It doesn't make sense to me to have an abstract method for overriding expiredAt that is also optional (but recommended) as per spec.

Furthermore, abstract methods/operations are typically provided to enable polymorphic behaviour in more complex classes. It's not that common to provide the same for a simple POJO attribute such as getExpiresAt() - it's either null or not-null nothing more.

Copy link
Contributor Author

@ch4mpy ch4mpy Apr 22, 2019

Choose a reason for hiding this comment

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

Does it make sens to have issue and expiration instants both as plein members AND claims (or attributes) in most token implementations ?

To me, issue and expiration claims (or attributes) access is polymorphic as claims could have different name and instant serialization depend on the token type. Some token types could even have no claim (attributes) and require instant members for that.

protected AbstractOAuth2Token(String tokenValue) {
this(tokenValue, null, null);
}
private final Map<String, Object> attributes;
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding Map<String, Object> attributes here doesn't make sense as there may be no attributes available for an instance of an OAuth 2.0 Token. A refresh token is an example of this as it's typically opaque. At a minimum, there is a token value and from a logical standpoint there will likely be a expires_at and if that is available than we can assume there is an issued_at. All other attributes are optional.

As an FYI, the concept of claims was introduced in the OpenID Connect related specifications NOT standard OAuth 2.0. For example, there is no concept of claims with GitHub and Facebook since they are not OpenID Connect compliant and instead implement standard OAuth 2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

issued_at and expires_at seemed good candidates for being stored in a Map<String, Object> attributes, just like for other token types.

*/
protected AbstractOAuth2Token(String tokenValue, @Nullable Instant issuedAt, @Nullable Instant expiresAt) {
protected AbstractOAuth2Token(final String tokenValue, final Map<String, Object> attributes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change breaks compatibility - see previous comment


@Override
public Instant getIssuedAt() {
return getClaimAsInstant("iat");
Copy link
Contributor

Choose a reason for hiding this comment

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

The iat claim is defined by the OpenID Connect related specifications as well as Jwt spec. However, this claim is likely not available for standard OAuth 2.0 providers like GitHub and Facebook. But it doesn't mean they don't provide their own attribute value for issueAt but using a different attribute name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

couldn't it be solved with more polymorphisme?


@Override
public Instant getExpiresAt() {
return getClaimAsInstant("exp");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same reasons as described for iat.

@jgrandja jgrandja closed this Apr 22, 2019
@jgrandja jgrandja self-assigned this Apr 22, 2019
@jgrandja jgrandja added the in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) label Apr 22, 2019
@jgrandja jgrandja added the status: declined A suggestion or change that we don't feel we should currently apply label Apr 22, 2019
@ch4mpy
Copy link
Contributor Author

ch4mpy commented Apr 22, 2019

This PR cannot be accepted

I can imagine. As per my opening comment in #6807:

I've no illusion this PR will be rejected at this stage, just a support for discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants