Skip to content

SDK should have a way to return 401 response body #41739

Open
@jiasli

Description

@jiasli

Is your feature request related to a problem? Please describe.
When a mgmt-plane request gets blocked by MFA policy, only the claims challenge from WWW-Authenticate header is passed to get_token_info via options['claims'].

The response body of the 401 response is discarded as Body is streamable:

cli.azure.cli.core.sdk.policies: Request URL: 'https://management.azure.com/subscriptions/9fb3fda4-e572-422a-a972-1011d3593176/resourceGroups/testpolicy1/providers/Microsoft.KeyVault/vaults/kv06171?api-version=2023-02-01'
cli.azure.cli.core.sdk.policies: Request method: 'PUT'
...

cli.azure.cli.core.sdk.policies: Response status: 401
cli.azure.cli.core.sdk.policies: Response headers:
...
cli.azure.cli.core.sdk.policies:     'WWW-Authenticate': 'Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", error="insufficient_claims", claims="eyJhY2Nlc3NfdG9rZW4iOnsiYWNycyI6eyJlc3NlbnRpYWwiOnRydWUsInZhbHVlcyI6WyJwMSJdfX19"'
...
cli.azure.cli.core.sdk.policies: Response content:
cli.azure.cli.core.sdk.policies: Body is streamable

However, the response body contains detailed information on the policy that rejected the request. The response body should be displayed to the user.

Describe the solution you'd like
SDK should have a way to pass the 401 response body to the credential that implements get_token_info so that it can display the response body accordingly.

For example, get_token_info's options can have a new field called body that contains the 401 response body.

Describe alternatives you've considered
N/A

Additional context

Metadata

Metadata

Labels

Azure.IdentityClientThis issue points to a problem in the data-plane of the library.feature-requestThis issue requires a new behavior in the product in order be resolved.

Type

No type

Projects

Status

Untriaged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions