Skip to content

Commit ee0ae9c

Browse files
committed
Merged main into live
2 parents 780db16 + d74823a commit ee0ae9c

File tree

7 files changed

+237
-120
lines changed

7 files changed

+237
-120
lines changed

docs/repos/git/auth-overview.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,65 @@
11
---
22
title: Authenticate with your Git repos
33
titleSuffix: Azure Repos
4-
description: Choose between HTTPS, SSH, and personal access tokens to securely sign in to your Git repos.
4+
description: Learn how to authenticate with Azure Repos using Microsoft Entra OAuth tokens (recommended), personal access tokens, or SSH keys for secure Git operations.
55
ms.assetid: 138f12d0-e3fd-4fde-a727-1b39d45c05c4
66
ms.service: azure-devops-repos
77
ms.topic: conceptual
8-
ms.date: 07/11/2024
8+
ms.date: 07/02/2025
99
monikerRange: '<= azure-devops'
1010
ms.subservice: azure-devops-repos-git
11+
# customer-intent: As a developer, I want to understand the different authentication methods available for Azure Repos so I can choose the most secure option (Microsoft Entra OAuth tokens) for accessing my Git repositories.
1112
---
1213

1314
# Authentication with Azure Repos
1415

1516
[!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)]
1617

17-
Selecting the right authentication method is crucial for secure access to your Azure Repos and Azure DevOps Server Git repositories. Whether you're working from a command prompt or using a Git client that supports HTTPS or SSH, it's important to choose credentials that not only provide the necessary access but also limit the scope to what's needed for your tasks.
18+
Secure authentication is fundamental to protecting your Azure Repos and Azure DevOps Server Git repositories. With multiple authentication options available—Microsoft Entra OAuth tokens, Personal Access Tokens, and SSH keys—choosing the right method ensures both security and productivity for your development workflow.
1819

19-
Always revoke credentials when they're no longer required to maintain the security of your repositories. This approach ensures that you have the flexibility to work with your code securely and efficiently, while also safeguarding it against unauthorized access.
20+
**Microsoft Entra OAuth tokens are the recommended approach** for modern development teams, offering enhanced security through OAuth 2.0 standards and seamless integration with enterprise identity systems. Whether you're working from the command line, using Git clients, or integrating with CI/CD pipelines, selecting an authentication method with appropriate scope limits reduces security risks while maintaining the access you need.
21+
22+
Always revoke or rotate credentials when they're no longer needed. This practice maintains repository security and follows the principle of least privilege access.
2023

2124
## Authentication mechanisms
2225

23-
### Microsoft Entra OAuth tokens
26+
### Microsoft Entra OAuth tokens (Recommended)
27+
28+
[Microsoft Entra tokens](../../integrate/get-started/authentication/entra.md) are the **preferred authentication method** for Git operations and [REST APIs](/rest/api/azure/devops/). They offer enhanced security features and can be used wherever personal access tokens are used. These tokens are generated for a user principal or a [managed identity and/or service principal](../../integrate/get-started/authentication/service-principal-managed-identity.md).
29+
30+
**Quick start with Azure CLI**: You can obtain a Microsoft Entra token for immediate use with Git operations using the Azure CLI. This method is ideal for testing or one-time operations.
31+
32+
**For user authentication:**
33+
```bash
34+
az login
35+
az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query "accessToken" --output tsv
36+
```
2437

25-
[Microsoft Entra tokens](../../integrate/get-started/authentication/entra.md) are the preferred authentication for Git operations and [REST APIs](/rest/api/azure/devops/). They can be used wherever personal access tokens are used and generated for a user principal or a [managed identity and/or service principal](../../integrate/get-started/authentication/service-principal-managed-identity.md).
38+
**For service principal authentication:**
39+
First [sign in as the service principal](/cli/azure/authenticate-azure-cli), then obtain the token:
40+
```bash
41+
az login --service-principal -u <client-id> -p <client-secret> --tenant <tenant-id>
42+
az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query "accessToken" --output tsv
43+
```
2644

27-
Here's a helpful tip on how to get a one-time Microsoft Entra token from the Azure CLI to call git fetch: (When generating on behalf of a service principal, make sure to [login as the service principal](/cli/azure/authenticate-azure-cli) first.)
45+
**Example usage with Git:**
2846

