use of com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod in project di-authentication-api by alphagov.
the class TokenService method generateClientCredentialsSelector.
private ClientCredentialsSelector<?> generateClientCredentialsSelector(String publicKey) {
return new ClientCredentialsSelector<>() {
@Override
public List<Secret> selectClientSecrets(ClientID claimedClientID, ClientAuthenticationMethod authMethod, com.nimbusds.oauth2.sdk.auth.verifier.Context context) {
return null;
}
@Override
public List<PublicKey> selectPublicKeys(ClientID claimedClientID, ClientAuthenticationMethod authMethod, JWSHeader jwsHeader, boolean forceRefresh, com.nimbusds.oauth2.sdk.auth.verifier.Context context) {
byte[] decodedKey = Base64.getMimeDecoder().decode(publicKey);
try {
X509EncodedKeySpec x509publicKey = new X509EncodedKeySpec(decodedKey);
KeyFactory kf = KeyFactory.getInstance("RSA");
return Collections.singletonList(kf.generatePublic(x509publicKey));
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
};
}
use of com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod in project Kustvakt by KorAP.
the class OpenIdTokenService method extractClientCredentials.
private String[] extractClientCredentials(ClientAuthentication clientAuthentication) throws KustvaktException {
ClientAuthenticationMethod method = clientAuthentication.getMethod();
String clientSecret;
String clientId;
if (method.equals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)) {
ClientSecretBasic basic = (ClientSecretBasic) clientAuthentication;
clientSecret = basic.getClientSecret().getValue();
clientId = basic.getClientID().getValue();
} else if (method.equals(ClientAuthenticationMethod.CLIENT_SECRET_POST)) {
ClientSecretPost post = (ClientSecretPost) clientAuthentication;
clientSecret = post.getClientSecret().getValue();
clientId = post.getClientID().getValue();
} else {
// client authentication method is not supported
throw new KustvaktException(StatusCodes.UNSUPPORTED_AUTHENTICATION_METHOD, method.getValue() + " is not supported.", OAuth2Error.INVALID_CLIENT);
}
return new String[] { clientId, clientSecret };
}
use of com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod in project di-ipv-cri-uk-passport-back by alphagov.
the class TokenRequestValidator method authenticateClientWithJwt.
private void authenticateClientWithJwt(String requestBody) throws ClientAuthenticationException {
PrivateKeyJWT clientJwt;
try {
clientJwt = PrivateKeyJWT.parse(requestBody);
String clientId = clientJwt.getClientID().getValue();
String clientAuthenticationMethod = configurationService.getClientAuthenticationMethod(clientId);
if (clientAuthenticationMethod.equals(NONE)) {
return;
}
verifier.verify(clientJwtWithConcatSignature(clientJwt, requestBody), null, null);
validateMaxAllowedAuthClientTtl(clientJwt.getJWTAuthenticationClaimsSet());
} catch (ParseException | InvalidClientException | JOSEException | java.text.ParseException e) {
LOGGER.error("Validation of client_assertion jwt failed");
throw new ClientAuthenticationException(e);
}
}
Aggregations