Azure-Samples / ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
293 stars 138 forks source link

Add devcontainer and Azure CLI script #101

Open pamelafox opened 1 year ago

pamelafox commented 1 year ago

The original goal of this pull request was to add a Dev Container configuration, but I realized it was easier to rewrite the scripts using the Azure CLI than get Powershell working inside a Dev Container on my Mac.

So, this PR does two things:

1) Adds a dev container config that creates a Python environment with the azure-cli installed in it 2) Replaces the Powershell scripts with bash scripts that use the Azure CLI scripts. It's possible the scripts don't have every capability of the original Powershell scripts, but they definitely take care of the steps from https://learn.microsoft.com/en-us/azure/active-directory/develop/web-app-quickstart?pivots=devlang-python&tabs=windows, and it's a pretty pleasant process. Try it out!

Example of using them:

vscode ➜ /workspaces/ms-identity-python-webapp (devcontainer) $ ./scripts/configure.sh
Extension 'account' 0.2.5 is already installed.
Attempting login to Azure...
A web browser has been opened at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
The following tenants don't contain accessible subscriptions. Use 'az login --allow-no-subscriptions' to have tenant level access.
2f32b846-1945-4cf2-a2ca-087cf844c482 'PythonPythonPython'
The following tenants require Multi-Factor Authentication (MFA). Use 'az login --tenant TENANT_ID' to explicitly login to a tenant.
12c2c747-3cbe-4a7d-9af6-a151055e24d4 'PythonB2C'
Attempting app registration creation...
Attempting to add a client secret to app 06362acb-91a0-4adc-aad5-a7ea6349dd18 ...
WARNING: The output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control. For more information, see https://aka.ms/azadsp-cli
Attempting to grant permissions for app 06362acb-91a0-4adc-aad5-a7ea6349dd18 to Microsoft Graph API User.ReadBasic.All...
Creating .env file...
Writing configuration to .env file...
Configuration complete.
vscode ➜ /workspaces/ms-identity-python-webapp (devcontainer) $ ./scripts/cleanup.sh 
Attempting to delete service principal with ID 02b2153f-6467-438d-ab72-c2390875e39d
Attempting to delete app with ID 06362acb-91a0-4adc-aad5-a7ea6349dd18
All associated resources are cleaned up.
pamelafox commented 1 year ago

@rayluo I'm excited about this PR!