Forum Discussion
Programmatically add a user to the SharePoint UIL from Fabric after ACS retirement?
Sounds interesting/promising !
As for the steps ahead, would you happen to have more detailed step-by-step guide to how to:
- generate a credential in Azure
- be able to use it in a Fabric Notebook to generate/acquire a token that would allow us to call the `_api/web/ensureuser` with a successfull outcome
As for some additional context here are ...
... a printscreen of the Azure App config menu - could you confirm part of the job happens here ?
... a snippet of code I found here to supposedly retrieve a certificate that would have been store in an Azure KeyVault Secret
import base64, msal
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import pkcs12, Encoding, PrivateFormat, NoEncryption
# 1. Load credentials from Azure Key Vault
kv_url = "https://your-keyvault.vault.azure.net"
tenant_id = notebookutils.credentials.getSecret(kv_url, "sp-tenant-id")
client_id = notebookutils.credentials.getSecret(kv_url, "sp-client-id")
cert_pfx_b64 = notebookutils.credentials.getSecret(kv_url, "sp-certificate")
# 2. Parse the PFX to extract what MSAL needs
private_key, certificate, _ = pkcs12.load_key_and_certificates(
base64.b64decode(cert_pfx_b64), password=None
)
private_key_pem = private_key.private_bytes(Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption()).decode()
thumbprint = certificate.fingerprint(hashes.SHA1()).hex().upper()
# 3. Acquire an access token
app = msal.ConfidentialClientApplication(
client_id=client_id,
client_credential={"private_key": private_key_pem, "thumbprint": thumbprint},
authority=f"https://login.microsoftonline.com/{tenant_id}"
)
Would you happen to need any additional intel to help: I am available to provide them asap.
Hi MathieuSGA,
Yes, the screenshot you shared shows the correct area in Azure where the certificate gets attached to the App Registration under the Certificates tab. Typically, the certificate itself is first generated externally (for example via PowerShell or Azure Key Vault) as a .cer + .pfx pair and then the public certificate is uploaded there. Your Fabric notebook approach is also aligned with the current MSAL + certificate + Key Vault pattern Microsoft recommends for modern SharePoint app-only authentication.
The general flow would be to generate a certificate, upload the public certificate to the App Registration, store the PFX securely in Key Vault, retrieve it from Fabric at runtime and then use MSAL certificate authentication instead of a client secret to acquire the SharePoint token.
That said, I would still treat this as a validation step specifically for /_api/web/ensureuser. Microsoft documents certificate-based Entra app-only authentication for SharePoint Online REST APIs generally, but I could not find clear documentation confirming that /_api/web/ensureuser specifically supports app-only execution. So, the setup itself looks correct, but ensureuser may (mostly not) still reject the token requiring delegated user context.
Regards,
Community Support Team.
- v-hjannapu2 months agoCommunity Support
Hi MathieuSGA,
I hope the information provided above assists you in resolving the issue. If you have any additional questions or concerns, please do not hesitate to contact us. We are here to support you and will be happy to help with any further assistance you may need.
Regards,
Community Support Team.- v-hjannapu2 months agoCommunity Support
Hi MathieuSGA,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We are always here to support you.
Regards,
Community Support Team.- MathieuSGA2 months agoAdvocate I
The resolution process is "On Hold" for now since I need my Azure Admin to help me implement the provided approach