/// <summary> /// Set the keyCredentials property in the servicePrincipal. It's expected that the servicePrincipal will have the /// keyCredential and the passwordCredential configured /// </summary> /// <param name="servicePrincipal"></param> /// <param name="spId"></param> /// <param name="logger"></param> /// <returns></returns> public async Task ConfigureSelfSignedCertificate(Beta.ServicePrincipal servicePrincipal, string spId) { _ = await _graphBetaClient.ServicePrincipals[spId] .Request() .UpdateAsync(servicePrincipal); logger.Info("servicePrincipal updated with new keyCredentials"); }
private async Task ConfigureSigningCertificate(string spoId) { // Set custom signing key string password = Guid.NewGuid().ToString(); string certName = "SelfSigned federation metadata"; SelfSignedCertificate selfSignedCert = new SelfSignedCertificate(password, certName); Guid keyIDPrivateCert = Guid.NewGuid(); var privateKey = new Beta.KeyCredential() { CustomKeyIdentifier = selfSignedCert.CustomKeyIdentifier, EndDateTime = selfSignedCert.EndDateTime, KeyId = keyIDPrivateCert, StartDateTime = selfSignedCert.StartDateTime, Type = "AsymmetricX509Cert", Usage = "Sign", Key = selfSignedCert.PrivateKey }; var publicKey = new Beta.KeyCredential() { CustomKeyIdentifier = selfSignedCert.CustomKeyIdentifier, EndDateTime = selfSignedCert.EndDateTime, KeyId = Guid.NewGuid(), StartDateTime = selfSignedCert.StartDateTime, Type = "AsymmetricX509Cert", Usage = "Verify", Key = selfSignedCert.PublicKey }; var keyCredentials = new List <Beta.KeyCredential>() { privateKey, publicKey }; var passwordCredentials = new List <Beta.PasswordCredential>() { new Beta.PasswordCredential() { CustomKeyIdentifier = selfSignedCert.CustomKeyIdentifier, KeyId = keyIDPrivateCert, EndDateTime = selfSignedCert.EndDateTime, StartDateTime = selfSignedCert.StartDateTime, SecretText = password } }; var spKeyCredentials = new Beta.ServicePrincipal { KeyCredentials = keyCredentials, PasswordCredentials = passwordCredentials, PreferredTokenSigningKeyThumbprint = selfSignedCert.Thumbprint }; await _galleryAppsRepository.ConfigureSelfSignedCertificate(spKeyCredentials, spoId); }