Create and Use Access keys for a user and use them in Python script.

Himanshu Vaish 26 Reputation points
2022-12-21T18:23:09.603+00:00

I want to execute the following command through a python script.

$ServicePrincipalUpdate =@{
"RelayState" = "https://signin.aws.amazon.com/saml"
}

Update-MgServicePrincipal -ServicePrincipalId '<servicePrincipalId>' -samlSingleSignOnSettings $ServicePrincipalUpdate

My requirement is to create access keys for my user in Azure and use those keys in python to authenticate and programmatically update ServicePrincipalID.

Currently I am able to do it via Azure cli but it has a GUI authentication component which I want to remove.

Thanks

Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,426 Reputation points Microsoft Employee Moderator
    2022-12-22T06:28:19.217+00:00

    Hi @Himanshu Vaish ,

    Thanks for reaching out.

    Currently we don't have any direct sample for your scenario. You can leverage below samples to

    Get service Principal Id using Python:

    https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-local-development-service-principal?tabs=azure-portal
    https://github.com/azureossd/python-sdk-aad-samples/tree/main/python-sdk-graph-samples

    Authenticate users using Python:

    https://github.com/Azure-Samples/ms-identity-python-webapp

    Executing PowerShell commands using Python:

    https://www.phillipsj.net/posts/executing-powershell-from-python/

    Hope this will help.

    Thanks,
    Shweta

    -----------------------------------------

    Please remember to "Accept Answer" if answer helped you.

    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.