Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KeyVaultSeries.Core
/// <summary>
/// From
/// </summary>
public static class TokenBasedAccessHelper
public static async Task<string> GetToken(string authority, string resource, string scope)
var authContext = new AuthenticationContext(authority);
ClientCredential clientCred = new ClientCredential(ConfigurationManager.AppSettings["ClientId"],
AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred);
if (result == null)
throw new InvalidOperationException("Failed to obtain the JWT token");
return result.AccessToken;