|
1 | 1 | --- |
2 | 2 | title: Authenticate with your Git repos |
3 | 3 | 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. |
5 | 5 | ms.assetid: 138f12d0-e3fd-4fde-a727-1b39d45c05c4 |
6 | 6 | ms.service: azure-devops-repos |
7 | 7 | ms.topic: conceptual |
8 | | -ms.date: 07/11/2024 |
| 8 | +ms.date: 07/02/2025 |
9 | 9 | monikerRange: '<= azure-devops' |
10 | 10 | 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. |
11 | 12 | --- |
12 | 13 |
|
13 | 14 | # Authentication with Azure Repos |
14 | 15 |
|
15 | 16 | [!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)] |
16 | 17 |
|
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. |
18 | 19 |
|
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. |
20 | 23 |
|
21 | 24 | ## Authentication mechanisms |
22 | 25 |
|
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 | +``` |
24 | 37 |
|
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 | +``` |
26 | 44 |
|
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:** |
28 | 46 |
|
29 | 47 | ```powershell |
30 | 48 | $accessToken = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query "accessToken" --output tsv |
31 | 49 | git -c http.extraheader="AUTHORIZATION: bearer $accessToken" clone https://dev.azure.com/{yourOrgName}/{yourProjectName}/_git/{yourRepoName} |
32 | 50 | ``` |
33 | 51 |
|
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. |
35 | 56 |
|
36 | 57 | [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. |
37 | 58 |
|
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 |
39 | 63 |
|
40 | 64 | 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. |
41 | 65 |
|
@@ -67,12 +91,12 @@ git --config-env=http.extraheader=HEADER_VALUE clone https://dev.azure.com/yourO |
67 | 91 | ### SSH keys |
68 | 92 |
|
69 | 93 | 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. |
71 | 95 | You decrypt the data on your computer with the private key, which is never shared or sent over the network. |
72 | 96 |
|
73 | 97 |  |
74 | 98 |
|
75 | | -SSH is a great option if you've already got it set up on your system—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—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. |
76 | 100 |
|
77 | 101 | For more information, see [Set up SSH with Azure DevOps](use-ssh-keys-to-authenticate.md). |
78 | 102 |
|
@@ -102,7 +126,8 @@ Use the [Git Credential Manager (GCM)](set-up-credential-managers.md) to avoid e |
102 | 126 |
|
103 | 127 | Replace `{organization}` with your Azure DevOps organization name and `{repository}` with the name of your repository. |
104 | 128 |
|
105 | | -## Related articles |
| 129 | +## Related content |
| 130 | + |
106 | 131 | - [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) |
0 commit comments