use of no.nav.security.token.support.client.core.ClientAuthenticationProperties in project token-support by navikt.
the class ClientCredentialsTokenClientTest method assertThatClientAuthMethodIsPrivateKeyJwt.
private static void assertThatClientAuthMethodIsPrivateKeyJwt(String body, ClientProperties clientProperties) {
ClientAuthenticationProperties auth = clientProperties.getAuthentication();
assertThat(auth.getClientAuthMethod().getValue()).isEqualTo("private_key_jwt");
assertThat(body).contains("client_id=" + encodeValue(auth.getClientId()));
assertThat(body).contains("client_assertion_type=" + encodeValue("urn:ietf:params:oauth:client-assertion-type:jwt-bearer"));
assertThat(body).contains("client_assertion=" + "ey");
}
use of no.nav.security.token.support.client.core.ClientAuthenticationProperties in project token-support by navikt.
the class ClientAssertionTest method testCreateAssertion.
@Test
void testCreateAssertion() throws ParseException, JOSEException {
ClientAuthenticationProperties clientAuth = ClientAuthenticationProperties.builder().clientJwk("src/test/resources/jwk.json").clientId("client1").clientAuthMethod(ClientAuthenticationMethod.PRIVATE_KEY_JWT).build();
ClientProperties clientProperties = ClientProperties.builder().grantType(OAuth2GrantType.CLIENT_CREDENTIALS).tokenEndpointUrl(URI.create("http://token")).authentication(clientAuth).build();
Instant now = Instant.now();
ClientAssertion clientAssertion = new ClientAssertion(clientProperties.getTokenEndpointUrl(), clientProperties.getAuthentication());
assertThat(clientAssertion).isNotNull();
assertThat(clientAssertion.assertionType()).isEqualTo("urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
String assertion = clientAssertion.assertion();
assertThat(clientAssertion.assertion()).isNotNull();
SignedJWT signedJWT = SignedJWT.parse(assertion);
String keyId = clientProperties.getAuthentication().getClientRsaKey().getKeyID();
assertThat(signedJWT.getHeader().getKeyID()).isEqualTo(keyId);
assertThat(signedJWT.getHeader().getType()).isEqualTo(JOSEObjectType.JWT);
assertThat(signedJWT.getHeader().getAlgorithm()).isEqualTo(JWSAlgorithm.RS256);
JWSVerifier verifier = new RSASSAVerifier(clientAuth.getClientRsaKey());
assertThat(signedJWT.verify(verifier)).isTrue();
JWTClaimsSet claims = signedJWT.getJWTClaimsSet();
assertThat(claims.getSubject()).isEqualTo(clientAuth.getClientId());
assertThat(claims.getIssuer()).isEqualTo(clientAuth.getClientId());
assertThat(claims.getAudience()).containsExactly(clientProperties.getTokenEndpointUrl().toString());
assertThat(claims.getExpirationTime()).isAfter(Date.from(now));
assertThat(claims.getNotBeforeTime()).isBefore(claims.getExpirationTime());
}
use of no.nav.security.token.support.client.core.ClientAuthenticationProperties in project token-support by navikt.
the class ClientCredentialsTokenClientTest method assertThatClientAuthMethodIsClientSecretPost.
private static void assertThatClientAuthMethodIsClientSecretPost(String body, ClientProperties clientProperties) {
ClientAuthenticationProperties auth = clientProperties.getAuthentication();
assertThat(auth.getClientAuthMethod().getValue()).isEqualTo("client_secret_post");
assertThat(body).contains("client_id=" + encodeValue(auth.getClientId()));
assertThat(body).contains("client_secret=" + encodeValue(auth.getClientSecret()));
}
use of no.nav.security.token.support.client.core.ClientAuthenticationProperties in project token-support by navikt.
the class ClientCredentialsTokenClientTest method assertThatClientAuthMethodIsClientSecretBasic.
private static void assertThatClientAuthMethodIsClientSecretBasic(RecordedRequest recordedRequest, ClientProperties clientProperties) {
ClientAuthenticationProperties auth = clientProperties.getAuthentication();
assertThat(auth.getClientAuthMethod().getValue()).isEqualTo("client_secret_basic");
assertThat(recordedRequest.getHeaders().get("Authorization")).isNotBlank();
String usernamePwd = decodeBasicAuth(recordedRequest);
assertThat(usernamePwd).isEqualTo(auth.getClientId() + ":" + auth.getClientSecret());
}
Aggregations