2947
```powershell
3048
$accessToken = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query "accessToken" --output tsv
3149
git -c http.extraheader="AUTHORIZATION: bearer $accessToken" clone https://dev.azure.com/{yourOrgName}/{yourProjectName}/_git/{yourRepoName}
3250
```
3351

34-
### Personal access tokens
52+
### Personal access tokens (Alternative option)
53+
54+
> [!NOTE]
55+
> While Personal Access Tokens are still supported, **Microsoft Entra OAuth tokens are recommended** for better security and modern authentication practices.
3556
3657
[Personal access tokens (PATs)](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) provide access to Azure DevOps without using your username and password directly. These tokens expire and allow you to restrict the scope of the data they can access.
3758

38-
Use PATs to authenticate if you don't have SSH keys set up on your system or need to limit the permissions granted by the credential.
59+
**Use PATs when:**
60+
- You don't have SSH keys set up on your system
61+
- You need to limit the permissions granted by the credential
62+
- Microsoft Entra OAuth tokens aren't available in your scenario
3963

4064
Git interactions require a username, which can be anything except an empty string. To use a PAT with HTTP basic authentication, `Base64-encode` your `$MyPat` as shown in the following code block.
4165

@@ -67,12 +91,12 @@ git --config-env=http.extraheader=HEADER_VALUE clone https://dev.azure.com/yourO
6791
### SSH keys
6892

6993
Key authentication with SSH works through a public and private key pair that you create on your computer.
70-
You associate the public key with your username from the web. Azure DevOps will encrypt the data sent to you with that key when you work with Git.
94+
You associate the public key with your username from the web. Azure DevOps encrypts the data sent to you with that key when you work with Git.
7195
You decrypt the data on your computer with the private key, which is never shared or sent over the network.
7296

7397
![Animated GIF showing adding of a SSH public key to Azure DevOps](media/ssh_add_public_key.gif)
7498

75-
SSH is a great option if you've already got it set up on your system&mdash;just add a public key to Azure DevOps and clone your repos using SSH. SSH might be preferred for those on Linux, macOS, or Windows running [Git for Windows](https://www.git-scm.com/download/win) who can't use [Git credential managers](../../repos/git/set-up-credential-managers.md) or [personal access tokens](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) for HTTPS authentication.
99+
SSH is a great option if it's already set up on your system&mdash;just add a public key to Azure DevOps and clone your repos using SSH. SSH might be preferred for Linux, macOS, or Windows running [Git for Windows](https://www.git-scm.com/download/win) who can't use [Git credential managers](../../repos/git/set-up-credential-managers.md) or [personal access tokens](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) for HTTPS authentication.
76100

77101
For more information, see [Set up SSH with Azure DevOps](use-ssh-keys-to-authenticate.md).
78102

@@ -102,7 +126,8 @@ Use the [Git Credential Manager (GCM)](set-up-credential-managers.md) to avoid e
102126

103127
Replace `{organization}` with your Azure DevOps organization name and `{repository}` with the name of your repository.
104128

105-
## Related articles
129+
## Related content
130+
106131
- [Use Git Credential Manager to authenticate to Azure Repos](set-up-credential-managers.md)
107-
- [About security, authentication, and authorization in Azure DevOps](../../organizations/security/about-security-identity.md)
108-
- [About permissions and security groups in Azure DevOps](../../organizations/security/about-permissions.md)
132+
- [Learn about security, authentication, and authorization in Azure DevOps](../../organizations/security/about-security-identity.md)
133+
- [Learn about permissions and security groups in Azure DevOps](../../organizations/security/about-permissions.md)

docs/repos/git/clone.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to create a local clone of any remote Git repo using Visu
55
ms.assetid: b6240e2f-2d3d-4874-9953-7e554d5e3b97
66
ms.service: azure-devops-repos
77
ms.topic: tutorial
8-
ms.date: 10/19/2022
8+
ms.date: 07/02/2025
99
monikerRange: '<= azure-devops'
1010
ms.subservice: azure-devops-repos-git
1111
---
@@ -71,8 +71,8 @@ Typically, you need to know the clone URL of the remote repo that you want to cl
7171

7272
:::image type="content" source="media/clone/visual-studio-2019/common/github-clone-repo.png" border="true" alt-text="Screenshot of the Clone popup on the page on the GitHub site." lightbox="media/clone/visual-studio-2019/common/github-clone-repo-lrg.png":::
7373

