Skip to content

Not able to retrieve azure service principal password using azure sdk for python #12246

@MonikaReddy-MSFT

Description

@MonikaReddy-MSFT

From Customer Question - MicrosoftDocs/azure-docs-cli#2052

Is there a way to retrieve azure service principal password using azure sdk for python? I am creating service principal using following but service principal create response has empty password.

def create_azure_service_principal(self, app_name=None):

app = self.graphrbac_client.applications.create({
    'available_to_other_tenants': False,
    'display_name': app_name,
    'identifier_uris': [f'http://{app_name}'],
    'app_roles': []
})

sp = self.graphrbac_client.service_principals.create({
    'app_id': app.app_id,
    'account_enabled': True
})
return sp

Here is the response :

{
'additional_properties': {
'odata.type': 'Microsoft.DirectoryServices.ServicePrincipal',
'signInAudience': 'AzureADMyOrg',
'preferredSingleSignOnMode': None,
'preferredTokenSigningKeyEndDateTime': None,
'samlSingleSignOnSettings': None,
'applicationTemplateId': None,
'notificationEmailAddresses': [],
'addIns': [],
'tokenEncryptionKeyId': None,
'informationalUrls': {
'termsOfService': None,
'support': None,
'privacy': None,
'marketing': None
},
'odata.metadata': 'https://graph.windows.net/<tenant_id>/$metadata#directoryObjects/@element'
},
'object_id': '<object_id>',
'deletion_timestamp': None,
'object_type': 'ServicePrincipal',
'account_enabled': True,
'alternative_names': [],
'app_display_name': 'my-test',
'app_id': '<app_id>',
'app_owner_tenant_id': '<tenant_id>',
'app_role_assignment_required': False,
'app_roles': [],
'display_name': 'my-test',
'error_url': None,
'homepage': None,
'key_credentials': [],
'logout_url': None,
'oauth2_permissions': [ < azure.graphrbac.models.oauth2_permission_py3.OAuth2Permission object at 0x7f64567b67810 > ],
'password_credentials': [],
'preferred_token_signing_key_thumbprint': None,
'publisher_name': 'Default Directory',
'reply_urls': [],
'saml_metadata_url': None,
'service_principal_names': ['<app_id>'],
'service_principal_type': 'Application',
'tags': []
}

Is there a way to reset the service principal using python sdk?

Not : I know we can this using azure cli but not sure if i want to mix azure sdk and cli in my code.

Please advice...

Metadata

Metadata

Labels

GraphMgmtThis issue is related to a management-plane library.Service AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions