Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into live #42319

Merged
merged 7 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .openpublishing.redirection.csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0246.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/assembly-references"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0260.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1683.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/assembly-references"
Expand Down Expand Up @@ -363,6 +367,10 @@
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0854.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1067.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-types"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1704.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/assembly-references"
Expand Down Expand Up @@ -463,6 +471,14 @@
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8401.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/feature-version-errors"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8795.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-types"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8817.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-types"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs8892.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/warning-waves#cs8892"
Expand Down Expand Up @@ -1501,6 +1517,38 @@
"source_path_from_root": "/docs/csharp/misc/cs0251.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/feature-version-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0261.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0262.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0263.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0264.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0265.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0267.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0282.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0501.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0400.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/assembly-references"
Expand Down Expand Up @@ -1617,10 +1665,54 @@
"source_path_from_root": "/docs/csharp/misc/cs0748.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#lambda-expression-parameters-and-returns"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0750.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0751.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0754.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0755.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0756.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0757.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0758.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0759.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0761.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0762.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0763.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0764.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/partial-declarations"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0765.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions"
Expand Down
112 changes: 81 additions & 31 deletions docs/azure/sdk/authentication/additional-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,92 @@ This method interactively authenticates an application through [`InteractiveBrow

Interactive browser authentication enables the application for all operations allowed by the interactive login credentials. As a result, if you're the owner or administrator of your subscription, your code has inherent access to most resources in that subscription without having to assign any specific permissions. For this reason, the use of interactive browser authentication is discouraged for anything but experimentation.

### Enable applications for interactive browser authentication

Perform the following steps to enable the application to authenticate through the interactive browser flow. These steps also work for the [device code authentication](#device-code-authentication) flow described later. This process is only necessary if you are using `InteractiveBrowserCredential` in your code.

1. In the [Azure portal](https://portal.azure.com), navigate to **Microsoft Entra ID** and select **App registrations** on the left navigation.
1. Select the registration for your app, then select **Authentication**.
1. Under **Advanced settings**, select **Yes** for **Allow public client flows**.
1. Select **Save** to apply the changes.
1. To authorize the application for specific resources, navigate to the resource in question, select **API Permissions**, and enable **Microsoft Graph** and other resources you want to access. Microsoft Graph is usually enabled by default.

> [!IMPORTANT]
> You must also be the admin of your tenant to grant consent to your application when you sign in for the first time.

### Example using InteractiveBrowserCredential

The following example demonstrates using an [`InteractiveBrowserCredential`](/dotnet/api/azure.identity.interactivebrowsercredential) to authenticate with the [`BlobServiceClient`](/dotnet/api/azure.storage.blobs.blobserviceclient):

```csharp
using Azure.Identity;
using Azure.Storage.Blobs;
:::code language="csharp" source="../snippets/additional-auth/interactive/InteractiveBrowserAuth.cs" highlight="15-17":::

var client = new BlobServiceClient(
new Uri("https://<storage-account-name>.blob.core.windows.net"),
new InteractiveBrowserCredential());
For more exact control, such as setting redirect URIs, you can supply specific arguments to `InteractiveBrowserCredential` such as `redirect_uri`.

foreach (var blobItem in client.GetBlobContainers())
{
Console.WriteLine(blobItem.Name);
}
```
## Interactive brokered authentication

For more exact control, such as setting redirect URIs, you can supply specific arguments to `InteractiveBrowserCredential` such as `redirect_uri`.
This method interactively authenticates an application through [`InteractiveBrowserCredential`](/dotnet/api/azure.identity.interactivebrowsercredential?view=azure-dotnet) by collecting user credentials using the system authentication broker. A system authentication broker is an app running on a user's machine that manages the authentication handshakes and token maintenance for all connected accounts. Currently, only the Windows authentication broker, Web Account Manager (WAM), is supported. Users on macOS and Linux will be authenticated through the non-brokered interactive browser flow.

WAM enables identity providers such as Microsoft Entra ID to natively plug into the OS and provide the service to other apps to provide a more secure login process. WAM offers the following benefits:

- **Feature support**: Apps can access OS-level and service-level capabilities, including Windows Hello, conditional access policies, and FIDO keys.
- **Streamlined single sign-on**: Apps can use the built-in account picker, allowing the user to select an existing account instead of repeatedly entering the same credentials.
- **Enhanced security**: Bug fixes and enhancements ship with Windows.
- **Token protection**: Refresh tokens are device-bound, and apps can acquire device-bound access tokens.

Interactive brokered authentication enables the application for all operations allowed by the interactive login credentials. Personal Microsoft accounts and work or school accounts are supported. If a supported version of Windows is used, the default browser-based UI is replaced with a smoother authentication experience, similar to Windows built-in apps.

### Enable applications for interactive brokered authentication

Perform the following steps to enable the application to authenticate through the interactive broker flow.

1. On the [Azure portal](https://portal.azure.com), navigate to **Microsoft Entra ID** and select **App registrations** on the left-hand menu.
1. Select the registration for your app, then select **Authentication**.
1. Add the WAM redirect URI to your app registration via a platform configuration:
1. Under **Platform configurations**, select **+ Add a platform**.
1. Under **Configure platforms**, select the tile for your application type (platform) to configure its settings, such as **mobile and desktop applications**.
1. In **Custom redirect URIs**, enter the following WAM redirect URI:

```text
ms-appx-web://microsoft.aad.brokerplugin/{client_id}
```

The `{client_id}` placeholder must be replaced with the **Application (client) ID** listed on the **Overview** pane of the app registration.

1. Select **Configure**.

To learn more, see [Add a redirect URI to an app registration](/entra/identity-platform/quickstart-register-app#add-a-redirect-uri).

1. Back on the **Authentication** pane, under **Advanced settings**, select **Yes** for **Allow public client flows**.
1. Select **Save** to apply the changes.
1. To authorize the application for specific resources, navigate to the resource in question, select **API Permissions**, and enable **Microsoft Graph** and other resources you want to access. Microsoft Graph is usually enabled by default.

> [!IMPORTANT]
> You must also be the admin of your tenant to grant consent to your application when you sign in for the first time.

### Example using InteractiveBrowserCredential

The following example demonstrates using an [`InteractiveBrowserCredential`](/dotnet/api/azure.identity.interactivebrowsercredential?view=azure-dotnet) in a Windows Forms app to authenticate with the [`BlobServiceClient`](/dotnet/api/azure.storage.blobs.blobserviceclient):

:::code language="csharp" source="../snippets/additional-auth/interactive/InteractiveBrokeredAuth.cs" highlight="16-20":::

> [!NOTE]
> Visit the [Parent window handles](/entra/msal/dotnet/acquiring-tokens/desktop-mobile/wam#parent-window-handles) and [Retrieve a window handle](/windows/apps/develop/ui-input/retrieve-hwnd) articles for more information about retrieving window handles.

For the code to run successfully, your user account must be assigned an Azure role on the storage account that allows access to blob containers such as **Storage Account Data Contributor**. If an app is specified, it must have API permissions set for **user_impersonation Access Azure Storage** (step 6 in the previous section). This API permission allows the app to access Azure storage on behalf of the signed-in user after consent is granted during sign-in.

The following screenshot shows the user sign-in experience:

:::image type="content" source="../media/web-account-manager-sign-in-account-picker.png" alt-text="A screenshot that shows the sign-in experience when using the interactive browser broker credential to authenticate a user." :::

### Authenticate the default system account via WAM

Many people always sign in to Windows with the same user account and, therefore, only ever want to authenticate using that account. WAM and `InteractiveBrowserCredential` also support a silent login process that automatically uses a default account so the user doesn't have to repeatedly select it.

The following example shows how to enable sign-in with the default system account:

:::code language="csharp" source="../snippets/additional-auth/interactive/SilentBrokeredAuth.cs" highlight="16-24":::

Once you opt into this behavior, the credential attempts to sign in by asking the underlying Microsoft Authentication Library (MSAL) to perform the sign-in for the default system account. If the sign-in fails, the credential falls back to displaying the account picker dialog, from which the user can select the appropriate account.

## Device code authentication

Expand All @@ -49,7 +116,7 @@ For more information, see [Microsoft identity platform and the OAuth 2.0 device

Device code authentication in a development environment enables the application for all operations allowed by the interactive login credentials. As a result, if you're the owner or administrator of your subscription, your code has inherent access to most resources in that subscription without having to assign any specific permissions. However, you can use this method with a specific client ID, rather than the default, for which you can assign specific permissions.

## Authentication with a username and password
## Username and password authentication

This method authenticates an application using previously collected credentials and the [UsernamePasswordCredential](/dotnet/api/azure.identity.usernamepasswordcredential) object.

Expand All @@ -58,21 +125,4 @@ This method authenticates an application using previously collected credentials
>
> Furthermore, this method authenticates only work and school accounts; Microsoft accounts aren't supported. For more information, see [Sign up your organization to use Microsoft Entra ID](/entra/fundamentals/sign-up-organization).

```csharp
using Azure.Identity;
using Azure.Storage.Blobs;

var clientId = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
var tenantId = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
var username = Environment.GetEnvironmentVariable("AZURE_USERNAME");
var password = Environment.GetEnvironmentVariable("AZURE_PASSWORD");

var client = new BlobServiceClient(
new Uri("https://<storage-account-name>.blob.core.windows.net"),
new UsernamePasswordCredential(username, password, tenantId, clientId));

foreach (var blobItem in client.GetBlobContainers())
{
Console.WriteLine(blobItem.Name);
}
```
:::code language="csharp" source="../snippets/additional-auth/username-password/Program.cs" highlight="9-11":::
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading