Skip to content

Commit 7781909

Browse files
committed
Updating Auth
1 parent e01ce74 commit 7781909

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

articles/azure-app-configuration/use-variant-feature-flags-python.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ In this example, you create a Python Flask web app named _Quote of the Day_. Whe
6767

6868
1. Create a new file named *app.py* in the *QuoteOfTheDay* folder.
6969

70+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
71+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
72+
7073
```python
7174
import os
7275
from azure.appconfiguration.provider import load
@@ -125,7 +128,62 @@ In this example, you create a Python Flask web app named _Quote of the Day_. Whe
125128
from . import routes
126129
app.register_blueprint(routes.bp)
127130
```
128-
131+
### [Connection string](#tab/connection-string)
132+
```python
133+
import os
134+
from azure.appconfiguration.provider import load
135+
from featuremanagement import FeatureManager
136+
from featuremanagement.azuremonitor import publish_telemetry
137+
from opentelemetry import trace
138+
from opentelemetry.trace import get_tracer_provider
139+
from flask_bcrypt import Bcrypt
140+
141+
from flask_sqlalchemy import SQLAlchemy
142+
from flask_login import LoginManager
143+
144+
from flask import Flask
145+
146+
app = Flask(__name__, template_folder="../templates", static_folder="../static")
147+
bcrypt = Bcrypt(app)
148+
149+
tracer = trace.get_tracer(__name__, tracer_provider=get_tracer_provider())
150+
151+
def callback():
152+
app.config.update(azure_app_config)
153+
154+
global azure_app_config
155+
azure_app_config = load(
156+
connection_string=os.getenv("AzureAppConfigurationConnectionString"),
157+
on_refresh_success=callback,
158+
feature_flag_enabled=True,
159+
feature_flag_refresh_enabled=True,
160+
)
161+
app.config.update(azure_app_config)
162+
feature_manager = FeatureManager(azure_app_config, on_feature_evaluated=publish_telemetry)
163+
164+
db = SQLAlchemy()
165+
db.init_app(app)
166+
167+
login_manager = LoginManager()
168+
login_manager.init_app(app)
169+
170+
171+
from .model import Users
172+
173+
@login_manager.user_loader
174+
def loader_user(user_id):
175+
return Users.query.get(user_id)
176+
177+
with app.app_context():
178+
db.create_all()
179+
180+
if __name__ == "__main__":
181+
app.run(debug=True)
182+
183+
from . import routes
184+
app.register_blueprint(routes.bp)
185+
```
186+
---
129187
1. Create a new file called *model.py* in the *QuoteOfTheDay* folder.
130188
131189
```python
@@ -539,6 +597,28 @@ In this example, you create a Python Flask web app named _Quote of the Day_. Whe
539597
export AzureAppConfigurationEndpoint='endpoint-of-your-app-configuration-store'
540598
```
541599
600+
### [Connection string](#tab/connection-string)
601+
Set the environment variable named **ConnectionString** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
602+
603+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
604+
605+
```cmd
606+
setx AzureAppConfigurationConnectionString "connection-string-of-your-app-configuration-store"
607+
```
608+
609+
If you use PowerShell, run the following command:
610+
611+
```powershell
612+
$Env:AzureAppConfigurationConnectionString = "connection-string-of-your-app-configuration-store"
613+
```
614+
615+
If you use macOS or Linux, run the following command:
616+
617+
```bash
618+
export AzureAppConfigurationConnectionString='connection-string-of-your-app-configuration-store'
619+
```
620+
---
621+
542622
1. In the command prompt, in the *QuoteOfTheDay* folder, run: `flask run`.
543623
1. Wait for the app to start, and then open a browser and navigate to `http://localhost:5000/`.
544624
1. Once viewing the running application, select **Register** at the top right to register a new user.

0 commit comments

Comments
 (0)