Azure / Azure/azure-cli

AZ Rest POST MultiPart/FormData is not working

Open
#17,627 1 comment 0 reactions 1 assignee Claimed by @jiasli View on GitHub
feature-request rest
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 22h
Merged PRs (30d)
64

Description

**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//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": {}
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.