microsoftgraph / microsoftgraph/msgraph-sdk-java
Authenticate with application id using Certificated-based Authentication
Offen
@Ndiritu arbeitet bereits daran.
Seit 15.7.2024.
Status: Needs Investigation
type:question
- Vorherrschende Sprache
- Java
- Sterne
- 444
- Forks
- 154
- Ø Merge
- 18 Std. 28 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
I registered the app on the Microsoft Entra admin center by referring to this page:
https://learn.microsoft.com/en-us/graph/auth-v2-service?tabs=http
Then I created public/private key using openssl. Here is the commands.
$ openssl genrsa -out ms365-private.key 2048
$ openssl req -new -x509 -key ms365-private.key -out ms365-public.crt -days 365000
Uploaded the public key (ms365-private.key) on the Microsoft Entra admin center, and I created this code.
TokenCredential credential = new ClientCertificateCredentialBuilder().tenantId("xxxxxxxx")
.clientId("xxxxxxxx")
.pemCertificate("/xxxx/xxxxx/ms365-private.key")
.build();
graphClient = new GraphServiceClient(credential);
but if i execute some methods on this graphClient , this following error occurs
[ERROR] com.azure.identity.implementation.util.CertificateUtil.performLogging - PEM certificate provided does not contain -----BEGIN CERTIFICATE-----END CERTIFICATE----- block
java.lang.IllegalArgumentException: PEM certificate provided does not contain -----BEGIN CERTIFICATE-----END CERTIFICATE----- block
at com.azure.identity.implementation.util.CertificateUtil.publicKeyFromPem(CertificateUtil.java:79)
at com.azure.identity.implementation.IdentityClientBase.getConfidentialClient(IdentityClientBase.java:196)
at com.azure.identity.implementation.IdentitySyncClient.lambda$new$2(IdentitySyncClient.java:91)
at com.azure.identity.implementation.SynchronousAccessor.getValue(SynchronousAccessor.java:45)
at com.azure.identity.implementation.IdentitySyncClient.authenticateWithConfidentialClientCache(IdentitySyncClient.java:171)
at com.azure.identity.ClientCertificateCredential.getTokenSync(ClientCertificateCredential.java:150)
at com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider.getAuthorizationToken(AzureIdentityAccessTokenProvider.java:146)
at com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider.authenticateRequest(BaseBearerTokenAuthenticationProvider.java:46)
Q. Should I also specify public key? If so, how to specify public key by using ClientCertificateCredentialBuilder?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.