Skip to content

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Jul 9, 2025

Related command
az login

Description
During the MSAL migration (#19853), interactive re-authentication with claims challenge is already supported by core via **kwargs, but is not exposed via az login and AAD error handling, because:

  1. This aligns with Azure PowerShell's Connect-AzAccount cmdlet which doesn't support claims challenge.
  2. Re-authenticating without claims challenge can already solve known CAE errors.

As now MFA policy returns a claims challenge, re-authenticating without this claims challenge will not trigger the MFA process.

Similar to #17778 which added --scope, this PR adds --claims-challenge argument to az login in order to trigger the MFA process during interactive authentication.

Because kwargs of azure.cli.core._profile.Profile.login was initially designed for supporting claims_challenge and claims_challenge is now explicitly supported, there is no need to keep kwargs.

Testing Guide

az login --tenant xxx --claims-challenge eyJhY2Nlc3NfdG9rZW4iOnsiYWNycyI6eyJlc3NlbnRpYWwiOnRydWUsInZhbHVlcyI6WyJwMSJdfX19

History Notes

[Profile] az login: Add --claims-challenge argument to support interactive authentication with claims challenge

Copilot AI review requested due to automatic review settings July 9, 2025 09:46
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jul 9, 2025

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.9
️✔️acs
️✔️latest
️✔️3.12
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.9
️✔️ams
️✔️latest
️✔️3.12
️✔️3.9
️✔️apim
️✔️latest
️✔️3.12
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️aro
️✔️latest
️✔️3.12
️✔️3.9
️✔️backup
️✔️latest
️✔️3.12
️✔️3.9
️✔️batch
️✔️latest
️✔️3.12
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.9
️✔️billing
️✔️latest
️✔️3.12
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.9
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.9
️✔️config
️✔️latest
️✔️3.12
️✔️3.9
️✔️configure
️✔️latest
️✔️3.12
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.9
️✔️container
️✔️latest
️✔️3.12
️✔️3.9
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.9
️✔️core
️✔️latest
️✔️3.12
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.9
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.9
️✔️dls
️✔️latest
️✔️3.12
️✔️3.9
️✔️dms
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.9
️✔️find
️✔️latest
️✔️3.12
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.9
️✔️identity
️✔️latest
️✔️3.12
️✔️3.9
️✔️iot
️✔️latest
️✔️3.12
️✔️3.9
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.9
️✔️lab
️✔️latest
️✔️3.12
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️maps
️✔️latest
️✔️3.12
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.9
️✔️network
️✔️latest
️✔️3.12
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.9
️✔️profile
️✔️latest
️✔️3.12
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.9
️✔️redis
️✔️latest
️✔️3.12
️✔️3.9
️✔️relay
️✔️latest
️✔️3.12
️✔️3.9
️✔️resource
️✔️latest
️✔️3.12
️✔️3.9
️✔️role
️✔️latest
️✔️3.12
️✔️3.9
️✔️search
️✔️latest
️✔️3.12
️✔️3.9
️✔️security
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.9
️✔️sql
️✔️latest
️✔️3.12
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.9
️✔️storage
️✔️latest
️✔️3.12
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.9
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.9
️✔️util
️✔️latest
️✔️3.12
️✔️3.9
️✔️vm
️✔️latest
️✔️3.12
️✔️3.9

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jul 9, 2025

⚠️AzureCLI-BreakingChangeTest
⚠️profile
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd login cmd login added parameter claims_challenge

@yonzhan
Copy link
Collaborator

yonzhan commented Jul 9, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link

github-actions bot commented Jul 9, 2025

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the --claims-challenge argument to az login, allowing clients to pass a Base64-encoded claims challenge (e.g., to trigger MFA) during interactive authentication. It decodes the flag at the CLI layer and propagates the decoded value through Profile.login down to MSAL.

  • Register --claims-challenge in the az login command and decode its value.
  • Introduce b64decode utility and simplify b64encode.
  • Update authentication methods and Profile.login to accept an explicit claims_challenge parameter and remove **kwargs.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/profile/custom.py Added claims_challenge parameter, Base64 decoding, and pass-through to profile.login.
src/azure-cli/azure/cli/command_modules/profile/init.py Registered the --claims-challenge CLI argument with help text.
src/azure-cli-core/azure/cli/core/util.py Simplified b64encode, and added new b64decode function.
src/azure-cli-core/azure/cli/core/auth/identity.py Changed login methods to explicit claims_challenge parameter and removed **kwargs.
src/azure-cli-core/azure/cli/core/_profile.py Updated Profile.login signature to include claims_challenge and adapted internal calls.
Comments suppressed due to low confidence (2)

src/azure-cli-core/azure/cli/core/_profile.py:155

  • Add documentation for the new claims_challenge parameter in the login method docstring to explain its purpose, expected format, and how it integrates with MSAL.
              claims_challenge=None):

