This sample shows how to generate a Personal Access Token (PAT) using the Client Libraries and the PAT Lifecycle Management API. Requests to this API need to be authorized with an Azure Active Directory (AAD) access token.
This sample uses the PublicClientApplicationBuilder
from Microsoft Authentication Library (MSAL) rather than relying on the interactive pop-up dialog to get an AAD access token which is then used as a credential to authenticate requests to Azure DevOps. This is meant to be used in scenarios where you need to generate a PAT associated with an account that does not have interactive login rights.
Prerequisites
- .NET Framework 4.7.2 SDK
- An Application in your Azure Active Directory (Azure AD) tenant
- (optional) Visual Studio / Visual Studio Code
From a shell or command line:
git clone https://github.com/microsoft/azure-devops-auth-samples.git
Update the configuration file App.config
with the information about your AAD application, AAD credentials, and Azure DevOps organization.
From Visual Studio:
- Open the solution file
NonInteractivePatGenerationSample.sln
. - Build and run the project.
-- OR --
From the command line:
cd NonInteractivePatGenerationSample/NonInteractivePatGenerationSample
dotnet run