74-
> [!IMPORTANT]
75-
> The "Generate Git Credentials" button will be removed in January 2025, to reduce creation of unnecessary and underutilized personal access tokens. Review the Git Authentication docs for all authentication methods available to you for git clone operations.
74+
> [!TIP]
75+
> **Microsoft Entra ID tokens are the recommended authentication method** for Git operations. The "Generate Git Credentials" button was removed in January 2025 to encourage the use of more secure authentication methods. For all available authentication options, including the preferred Microsoft Entra OAuth tokens, see the [Authentication overview](auth-overview.md).
7676
7777
## Clone an Azure Repos Git repo
7878

@@ -105,7 +105,7 @@ Visual Studio 2019 version 16.8 and later versions provides a Git version contro
105105

106106
:::image type="content" source="media/clone/visual-studio-2019/team-explorer/connect-add-server.png" border="true" alt-text="Screenshot of the 'Connect to a Project' window in Visual Studio 2019." lightbox="media/clone/visual-studio-2019/team-explorer/connect-add-server-lrg.png":::
107107

108-
After you've cloned a remote Git repo, Visual Studio detects the local clone and adds it to the list of **Local Repositories** in the **Git** menu.
108+
After you clone a remote Git repo, Visual Studio detects the local clone and adds it to the list of **Local Repositories** in the **Git** menu.
109109

110110
:::image type="content" source="media/clone/visual-studio-2019/common/local-repositories.png" border="true" alt-text="Screenshot of the 'Local Repositories' option in the Git menu in Visual Studio 2019." lightbox="media/clone/visual-studio-2019/common/local-repositories-lrg.png":::
111111

@@ -165,15 +165,15 @@ You can clone any Git repo that's accessible to you by using the clone URL of th
165165

166166
:::image type="content" source="media/clone/visual-studio-2019/team-explorer/clone-remote-repo.png" border="true" alt-text="Screenshot of the Clone options in the 'Local Git Repositories' section of the 'Team Explorer' Connect view in Visual Studio 2019." lightbox="media/clone/visual-studio-2019/team-explorer/clone-remote-repo-lrg.png":::
167167

168-
After you've cloned a remote Git repo, Visual Studio detects the local clone and adds it to the list of **Local Repositories** in the **Git** menu.
168+
After you clone a remote Git repo, Visual Studio detects the local clone and adds it to the list of **Local Repositories** in the **Git** menu.
169169

170170
:::image type="content" source="media/clone/visual-studio-2019/common/local-repositories.png" border="true" alt-text="Screenshot of the 'Local Repositories' option from the Git menu in Visual Studio 2019." lightbox="media/clone/visual-studio-2019/common/local-repositories-lrg.png":::
171171

172172
#### [Git Command Line](#tab/git-command-line)
173173

174174
1. If you haven't already, [download and install Git](http://git-scm.com/download). Enable [Git Credential Manager](set-up-credential-managers.md) when prompted during the install, or [configure SSH authentication](use-ssh-keys-to-authenticate.md).
175175

