Given a Subscription Key-Is there a way to find who the key belongs to?

Martin Kal 20 Reputation points
2024-06-22T22:57:56.96+00:00

Is there a way to find the user who owns a particular sub key?
for instance:
I want to find out in APIM who owns the key AABBCCDDEEFFGGHHIII

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,908 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,466 Reputation points
    2024-06-24T05:53:11.6+00:00

    @Martin Kal Thanks for reaching out. Assuming you have the apim service name , you can use below sample script to retrieve the respective information.

    try {
    
        "Logging in to Azure..."
    
        Connect-AzAccount  -Tenant "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 
    
    }
    
    catch {
    
        Write-Error -Message $_.Exception
    
        throw $_.Exception
    
    }
    
        
    
    $subscriptions = Get-AzSubscription -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    
    Set-AzContext -Subscription $subscriptions[0]
    
    $apimContext = New-AzApiManagementContext -ResourceGroupName "ResourcesRG" -ServiceName "apimgmt"
    
    $sId = Get-AzApiManagementSubscription -Context $apimContext
    
    foreach ($s in $sId) {
    
        $subKey = Get-AzApiManagementSubscriptionKey -Context $apimContext -SubscriptionId $s.SubscriptionId 
    
        if ($subKey.PrimaryKey -eq "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" -or $subKey.SecondaryKey -eq "xxxxxxxxxxxxxxxxxxxxxxxxxxxx") {             
    
            $subtemp = Get-AzApiManagementSubscription -context $apimContext -SubscriptionId $s.SubscriptionId
    
            $user = Get-AzApiManagementUser -Context $apimContext -UserId $subtemp.UserId      Write-Output "Subscription ID: " + $s.SubscriptionId + " User ID: " + $user.Id + " User Email: " + $user.Email
    
        }
    
    }
    
    0 comments No comments