I have the following code for obtaining a secret from the Azure key vault:
public static async Task GetToken(string authority, string resource,
What is happening - your service principal doesn't have permissions to perform said operation. Take a look at this thread.
How do I fix an "Operation 'set' not allowed" error when creating an Azure KeyVault secret programmatically?