Skip to content

Commit 5a6b49a

Browse files
committed
Add additional comments for token caching.
1 parent 01a0ce6 commit 5a6b49a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

articles/postgresql/flexible-server/connect-python.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,14 @@ In this section, you add authentication code to your working directory and perfo
118118
sslmode = os.environ['SSLMODE']
119119

120120
# Use passwordless authentication via DefaultAzureCredential.
121+
# IMPORTANT! This code is for demonstration purposes only. DefaultAzureCredential() is invoked on every call.
122+
# In practice, it's better to persist the credential across calls and reuse it so you can take advantage of token
123+
# caching and minimize round trips to the identity provider. To learn more, see:
124+
# https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TOKEN_CACHING.md
125+
credential = DefaultAzureCredential()
126+
121127
# Call get_token() to get a token from Microsft Entra ID and add it as the password in the URI.
122128
# Note the requested scope parameter in the call to get_token, "https://ossrdbms-aad.database.windows.net/.default".
123-
credential = DefaultAzureCredential()
124129
password = credential.get_token("https://ossrdbms-aad.database.windows.net/.default").token
125130

126131
db_uri = f"postgresql://{dbuser}:{password}@{dbhost}/{dbname}?sslmode={sslmode}"

0 commit comments

Comments
 (0)