private static async Task RotateCertificateCoreAsync( CredentialRotatePayload payload, StringBuilder executionLogs, Dictionary <string, string> context, AzDoService azdo, Payloads.AzureDevOps.VstsServiceEndpoint endpoint, GraphServiceClient graph, Application application, DateTimeOffset now) { var selfSignedCertificate = CertificateUtils.CreateSelfSignedCertificateAsync(validForDays: payload.LifeTimeInDays); var certificateCredentail = new KeyCredential { StartDateTime = now, EndDateTime = now.AddDays(payload.LifeTimeInDays), Type = "AsymmetricX509Cert", Usage = "Verify", Key = CertificateUtils.GetPfxAsBytes(selfSignedCertificate) }; var app = new Application { KeyCredentials = new List <KeyCredential> { certificateCredentail } }; await graph.Applications[application.Id].Request().UpdateAsync(app); endpoint.Authorization.Parameters .ServicePrincipalCertificate = CertificateUtils.GeneratePEMWithPrivateKeyAsString(selfSignedCertificate); await azdo.UpdateServiceEndpointsAsync(payload.ProjectId, endpoint.Id, endpoint); context.Add("Certificate Key Id", certificateCredentail.KeyId.ToString()); context.Add("Certificate Start Time", certificateCredentail.StartDateTime.ToString()); context.Add("Certificate End Time", certificateCredentail.EndDateTime.ToString()); context.Add("Certificate Thumbprint", selfSignedCertificate.Thumbprint); }