Skip to content

fix: add 'Bearer ' prefix #5025

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public List<ServiceProvider> getServiceProviders() {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"injectionTarget=" + injectionTarget +
'}';
"injectionTarget=" + injectionTarget +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public Result<TokenRepresentation> obtainClientCredentials(TokenParameters param
SUBJECT, myOwnDid,
AUDIENCE, parameters.getStringClaim(AUDIENCE)));

return secureTokenService.createToken(claims, scope);
return secureTokenService.createToken(claims, scope)
.map(originalToken -> originalToken.toBuilder()
.token("Bearer " + originalToken.getToken())
.build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


import com.nimbusds.jwt.JWTClaimsSet;
import org.assertj.core.api.Assertions;
import org.eclipse.edc.iam.identitytrust.spi.CredentialServiceClient;
import org.eclipse.edc.iam.identitytrust.spi.CredentialServiceUrlResolver;
import org.eclipse.edc.iam.identitytrust.spi.SecureTokenService;
Expand All @@ -44,6 +43,7 @@

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.iam.identitytrust.spi.SelfIssuedTokenConstants.PRESENTATION_TOKEN_CLAIM;
import static org.eclipse.edc.iam.verifiablecredentials.spi.TestFunctions.createCredentialBuilder;
import static org.eclipse.edc.iam.verifiablecredentials.spi.TestFunctions.createPresentationBuilder;
Expand Down Expand Up @@ -102,9 +102,11 @@ private VerificationContext verificationContext() {

@Nested
class ObtainClientCredentials {
@ParameterizedTest(name = "{0}")
@ParameterizedTest(name = "Invalid Scope: {0}")
@ValueSource(strings = {"org.eclipse.edc:TestCredential:modify", "org.eclipse.edc:TestCredential:", "org.eclipse.edc:TestCredential: ", "org.eclipse.edc:TestCredential:write*", ":TestCredential:read",
"org.eclipse.edc:fooCredential:+"})
@EmptySource
@NullSource
void obtainClientCredentials_invalidScopeString(String scope) {
var tp = TokenParameters.Builder.newInstance()
.claims(SCOPE, scope)
Expand All @@ -117,19 +119,18 @@ void obtainClientCredentials_invalidScopeString(String scope) {
}

@ParameterizedTest(name = "Scope: {0}")
@ValueSource(strings = {"org.eclipse.edc:TestCredential:modify", "org.eclipse.edc:TestCredential:", "org.eclipse.edc:TestCredential: ", "org.eclipse.edc:TestCredential:write*", ":TestCredential:read",
"org.eclipse.edc:fooCredential:+"})
@NullSource
@EmptySource
@ValueSource(strings = {"org.eclipse.edc:TestCredential:read", "org.eclipse.edc:TestCredential:*", "org.eclipse.edc:TestCredential:write"})
void obtainClientCredentials_validScopeString(String scope) {
var tp = TokenParameters.Builder.newInstance()
.claims(SCOPE, scope)
.claims(AUDIENCE, "test-audience")
.build();
assertThat(service.obtainClientCredentials(tp))
var result = service.obtainClientCredentials(tp);
assertThat(result)
.isNotNull()
.isFailed()
.detail().contains("Scope string invalid");
.isSucceeded();

assertThat(result.getContent().getToken()).startsWith("Bearer ");
}


Expand Down Expand Up @@ -248,8 +249,8 @@ void verify_singlePresentation_singleCredential() {
assertThat(result).isSucceeded()
.satisfies(ct -> {
var vc = (List<VerifiableCredential>) ct.getListClaim("vc");
Assertions.assertThat(vc).hasSize(1);
Assertions.assertThat(vc.get(0).getCredentialSubject().get(0).getClaims()).containsEntry("some-claim", "some-val");
assertThat(vc).hasSize(1);
assertThat(vc.get(0).getCredentialSubject().get(0).getClaims()).containsEntry("some-claim", "some-val");
});
}

Expand Down Expand Up @@ -279,9 +280,9 @@ void verify_singlePresentation_multipleCredentials() {
assertThat(result).isSucceeded()
.satisfies(ct -> {
var credentials = (List<VerifiableCredential>) ct.getClaims().get("vc");
Assertions.assertThat(credentials).hasSize(2);
Assertions.assertThat(credentials.get(0).getCredentialSubject().get(0).getClaims()).containsEntry("some-claim", "some-val");
Assertions.assertThat(credentials.get(1).getCredentialSubject().get(0).getClaims()).containsEntry("some-other-claim", "some-other-val");
assertThat(credentials).hasSize(2);
assertThat(credentials.get(0).getCredentialSubject().get(0).getClaims()).containsEntry("some-claim", "some-val");
assertThat(credentials.get(1).getCredentialSubject().get(0).getClaims()).containsEntry("some-other-claim", "some-other-val");
});
}

Expand Down Expand Up @@ -331,11 +332,11 @@ void verify_multiplePresentations_multipleCredentialsEach() {
assertThat(result).isSucceeded()
.satisfies(ct -> {
var credentials = (List<VerifiableCredential>) ct.getListClaim("vc");
Assertions.assertThat(credentials).hasSize(4);
Assertions.assertThat(credentials).anySatisfy(vc -> Assertions.assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-claim", "some-val"));
Assertions.assertThat(credentials).anySatisfy(vc -> Assertions.assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-other-claim", "some-other-val"));
Assertions.assertThat(credentials).anySatisfy(vc -> Assertions.assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-claim-2", "some-val-2"));
Assertions.assertThat(credentials).anySatisfy(vc -> Assertions.assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-other-claim-2", "some-other-val-2"));
assertThat(credentials).hasSize(4);
assertThat(credentials).anySatisfy(vc -> assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-claim", "some-val"));
assertThat(credentials).anySatisfy(vc -> assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-other-claim", "some-other-val"));
assertThat(credentials).anySatisfy(vc -> assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-claim-2", "some-val-2"));
assertThat(credentials).anySatisfy(vc -> assertThat(vc.getCredentialSubject().get(0).getClaims()).containsEntry("some-other-claim-2", "some-other-val-2"));
});
}

Expand Down
1 change: 1 addition & 0 deletions resources/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress files="package-info.java" checks="[a-zA-Z0-9]*"/>
<suppress files=".*" checks="Indentation"/>
</suppressions>