176-
1. At the command prompt, run the Git clone command with the [clone URL](#clone_url) of the remote repo. This command will create a local clone repo under the current folder.
176+
1. At the command prompt, run the Git clone command with the [clone URL](#clone_url) of the remote repo. This command creates a local clone repo under the current folder.
177177

178178
```console
179179
git clone <clone URL>

docs/repos/git/create-pr-status-server-with-azure-functions.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Create a serverless function to listen to pull request events and p
55
ms.assetid:
66
ms.service: azure-devops-repos
77
ms.topic: conceptual
8-
ms.date: 02/14/2025
8+
ms.date: 07/02/2025
99
monikerRange: '<= azure-devops'
1010
ms.subservice: azure-devops-repos-git
1111
---
@@ -14,7 +14,7 @@ ms.subservice: azure-devops-repos-git
1414

1515
[!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)]
1616

17-
The pull request (PR) workflow allows developers to receive feedback on their code from peers and automated tools. Non-Microsoft tools and services can also participate in the PR workflow by using the PR [Status API](/rest/api/azure/devops/git/pull%20request%20statuses). This article guides you through creating a custom branch policy using [Azure Functions](https://azure.microsoft.com/services/functions/) to validate PRs in an Azure DevOps Git repository. Azure Functions eliminate the need to provision and maintain servers, even as your workload grows. They provide a fully managed compute platform with high reliability and security.
17+
The pull request (PR) workflow allows developers to receive feedback on their code from peers and automated tools. Non-Microsoft tools and services can also participate in the PR workflow by using the PR [Status API](/rest/api/azure/devops/git/pull%20request%20statuses). This article guides you through creating a custom branch policy using [Azure Functions](https://azure.microsoft.com/services/functions/) to validate PRs in an Azure DevOps Git repository. Azure Functions eliminates the need to provision and maintain servers, even as your workload grows. They provide a fully managed compute platform with high reliability and security.
1818

1919
For more information about PR status, see [Customize and extend pull request workflows with pull request status](pull-request-status.md).
2020

@@ -25,7 +25,7 @@ For more information about PR status, see [Customize and extend pull request wor
2525
| **Organization** | An [organization in Azure DevOps](../../organizations/accounts/create-organization.md) with a Git repository. |
2626
| **Azure Function** | An [Azure Function](#create-a-basic-azure-function-to-listen-to-azure-repos-events), which implements a serverless, event-driven solution that integrates with Azure DevOps to create custom branch policies and automate PR validation.|
2727
| **Service Hooks** | [Configure service hooks](#configure-a-service-hook-for-pr-events) for PR events to notify your Azure function when a pull request changes. |
28-
| **Personal Access Token (PAT)** | Create a PAT with the **Code (status)** scope to have permission to change PR status. For more information, see [Use PATs to authenticate](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md). |
28+
| **Authentication** | **Microsoft Entra ID token** with the **Code (status)** scope to have permission to change PR status. For more information, see [Microsoft Entra authentication](../../integrate/get-started/authentication/entra.md). |
2929

3030
### Create a basic Azure Function to listen to Azure Repos events
3131

@@ -140,13 +140,13 @@ Now that your server can receive service hook events when new PRs are created, u
140140
141141
Update the code of your Azure function, similar to the following example.
142142
143-
Make sure to update the code with your organization name, project name, repository name, and [PAT token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md). In order to have permission to change PR status, the PAT requires [vso.code_status](../../integrate/get-started/authentication/oauth.md#scopes) scope, which you can grant by selecting the **Code (status)** scope on the **Create a personal access token** page.
143+
Make sure to update the code with your organization name, project name, repository name, and Microsoft Entra ID token. In order to have permission to change PR status, the token requires [vso.code_status](../../integrate/get-started/authentication/oauth.md#scopes) scope, which you can obtain through Microsoft Entra authentication.
144144
145145
>[!Important]
146-
>This sample code stores the PAT in code, simplifying the sample. It is recommended to store secrets in KeyVault and retrieve them from there.
146+
>This sample code stores the token in code, simplifying the sample. It is recommended to store secrets in Azure Key Vault and retrieve them from there using managed identity for enhanced security.
147147
148148
149-
This sample inspects the PR title to see if the user indicated if the PR is a work in progress by adding **WIP** to the title. If so, the sample code changes the status posted back to the PR. Replace the code in your Azure function with the following code which updates the status posted back to the PR.
149+
This sample inspects the PR title to see if the user indicated if the PR is a work in progress by adding **WIP** to the title. If so, the sample code changes the status posted back to the PR. Replace the code in your Azure function with the following code, which updates the status posted back to the PR.
150150
151151
```cs
152152
using System;
@@ -162,9 +162,9 @@ private static string repositoryName = "[Repo Name]"; // Repository n
162162
163163
/*
164164
This is here just to simplify the sample, it is recommended to store
165-
secrets in KeyVault and retrieve them from there.
165+
secrets in Azure Key Vault and retrieve them using managed identity.
166166
*/
167-
private static string pat = "[PAT TOKEN]";
167+
private static string accessToken = "[MICROSOFT_ENTRA_TOKEN]";
168168
169169
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
170170
{
@@ -215,9 +215,7 @@ private static void PostStatusOnPullRequest(int pullRequestId, string status)
215215
using (HttpClient client = new HttpClient())
216216
{
217217
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
218-
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
219-
ASCIIEncoding.ASCII.GetBytes(
220-
string.Format("{0}:{1}", "", pat))));
218+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
221219
222220
var method = new HttpMethod("POST");
223221
var request = new HttpRequestMessage(method, Url)

0 commit comments

Comments
 (0)