Skip to content

Commit 48ee116

Browse files
alexwolfmsftscottaddiechristothes
authored
Update visual studio code auth content and diagrams (dotnet#48182)
* update visual studio code auth content * fixes * fix image * fix diagram * trim image * images * standardize * fix link * fixes * added broker section * fix image * diagram fixes * PR changes * update images * Apply suggestions from code review Co-authored-by: Scott Addie <[email protected]> * image changes * Feedback changes * add vs code flow * add package * edit pass * fix blank lines * move vs code tab * fix diagram and tabs * fix image name * fix intro * fix cli verbiage * Apply suggestions from code review Co-authored-by: Scott Addie <[email protected]> * Apply suggestions from code review * fixes * fixes * fix link * Apply suggestions from code review Co-authored-by: Scott Addie <[email protected]> * Apply suggestions from code review Co-authored-by: Christopher Scott <[email protected]> * refactor intro * fix link * refactor --------- Co-authored-by: Scott Addie <[email protected]> Co-authored-by: Christopher Scott <[email protected]>
1 parent a59ffda commit 48ee116

12 files changed

+127
-14
lines changed

docs/azure/sdk/authentication/index.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ Use of connection strings should be limited to scenarios where token-based authe
3232

3333
The specific type of token-based authentication an app should use to authenticate to Azure resources depends on where the app runs. The following diagram provides guidance for different scenarios and environments:
3434

35-
:::image type="content" source="../media/dotnet-sdk-auth-strategy.png" alt-text="A diagram showing the recommended token-based authentication strategies for an app depending on where it's running." :::
35+
:::image type="content" source="../media/mermaidjs/authentication-environments.svg" alt-text="A diagram showing the recommended token-based authentication strategies for an app depending on where it's running." :::
3636

3737
When an app is:
3838

3939
- **Hosted on Azure**: The app should authenticate to Azure resources using a managed identity. This option is discussed in more detail at [authentication in server environments](#authentication-for-azure-hosted-apps).
40-
- **Running locally during development**: The app can authenticate to Azure using either an application service principal for local development or by using the developer's Azure credentials. Each option is discussed in more detail at [authentication during local development](#authentication-during-local-development).
41-
- **Hosted on-premises**: The app should authenticate to Azure resources using an application service principal, or a managed identity in the case of Azure Arc. On-premises workflows are discussed in more detail at [authentication in server environments](#authentication-for-apps-hosted-on-premises).
40+
- **Running locally during development**: The app can authenticate to Azure using a [developer account](local-development-dev-accounts.md), a [broker](local-development-broker.md), or a [service principal](local-development-service-principal.md). Each option is discussed in more detail at [authentication during local development](#authentication-during-local-development).
41+
- **Hosted on-premises**: The app should authenticate to Azure resources using an application service principal, or a managed identity in the case of Azure Arc. On-premises workflows are discussed in more detail at [Authentication for apps hosted on-premises](#authentication-for-apps-hosted-on-premises).
4242

4343
## Authentication for Azure-hosted apps
4444

@@ -69,6 +69,13 @@ You can use your own Azure credentials to authenticate to Azure resources during
6969
> [!div class="nextstepaction"]
7070
> [Authenticate locally using developer credentials](local-development-dev-accounts.md)
7171
72+
#### Use a broker
73+
74+
Brokered authentication collects user credentials using the system authentication broker to authenticate an app. A system authentication broker runs on a user's machine and manages the authentication handshakes and token maintenance for all connected accounts.
75+
76+
> [!div class="nextstepaction"]
77+
> [Authenticate locally using a broker](local-development-broker.md)
78+
7279
#### Use a service principal
7380

7481
A service principal is created in a Microsoft Entra tenant to represent an app and be used to authenticate to Azure resources. You can configure your app to use service principal credentials during local development. This method is more secure than using developer credentials and is closer to how your app will authenticate in production. However, it's still less ideal than using a managed identity due to the need for secrets.

docs/azure/sdk/authentication/local-development-dev-accounts.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,28 @@ ms.custom:
1212

1313
# Authenticate .NET apps to Azure services during local development using developer accounts
1414

15-
During local development, applications need to authenticate to Azure to access various Azure services. Two common approaches for local authentication are to [use a service principal](local-development-service-principal.md) or to use a developer account. This article explains how to use a developer account. In the sections ahead, you learn:
15+
During local development, applications need to authenticate to Azure to use different Azure services. Authenticate locally using one of these approaches:
1616

17-
- How to use Microsoft Entra groups to efficiently manage permissions for multiple developer accounts
18-
- How to assign roles to developer accounts to scope permissions
19-
- How to sign-in to supported local development tools
20-
- How to authenticate using a developer account from your app code
17+
- Use a developer account with one of the [developer tools supported by the Azure Identity library](#supported-developer-tools-for-authentication).
18+
- Use a [broker](local-development-broker.md) to manage credentials.
19+
- Use a [service principal](local-development-service-principal.md).
2120

22-
:::image type="content" source="../media/local-dev-dev-accounts-overview.png" alt-text="A diagram showing an app running in local development using a developer tool identity to connect to Azure resources.":::
21+
This article explains how to authenticate using a developer account with tools supported by the Azure Identity library. In the sections ahead, you learn:
22+
23+
- How to use Microsoft Entra groups to efficiently manage permissions for multiple developer accounts.
24+
- How to assign roles to developer accounts to scope permissions.
25+
- How to sign-in to supported local development tools.
26+
- How to authenticate using a developer account from your app code.
27+
28+
## Supported developer tools for authentication
2329

2430
For an app to authenticate to Azure during local development using the developer's Azure credentials, the developer must be signed-in to Azure from one of the following developer tools:
2531

2632
- Azure CLI
2733
- Azure Developer CLI
2834
- Azure PowerShell
2935
- Visual Studio
36+
- Visual Studio Code
3037

3138
The Azure Identity library can detect that the developer is signed-in from one of these tools. The library can then obtain the Microsoft Entra access token via the tool to authenticate the app to Azure as the signed-in user.
3239

@@ -44,9 +51,30 @@ Next, sign-in to Azure using one of several developer tools that can be used to
4451

4552
[!INCLUDE [auth-visual-studio](../includes/auth-visual-studio.md)]
4653

54+
### [Visual Studio Code](#tab/sign-in-visual-studio-code)
55+
56+
Developers using Visual Studio Code can authenticate with their developer account directly through the editor via the broker. Apps that use <xref:Azure.Identity.DefaultAzureCredential> or <xref:Azure.Identity.VisualStudioCodeCredential> can then use this account to authenticate app requests through a seamless single-sign-on experience.
57+
58+
1. In Visual Studio Code, go to the **Extensions** panel and install the [Azure Resources](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureresourcegroups) extension. This extension lets you view and manage Azure resources directly from Visual Studio Code. It also uses the built-in Visual Studio Code Microsoft authentication provider to authenticate with Azure.
59+
60+
:::image type="content" source="../media/azure-resources-extension.png" alt-text="Screenshot showing the Azure Resources extension.":::
61+
62+
1. Open the Command Palette in Visual Studio Code, then search for and select **Azure: Sign in**.
63+
64+
:::image type="content" source="../media/visual-studio-code-sign-in.png" alt-text="Screenshot showing how to sign in to Azure in Visual Studio Code.":::
65+
66+
> [!TIP]
67+
> Open the Command Palette using `Ctrl+Shift+P` on Windows/Linux or `Cmd+Shift+P` on macOS.
68+
69+
1. Add the [Azure.Identity.Broker](https://www.nuget.org/packages/Azure.Identity.Broker) NuGet package to your app:
70+
71+
```dotnetcli
72+
dotnet add package Azure.Identity.Broker
73+
```
74+
4775
### [Azure CLI](#tab/sign-in-azure-cli)
4876
49-
Developers coding outside of an IDE can also use the [Azure CLI](/cli/azure/what-is-azure-cli) to authenticate. Apps using `DefaultAzureCredential` or <xref:Azure.Identity.AzureCliCredential> can then use this account to authenticate app requests when running locally.
77+
Developers can use [Azure CLI](/cli/azure/what-is-azure-cli) to authenticate. Apps using <xref:Azure.Identity.DefaultAzureCredential> or <xref:Azure.Identity.AzureCliCredential> can then use this account to authenticate app requests.
5078
5179
To authenticate with the Azure CLI, run the `az login` command. On a system with a default web browser, the Azure CLI launches the browser to authenticate the user.
5280
@@ -62,23 +90,23 @@ az login --use-device-code
6290

6391
### [Azure Developer CLI](#tab/sign-in-azure-developer-cli)
6492

65-
Developers coding outside of an IDE can also use the [Azure Developer CLI](/azure/developer/azure-developer-cli/overview) to authenticate. Apps using `DefaultAzureCredential` or <xref:Azure.Identity.AzureDeveloperCliCredential> can then use this account to authenticate app requests when running locally.
93+
Developers can use [Azure Developer CLI](/azure/developer/azure-developer-cli/overview) to authenticate. Apps using <xref:Azure.Identity.DefaultAzureCredential> or <xref:Azure.Identity.AzureDeveloperCliCredential> can then use this account to authenticate app requests.
6694

6795
To authenticate with the Azure Developer CLI, run the `azd auth login` command. On a system with a default web browser, the Azure Developer CLI launches the browser to authenticate the user.
6896

6997
```azdeveloper
7098
azd auth login
7199
```
72100

73-
For systems without a default web browser, the `azd auth login --use-device-code` uses the device code authentication flow. The user can also force the the Azure Developer CLI to use the device code flow rather than launching a browser by specifying the `--use-device-code` argument.
101+
For systems without a default web browser, the `azd auth login --use-device-code` uses the device code authentication flow. The user can also force the Azure Developer CLI to use the device code flow rather than launching a browser by specifying the `--use-device-code` argument.
74102

75103
```azdeveloper
76104
azd auth login --use-device-code
77105
```
78106

79107
### [Azure PowerShell](#tab/sign-in-azure-powershell)
80108

81-
Developers coding outside of an IDE can also use [Azure PowerShell](/powershell/azure/what-is-azure-powershell) to authenticate. Apps using `DefaultAzureCredential` or <xref:Azure.Identity.AzurePowerShellCredential> can then use this account to authenticate app requests when running locally.
109+
Developers can use [Azure PowerShell](/powershell/azure/what-is-azure-powershell) to authenticate. Apps using <xref:Azure.Identity.DefaultAzureCredential> or <xref:Azure.Identity.AzurePowerShellCredential> can then use this account to authenticate app requests.
82110

83111
To authenticate with Azure PowerShell, run the command `Connect-AzAccount`. On a system with a default web browser and version 5.0.0 or later of Azure PowerShell, it launches the browser to authenticate the user.
84112

docs/azure/sdk/authentication/local-development-service-principal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ During local development, applications need to authenticate to Azure to access v
2121

2222
Using dedicated application service principals allows you to adhere to the principle of least privilege when accessing Azure resources. Permissions are limited to the specific requirements of the app during development, preventing accidental access to Azure resources intended for other apps or services. This approach also helps avoid issues when the app is moved to production by ensuring it isn't over-privileged in the development environment.
2323

24-
:::image type="content" source="../media/local-dev-service-principal-overview.png" alt-text="A diagram showing how a local .NET app uses the developer's credentials to connect to Azure by using locally installed development tools.":::
24+
:::image type="content" source="../media/mermaidjs/local-service-principal-authentication.svg" alt-text="A diagram showing how a local .NET app uses a service principal to connect to Azure resources.":::
2525

2626
When the app is registered in Azure, an application service principal is created. For local development:
2727

14.7 KB
Loading
-86.7 KB
Loading
-40 KB
Binary file not shown.
-71.2 KB
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
ms.topic: include
3+
ms.date: 08/07/2024
4+
---
5+
6+
```mermaid
7+
%% STEPS TO GENERATE IMAGE
8+
%% =======================
9+
%% 1. Install mermaid CLI v10.9.1 (see https://github.com/mermaid-js/mermaid-cli/blob/master/README.md):
10+
%% npm i -g @mermaid-js/[email protected]
11+
%% 2. Run command: mmdc -i authentication-environments.md -o ../../media/mermaidjs/authentication-environments.svg
12+
13+
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor': '#fff', 'edgeLabelBackground':'#fff', 'fontSize': '24px'}}}%%
14+
flowchart LR
15+
NetApp[".NET app"]
16+
Q1{Where is the app running?}
17+
18+
NetApp --> Q1
19+
20+
%% Local Development Machine Branch
21+
Q1 --> LocalDev[Development machine]
22+
LocalDev --> AppSP["**Service principal**"]
23+
LocalDev --> UserPrincipal["**User principal**"]
24+
25+
%% Azure Branch
26+
Q1 --> AzureApp[Azure]
27+
AzureApp --> ManagedId["**Managed identity**"]
28+
29+
30+
%% On-premises Server Branch
31+
Q1 --> OnPremApp[On-premises server]
32+
OnPremApp --> ServicePrincipal["**Service principal**"]
33+
OnPremApp --> ArcManagedId["**Managed identity (Azure Arc only)**"]
34+
35+
%% Styling
36+
classDef questionBox fill:#4472C4,stroke:#333,stroke-width:2px,color:#fff,font-size:24px
37+
classDef authMethod fill:#e6f2ff,stroke:#4472C4,stroke-width:2px,color:#000,font-size:24px
38+
classDef envNode fill:#8fbc8f,stroke:#333,stroke-width:2px,color:#000,font-size:24px
39+
classDef startNode fill:#2d5f3f,stroke:#333,stroke-width:2px,color:#fff,font-size:24px
40+
41+
%% Edge label styling
42+
linkStyle default font-size:24px
43+
44+
class NetApp startNode
45+
class Q1 questionBox
46+
class AppSP,UserPrincipal,ManagedId,ServicePrincipal,ArcManagedId authMethod
47+
class LocalDev,AzureApp,OnPremApp envNode
48+
```

docs/azure/sdk/media/mermaidjs/authentication-environments.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
ms.topic: include
3+
ms.date: 08/07/2024
4+
---
5+
6+
```mermaid
7+
%% STEPS TO GENERATE IMAGE
8+
%% =======================
9+
%% 1. Install mermaid CLI v10.9.1 (see https://github.com/mermaid-js/mermaid-cli/blob/master/README.md):
10+
%% npm i -g @mermaid-js/[email protected]
11+
%% 2. Run command: mmdc -i local-service-principal-authentication.md -o ../../media/mermaidjs/local-service-principal-authentication.svg
12+
13+
flowchart LR
14+
APP["Local .NET app"]
15+
SP["App service principal stored in environment variables"]
16+
AS["Azure services"]
17+
18+
APP --> SP
19+
SP --> AS
20+
21+
classDef app fill:#e6f3ff,stroke:#0078d4,stroke-width:2px,color:#000,font-size:16px
22+
classDef serviceP fill:#D4F4D4,stroke:#7BC97B,stroke-width:2px,color:#000,font-size:16px
23+
classDef services fill:#0078d4,stroke:#005ba1,stroke-width:2px,color:#fff,font-size:16px
24+
25+
class APP app
26+
class SP serviceP
27+
class AS services
28+
```

0 commit comments

Comments
 (0)