Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17447

Unable to create clientid-secret in Azure Active Directory

$
0
0

I am trying to generate a New ClientID and Secret for an Application in Azure Active Directory using client_credentials flow using code below.

The application used to run this script has Application.ReadWrite.All, Application.ReadWrite.OwnedBy and Directory.ReadWrite.All permissions at Application and Delegated level.

import requestsfrom datetime import datetime, timedelta# Azure AD B2C Constantsapplication_id ='888-xxxx-xxxx-xxxxx'TENANT_ID = 'xxxx-xxxx-xxxxxxx'CLIENT_ID = 'xxxx-xxxx-xxxxxxx'CLIENT_SECRET = 'xxxxx-xxxxx-xxxxx'# Token endpoint to get the access tokentoken_endpoint = f'https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token'# Resource URLresource_url = 'https://graph.microsoft.com'# Scopes for the Microsoft Graph APIscopes = ['https://graph.microsoft.com/.default' ]# Parameters to get the access tokentoken_data = {'grant_type': 'client_credentials','client_id': CLIENT_ID,'client_secret': CLIENT_SECRET,'scope': ''.join(scopes)}# Get access tokentoken_response = requests.post(token_endpoint, data=token_data)access_token = token_response.json().get('access_token')# Create app registration in Azure AD B2Ccreate_app_endpoint = f'{resource_url}/v1.0/{TENANT_ID}/applications'headers = {'Authorization': f'Bearer {access_token}','Content-Type': 'application/json'}url_password = f'{resource_url}/v1.0/applications/{application_id}/addPassword'print(url_password)# Construct the request body with password credentials detailspassword_credentials_data = {"passwordCredential": {"displayName": "System_Access_1"    }}# Send the request to create password credentialsresponse = requests.post(url_password, headers=headers, json=password_credentials_data)# Check the responseif response.status_code == 200:    print("Password credentials created successfully.")else:    print("Failed to create password credentials. Status code:", response.status_code)    print("Response:", response.text)

However, I am getting an error

https://graph.microsoft.com/v1.0/applications/888-xxxx-xxxx-xxxxx/addPasswordFailed to create password credentials. Status code: 404Response: {"error":{"code":"Request_ResourceNotFound","message":"Resource '888-xxxx-xxxx-xxxxx' does not exist or one of its queried reference-property objects are not present.","innerError":{"date":"2024-02-26T16:01:36","request-id":" ","client-request-id":""}}}

I have followed the approach here,

https://learn.microsoft.com/en-us/graph/api/application-addpassword?view=graph-rest-1.0&tabs=http

I checked in Azure Active Directory and the application exists. What could be the potential reason?


Viewing all articles
Browse latest Browse all 17447

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>