src/azure-cli/azure/cli/command_modules/profile/custom.py:152

  • Add or update unit/integration tests for the new --claims-challenge flag to verify that Base64 decoding is performed correctly and the value is passed through to authentication flows.
    if claims_challenge:

@jiasli jiasli changed the title [Profile] az login: support --claims-challenge [Profile] az login: Support --claims-challenge Jul 10, 2025

if use_device_code:
user_identity = identity.login_with_device_code(scopes=scopes, **kwargs)
user_identity = identity.login_with_device_code(scopes=scopes)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initiate_device_flow doesn't support claims_challenge and fails with

  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\auth\identity.py", line 176, in login_with_device_code
    flow = self._msal_app.initiate_device_flow(scopes, claims_challenge=claims_challenge)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\cli\py312\Lib\site-packages\msal\application.py", line 2341, in initiate_device_flow
    flow = self.client.initiate_device_flow(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\cli\py312\Lib\site-packages\msal\oauth2cli\oauth2.py", line 326, in initiate_device_flow
    resp = self._http_client.post(self.configuration[DAE],
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\cli\py312\Lib\site-packages\msal\individual_cache.py", line 273, in wrapper
    value = function(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\cli\py312\Lib\site-packages\msal\individual_cache.py", line 273, in wrapper
    value = function(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\cli\py312\Lib\site-packages\msal\throttled_http_client.py", line 96, in post
    return NormalizedResponse(self.http_client.post(*args, **kwargs))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\cli\py312\Lib\site-packages\requests\sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Session.request() got an unexpected keyword argument 'claims_challenge'

If claims_challenge is not passed to initiate_device_flow, calling acquire_token_by_device_flow with claims_challenge fails:

  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\auth\identity.py", line 186, in login_with_device_code
    return check_result(result)
           ^^^^^^^^^^^^^^^^^^^^
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\auth\util.py", line 134, in check_result
    aad_error_handler(result, **kwargs)
  File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\auth\util.py", line 53, in aad_error_handler
    raise AuthenticationError(error_description, msal_error=error, recommendation=recommendation)
azure.cli.core.azclierror.AuthenticationError: AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 9416cbef-6f2f-4bba-b99f-e41722113e00 Correlation ID: d657b456-40d3-4d39-ae98-4d2927752bb8 Timestamp: 2025-06-24 07:56:44Z

This has been reported to MSAL:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we show a warning telling customers that --claims-challenge is not supported for device code flow and will be ignored?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temporary bug in MSAL's device code implementation. I prefer not to complicate things as the bug will be fixed eventually.

@jiasli jiasli changed the title [Profile] az login: Support --claims-challenge [Profile] az login: Support --claims-challenge in auth code flow Jul 10, 2025
allow_no_subscriptions=False,
use_cert_sn_issuer=None,
show_progress=False,
**kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR removes lots of kwargs. I just want to confirm that kwargs is never used and always empty, right?

Copy link
Member Author

@jiasli jiasli Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It is not used by any means. See the explanation in the PR description #31778 (comment).

@jiasli jiasli merged commit 02809f3 into Azure:dev Jul 10, 2025
56 checks passed
@jiasli jiasli deleted the login_claims_challenge branch July 10, 2025 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Account az login/account Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants