Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

GraphServiceClient token cache persistence and CAE control

Offen
#1,355 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@ramsessanchez arbeitet bereits daran.

Seit 18.5.2026.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

type:feature
Is your feature request related to a problem? Please describe the problem.

As outlined in this issue: https://github.com/Azure/azure-sdk-for-python/issues/42898

Given this example code:

token_cache_options = TokenCachePersistenceOptions(name="MyApp")

if Path("cred.json").exists():
    with open("cred.json", "r") as f:
        deserealized_record = AuthenticationRecord.deserialize(f.read())

    device_credential = DeviceCodeCredential(
        client_id=azure_settings["clientId"],
        tenant_id=azure_settings["tenantId"],
        authentication_record=deserealized_record,
        cache_persistence_options=token_cache_options,
        disable_automatic_authentication=True,
    )
else:
    device_credential = DeviceCodeCredential(
        client_id=azure_settings["clientId"],
        tenant_id=azure_settings["tenantId"],
        cache_persistence_options=token_cache_options,
        disable_automatic_authentication=True,
    )

    record = device_credential.authenticate(scopes=azure_settings["graphScope"])

    with open("cred.json", "w") as f:
        f.write(record.serialize())

app_client = GraphServiceClient(
    credentials=device_credential, scopes=azure_settings["graphScope"]
)

# do something with app_client, eg: `app_client.me.get()`

We will not be able to achieve token cache persistence, because by default, the AzureIdentityAuthenticationProvider used internally by the GraphServiceClient has it's CAE setting set to True while the DeviceCodeCredential.authenticate method defaults it to False. Setting the value in authenticate explicitly to True makes the code work:

record = device_credential.authenticate(scopes=azure_settings["graphScope"], enable_cae=True)

But this leaves one issue - if (for some reason) someone wants to set the above value to False, they will never be able to make the code work using the current implementation of the GraphServiceClient.

Describe the solution you'd like.

It is my suggestion to add an argument to the GraphServiceClient initializer method to allow controlling the is_cae_enabled parameter of the AzureIdentityAuthenticationProvider object created inside.

Additional context?

No response

Vorherrschende Sprache
Python
Sterne
630
Forks
96
Ø Merge
15 Std. 20 Min.
Gemergte PRs (30 T.)
3

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus microsoftgraph/msgraph-sdk-python

Alle Issues in microsoftgraph/msgraph-sdk-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.