I want to connect to get Key Vault secrets using Azure AD client certificate
The example https://github.com/Azure-Samples/key-vault-java-certificate-authentication is not working for me.
Scenario steps:
1.Registered application in Azure AD, Added API/Permission name - Azure Key Vault
Selected user_impersonation. Have full access to Key Vault Service
2.Created certificate - pfx file
- Java code from example - specifying client id (registered application client id), pfx file password, pfx file location, key vault url
Question: How does Azure know about the certificate? Never worked with pfx file. Do I need to upload certificate (it says public key .cer/pem/crt)
Can I ask what step I'm missing, as I think authentication is not happening?
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.List (java.lang.String and java.util.List are in module java.base of loader 'bootstrap') at com.nimbusds.oauth2.sdk.util.MultivaluedMapUtils.getFirstValue(MultivaluedMapUtils.java:70) at com.nimbusds.oauth2.sdk.auth.JWTAuthentication.ensureClientAssertionType(JWTAuthentication.java:246)
Correction: My application is not in the Azure VM. It is on-premise
Java Code:
I updated the github example code with the below, but the error is same on acquireAccessToken call
AzureAdTokenCredentials credentials = new AzureAdTokenCredentials(
tenant,
AsymmetricKeyCredential.create(clientId, privateKey, certificateKey.getCertificate()),
AzureEnvironments.AZURE_CLOUD_ENVIRONMENT);
TokenProvider provider = new AzureAdTokenProvider(credentials, executorService);
String newToken = provider.acquireAccessToken().getAccessToken();
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.List (java.lang.String and java.util.List are in module java.base of loader 'bootstrap') at com.nimbusds.oauth2.sdk.util.MultivaluedMapUtils.getFirstValue(MultivaluedMapUtils.java:70) at com.nimbusds.oauth2.sdk.auth.JWTAuthentication.ensureClientAssertionType(JWTAuthentication.java:246) at com.nimbusds.oauth2.sdk.auth.PrivateKeyJWT.parse(PrivateKeyJWT.java:277) at com.microsoft.aad.adal4j.AuthenticationContext.createClientAuthFromClientAssertion(AuthenticationContext.java:903)
More Updates:
I see the above error in https://github.com/microsoft/azure-spring-boot/issues/457 and so updated a few of my dependencies and crossed that bridge.
New Error:
So I see it is unauthorized? and so too many follow up requests. How I can fix this? Should I use Handling Authentication in Okhttp ? Is this only a cap to avoid error, or guarantee authentication
Added API/Permission name - Azure Key Vault
) just allows you to get access token for key vault resource type. – Gaurav Mantri