Share via

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.

Lilu Wan 0 Reputation points Microsoft Employee
2026-05-23T23:04:22.71+00:00

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 (https://cognitiveservices.azure.com):  

  1. mssparkutils.credentials.getToken("https://cognitiveservices.azure.com") → 400: "Audience has invalid characters"  
  2. mssparkutils.credentials.getToken("CognitiveServices") → Not a recognized alias  
  3. mssparkutils.credentials.getToken("AzureOpenAI") → Not a recognized alias  
  4. mssparkutils.credentials.getToken("AzureCognitiveServices") → Not a recognized alias

AI Foundry (https://ai.azure.com):

  1. mssparkutils.credentials.getToken("https://ai.azure.com") → 400: "Audience has invalid characters"
  2. 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?  

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

Azure Synapse Analytics
Azure Synapse Analytics

An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.


1 answer

Sort by: Most helpful
  1. Smaran Thoomu 35,125 Reputation points Microsoft External Staff Moderator
    2026-05-26T07:36:33.0233333+00:00

    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:

    CognitiveServices

    AIServices

    is 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.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.