Azure / azure-cli

Azure Command-Line Interface
MIT License
3.92k stars 2.88k forks source link

AZ Rest POST MultiPart/FormData is not working #17627

Open fabienso opened 3 years ago

fabienso commented 3 years ago

Description I have the following challenge: I am in the process of rolling out an Azure AD B2C fully automatically with all user flows. For this I am creating the app registrations, the user structures, the tenant etc. via a Python script and using execute().

For the creation of a user flow I need a service principal which returns an OAuth2 token from the secret ID and the ID of the app registration (B2C context).

Via Postman I get a valid token using the rest method POST to https://login.microsoftonline.com//oauth2/token, for this I need to pass the Secrets, the ID, the GrantType, Scope and the Resource.

In my Python script, which should give me the token to modify the B2C flows via the Graph API, I use for REST requests. However, "az rest" does not give me the chance to "multipart/form-data;" bodies to pass.

Do you know any alternatives or ways like "WebkitFormData" via az-rest (POST) can send over the body with?

To Reproduce Python-Command jwt = >(f'az rest --method POST --uri "https://login.microsoftonline.com/<TENANT_ID>/oauth2/token" --skip-authorization-header --headers "multipart/form-data" --body @body/form-params.txt) form-params.txt includes: `------WebKitFormBoundaryABCDEFGH Content-Disposition: form-data; name="grant_type"

client_credentials ------WebKitFormBoundaryABCDEFGH Content-Disposition: form-data; name="client_id"

------WebKitFormBoundaryABCDEFGH Content-Disposition: form-data; name="client_secret" ------WebKitFormBoundaryABCDEFGH Content-Disposition: form-data; name="resource" https://graph.microsoft.com ------WebKitFormBoundaryABCDEFGH Content-Disposition: form-data; name="scope" https://graph.microsoft.com/IdentityUserFlow.ReadWrite.All ------WebKitFormBoundaryABCDEFGH ` ==> Returns: ..... The request body must contain the following parameter: 'grant_type' .... **Expected behavior** **Environment summary** IDE: VS Code { "azure-cli": "2.19.1", "azure-cli-core": "2.19.1", "azure-cli-telemetry": "1.0.6", "extensions": {} }
yonzhan commented 3 years ago

@jiasli for awareness