-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
25 lines (20 loc) · 1.05 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// See https://aka.ms/new-console-template for more information
using Azure.Identity;
using Microsoft.Extensions.Configuration;
namespace AzureDevOpsPatGenerator;
public class Program
{
static async Task Main(string[] args)
{
var Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
const string azureDevOpsAppScope = "499b84ac-1321-427f-aa17-267ca6975798/.default";
var azureDevOpsOptions = Configuration.GetSection(nameof(AzureDevOps)).Get<AzureDevOps>() ?? throw new ArgumentException($"{nameof(AzureDevOps)} not configured correctly");
var credentials = new ClientSecretCredential(azureDevOpsOptions.TenantId, azureDevOpsOptions.ClientId, azureDevOpsOptions.ClientSecret);
var accessToken = await credentials.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { azureDevOpsAppScope }));
Console.WriteLine(accessToken.Token);
}
}