Search in sources :

Example 1 with ClientCredentialsSelector

use of com.nimbusds.oauth2.sdk.auth.verifier.ClientCredentialsSelector 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);
            }
        }
    };
}
Also used : PublicKey(java.security.PublicKey) ClientAuthenticationMethod(com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientCredentialsSelector(com.nimbusds.oauth2.sdk.auth.verifier.ClientCredentialsSelector) Secret(com.nimbusds.oauth2.sdk.auth.Secret) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JWSHeader(com.nimbusds.jose.JWSHeader) KeyFactory(java.security.KeyFactory)

Aggregations

JWSHeader (com.nimbusds.jose.JWSHeader)1 ClientAuthenticationMethod (com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod)1 Secret (com.nimbusds.oauth2.sdk.auth.Secret)1 ClientCredentialsSelector (com.nimbusds.oauth2.sdk.auth.verifier.ClientCredentialsSelector)1 ClientID (com.nimbusds.oauth2.sdk.id.ClientID)1 KeyFactory (java.security.KeyFactory)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)1