mssparkutils.credentials.getToken() does not support CognitiveServices or AIServices audience aliases — no way to acquire SAMI token for Azure OpenAI or Azure AI Foundry from Spark notebook.
We are migrating Synapse Spark pipeline authentication from certificate-based Service Principal to workspace System-Assigned Managed Identity (SAMI) to comply with SFI. The SAMI has been granted the required RBAC roles (Cognitive Services OpenAI Contributor, Azure AI User) and the configuration is verified. However, mssparkutils.credentials.getToken() does not support Azure Cognitive Services or Azure AI Foundry as audiences. Per the official documentation (Introduction to Microsoft Spark utilities - Azure Synapse Analytics | Microsoft Learn), the supported audiences are limited to: AzureManagement, Storage, AzureDataExplorer, Synapse, DW, etc. Neither Cognitive Services nor AI Foundry is listed.
This blocks our SFI migration — we cannot eliminate certificate-based auth because there is no way to acquire tokens for these audiences via managed identity from within a Synapse Spark notebook.
What we tested (2026-05-20) Cognitive Services ():
- mssparkutils.credentials.getToken("https://cognitiveservices.azure.com") → 400: "Audience has invalid characters"
- mssparkutils.credentials.getToken("CognitiveServices") → Not a recognized alias
- mssparkutils.credentials.getToken("AzureOpenAI") → Not a recognized alias
- mssparkutils.credentials.getToken("AzureCognitiveServices") → Not a recognized alias
AI Foundry ():
- mssparkutils.credentials.getToken("https://ai.azure.com") → 400: "Audience has invalid characters"
- mssparkutils.credentials.getToken("AIServices") → Not a recognized alias
7. mssparkutils.credentials.getToken("AzureAIServices") → Not a recognized alias All other scopes work correctly via named aliases (AzureManagement, Storage, AzureDataExplorer).
Ask
Could we have the following audience aliases added to the Synapse Token Service?
- CognitiveServices → (for Azure OpenAI API calls)
- AIServices → (for Azure AI Foundry project access)
This would allow mssparkutils.credentials.getToken("CognitiveServices") and mssparkutils.credentials.getToken("AIServices") to return tokens using the workspace managed identity, enabling SFI-compliant authentication for AI workloads in Synapse Spark.
Thank you
-
Gautami Bhoopati 90 Reputation points • Microsoft External Staff • Moderator
Hey @Lilu Wan ,
Thanks for the detailed write-up. You’re right—today’s mssparkutils.credentials.getToken API only knows about a fixed set of audience aliases (Storage, Vault, AzureManagement, DW, Synapse, ADF, AzureDataExplorer, AzureOSSDB, etc.), and it doesn’t expose CognitiveServices or AIServices. That’s why all your attempts to call getToken("https://cognitiveservices.azure.com") or getToken("CognitiveServices") are being rejected as unrecognized.Here’s what you can do today to move off certificate-based auth in your Spark notebook:
- Use the Azure Identity library directly instead of mssparkutils for those two endpoints. • In your notebook, pip-install azure-identity:
• Acquire a token with DefaultAzureCredential (which will pick up your workspace system-assigned identity):%pip install azure-identity
• Do the same for https://ai.azure.com/.default when calling Azure AI Foundry APIs.from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential() token = credential.get_token("https://cognitiveservices.azure.com/.default") spark.conf.set("fs.azure.token.provider.type", "Custom") # or however you pass the bearer token into your REST calls print(token.token) - File a feature request so the Synapse Token Service adds the two aliases you asked for: • CognitiveServices → https://cognitiveservices.azure.com • AIServices → https://ai.azure.com
That way, once the platform teams add them, you’d be able to do:
mssparkutils.credentials.getToken("CognitiveServices") mssparkutils.credentials.getToken("AIServices")and get back tokens via your workspace managed identity.
Hope this helps unblock your SFI migration. Let me know if you need any code samples or run into other errors!
Reference docs
- Microsoft Spark utilities (credentials) – supported audience aliases https://learn.microsoft.com/azure/synapse-analytics/spark/microsoft-spark-utilities#credentials-utilities
- Secure credentials with linked services using mssparkutils https://learn.microsoft.com/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary#tokenlibrary-for-other-linked-services
- DefaultAzureCredential (azure-identity) https://learn.microsoft.com/python/api/overview/azure/identity-readme
Note: This content was drafted with the help of an AI system. Please verify the information before relying on it for decision-making.
- Use the Azure Identity library directly instead of mssparkutils for those two endpoints. • In your notebook, pip-install azure-identity:
-
Lilu Wan 0 Reputation points • Microsoft Employee
Thank you for the response. Could you clarify which specific credential class within DefaultAzureCredential is expected to acquire the workspace SAMI token in a Synapse Spark pool?
I tested both the suggested DefaultAzureCredential approach and an additional federated identity credential workaround. Neither works in Synapse Spark pools.
EnvironmentCredential: No AZURE_CLIENT_ID/AZURE_TENANT_ID env vars
WorkloadIdentityCredential: No AZURE_FEDERATED_TOKEN_FILE env var
ManagedIdentityCredential: No IMDS endpoint (169.254.169.254 unreachable)
AzureCliCredential: Azure CLI not installed
AzurePowerShellCredential: PowerShell not installed
No MSI_ENDPOINT, IDENTITY_ENDPOINT, or AZURE_CLIENT_ID environment variables are set in the Spark pool. Is there a Synapse-specific credential provider or a runtime version where this works?
-
Smaran Thoomu 35,375 Reputation points • Microsoft External Staff • Moderator
Hi @Lilu Wan
Thank you for validating this in detail and sharing the credential chain results.
Based on your findings, it appears that in the current Synapse Spark runtime environment,
DefaultAzureCredential()is not able to discover or access the workspace System Assigned Managed Identity through the standard Azure Identity credential chain mechanisms (IMDS, workload identity, Azure CLI, environment variables, etc.).At this time, there does not appear to be a Synapse-specific Azure Identity credential provider exposed within Spark pools for acquiring Cognitive Services / Azure AI Foundry tokens through
DefaultAzureCredential()using workspace SAMI.Currently:
-
mssparkutils.credentials.getToken()supports only predefined audience aliases - Cognitive Services / AI Foundry audiences are not included
- Standard Azure Identity credential discovery also does not appear fully wired into Synapse Spark runtime for these scenarios
Given this behavior, your findings suggest there is currently a platform limitation/gap for acquiring SAMI tokens for Azure OpenAI / Azure AI Foundry directly from Synapse Spark notebooks using managed identity-only authentication.
We are checking internally with the engineering/Product Group team to better understand:
- whether this scenario is officially unsupported today
- whether there is any Synapse runtime/version where this is expected to work
- whether future support is planned for CognitiveServices / AIServices audience aliases or Synapse-managed identity integration for Azure Identity SDK flows
Thank you again for the detailed investigation and validation results.
-
Sign in to comment
2 answers
-
Smaran Thoomu 35,375 Reputation points • Microsoft External Staff • Moderator
Hi @Lilu Wan
Thank you for the detailed investigation and testing results.
Based on the current Microsoft Spark utilities implementation,
mssparkutils.credentials.getToken()supports only a predefined set of audience aliases, and currently Azure Cognitive Services / Azure AI Foundry audiences are not included. This explains why requests such as:mssparkutils.credentials.getToken("https://cognitiveservices.azure.com")or aliases like:
mssparkutils.credentials.getToken("CognitiveServices")are failing.
At present, the recommended workaround is to use the Azure Identity SDK directly inside the Synapse Spark notebook with the workspace Managed Identity, for example:
from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential() token = credential.get_token( "https://cognitiveservices.azure.com/.default" ) print(token.token)This approach allows token acquisition using the workspace System Assigned Managed Identity without relying on certificate-based authentication.
Similarly, for Azure AI Foundry scenarios, the corresponding scope can be requested using:
"https://ai.azure.com/.default"Your feedback regarding additional aliases such as:
CognitiveServicesAIServicesis valid and would improve managed identity integration experience within Synapse Spark. We recommend submitting this through official feedback/support channels so the Product Group can evaluate adding support in the Synapse Token Service.
Thank you for highlighting this scenario and sharing the detailed validation results.
-
Sina Salam 30,166 Reputation points • Volunteer Moderator
Hello Lilu Wan,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that your mssparkutils.credentials.getToken() does not support CognitiveServices or AIServices audience aliases and you need away to acquire SAMI token for Azure OpenAI or Azure AI Foundry from Spark notebook.
I reviewed this against the current Microsoft documentation, and the issue is a product limitation, not a misconfiguration. In Azure Synapse Spark,
mssparkutils.credentials.getToken()only supports a fixed, documented set of audiences, and Azure OpenAI / Azure AI Foundry audiences are not in that supported list today. That is why values such asCognitiveServices,AIServices,AzureOpenAI,AzureAIServices,https://cognitiveservices.azure.com, andhttps://ai.azure.comdo not work from the notebook. - https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary, https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/microsoft-spark-utilitiesThere is also a second documented limitation: in Synapse notebooks and Spark job definitions, the workspace system-assigned managed identity is only supported through linked services and
mssparkutilsAPIs, and MSAL / other authentication libraries cannot use that SAMI path inside the Spark notebook runtime. Because of that, switching toManagedIdentityCredential,DefaultAzureCredential, or MSAL inside the Synapse notebook is not a supported fix for this exact scenario. - https://learn.microsoft.com/en-us/azure/synapse-analytics/synapse-service-identity, https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.managedidentitycredential?view=azure-python, https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-pythonSo, my best advice since there is no supported way today to obtain an Azure OpenAI / Azure AI Foundry token directly from a Synapse Spark notebook by using the workspace system-assigned managed identity. Adding RBAC such as Cognitive Services OpenAI User / Contributor or Foundry roles is necessary for authorization, but it does not solve this case because the failure happens earlier, at token acquisition. - https://learn.microsoft.com/en-us/dotnet/ai/how-to/app-service-aoai-auth, https://learn.microsoft.com/en-us/azure/foundry/concepts/authentication-authorization-foundry, https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary
If the requirement is to remain secretless and managed-identity-based, the only reliable and supportable design is to move the Azure OpenAI / Azure AI Foundry call to an Azure host that supports managed identity directly, such as Azure Functions, App Service, Container Apps, AKS, or VM, assign the required AI roles there, and call that service from Synapse. Microsoft documents that model for Azure-hosted applications using managed identity with Azure OpenAI, and Foundry documentation recommends Microsoft Entra ID for production workloads. - https://learn.microsoft.com/en-us/dotnet/ai/how-to/app-service-aoai-auth, https://learn.microsoft.com/en
If the requirement is specifically “keep the call inside Synapse Spark and use workspace SAMI directly”, then this remains an unsupported scenario and should be treated as a feature gap in Synapse TokenLibrary / Token Service, not as a notebook-level fix. There is a supported Foundry Tools linked service path in Synapse, but the documented setup uses Key Vault-stored keys, so it changes the authentication model and does not meet your original “SAMI-only / no-secrets” requirement. - https://learn.microsoft.com/en-us/azure/synapse-analytics/synapse-service-identity, https://learn.microsoft.com/en-us/azure/synapse-analytics/machine-learning/tutorial-configure-cognitive-services-synapse
I hope this is helpful! Do not hesitate to let me know if you have any other questions, steps or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.
-
Sina Salam 30,166 Reputation points • Volunteer Moderator
In addition, for technical reasoning:
-
mssparkutils.credentials.getToken()in Synapse Spark does not support Azure OpenAI / Azure AI Foundry audiences today. - https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary, https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/microsoft-spark-utilities - Synapse Spark notebooks do not support using the workspace system-assigned managed identity through generic MSAL / Azure Identity libraries. - https://learn.microsoft.com/en-us/azure/synapse-analytics/synapse-service-identity, https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.managedidentitycredential?view=azure-python, https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python
- Therefore, there is no supported in-notebook fix for direct secretless Azure OpenAI / Foundry calls with workspace SAMI. - https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary, https://learn.microsoft.com/en-us/azure/synapse-analytics/synapse-service-identity
- The only reliable, supportable, production-ready is to move the AI call to another Azure host that supports managed identity directly and call that host from Synapse. - https://learn.microsoft.com/en-us/dotnet/ai/how-to/app-service-aoai-auth, https://learn.microsoft.com/en-us/azure/foundry/concepts/authentication-authorization-foundry, https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.managedidentitycredential?view=azure-python, https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python
- If the business will accept a different security model inside Synapse, the documented Foundry Tools linked-service path exists, but it is key-based and does not satisfy the original “workspace SAMI only / no secrets” requirement. - https://learn.microsoft.com/en-us/azure/synapse-analytics/machine-learning/tutorial-configure-cognitive-services-synapse, https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/apache-spark-secure-credentials-with-tokenlibrary
Success
-
Sign in to comment -
