Last active
July 7, 2021 14:50
-
-
Save asadrefai/b40b95bb4efc827c1402f3d7c85ae46b to your computer and use it in GitHub Desktop.
Gets the secret value from Azure Key Vault and establish SharePoint connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[FunctionName("Function1")] | |
public static async Task<IActionResult> Run( | |
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, | |
ILogger log) | |
{ | |
log.LogInformation("C# HTTP trigger function processed a request."); | |
const string secretName = "Test"; | |
var keyVaultName = "test-blog-kv"; | |
var kvUri = $"https://{keyVaultName}.vault.azure.net"; | |
var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential()); | |
var secret = await client.GetSecretAsync(secretName); | |
var cert = new X509Certificate2(Convert.FromBase64String(secret.Value.Value)); | |
var cc = new PnP.Framework.AuthenticationManager("<Azure App Registration Client ID>", cert, "<Tenant ID>", null, PnP.Framework.AzureEnvironment.Production, null).GetContext("https://Tenant.sharepoint.com"); | |
cc.Load(cc.Web); | |
cc.ExecuteQuery(); | |
return new OkObjectResult("Title of web: " + cc.Web.Title); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment