Skip to content
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

Add support for resource parameter #888

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open

Conversation

federicaagostini
Copy link
Contributor

Following RFC8707, during an OAuth request the client may indicate a resource parameter, which is the target service to which access is being requested (MUST be an absolute URI). The value of the resource parameter is returned as aud claim in the JWT.

In case both audience and resource are provided, only the resource parameter will be included in the token (as aud claim).

@@ -0,0 +1,32 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021
Copy link
Contributor

Choose a reason for hiding this comment

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

At least for new files, let's use the right year(s). In this case it would just be 2024.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, maybe we can add a PR which updates all the licenses, otherwise the workflow would fail here https://github.com/indigo-iam/iam/blob/master/.github/workflows/maven.yml#L27.

new URL(url).toURI();
return true;
} catch (MalformedURLException | URISyntaxException e) {
throw new InvalidResourceError("Not a valid URI: " + url);
Copy link
Contributor

Choose a reason for hiding this comment

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

In case of an exception, it's not clear to me at what level the exception is caught; in other words, does the whole request fail? just the setting of the audience? if resource is invalid, shall we (re)consider the aud parameter instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add some tests for these cases, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the "resource" is not a valid URI, the whole request fails (see tests https://github.com/indigo-iam/iam/blob/issue-381/iam-login-service/src/test/java/it/infn/mw/iam/test/oauth/ResourceIndicatorTests.java).
At least this is my interpretation of the specification, which states

If the authorization server fails to parse the provided value(s) or does not consider the resource(s) acceptable, it should reject the request with an error response using the error code invalid_target as the value of the error parameter and can provide additional information regarding the reasons for the error using the error_description.

final String audience = authentication.getOAuth2Request()
.getRefreshTokenRequest()
.getRequestParameters()
.get(RESOURCE);
Copy link
Contributor

Choose a reason for hiding this comment

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

This was already computed in the if. Can we reuse that value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case refreshTokenRequest is null, refreshTokenRequest.getRequestParameters() would return a NullPointerException.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants