0
votes

I have a xamarin app --> azureFunction --->BlobStorage. so far so good. The AzureFunction is set with AuthorizationLevel.Function.

  1. I have set the azure function Managed identity "ON"
  2. I have assigned a role to the BlobStorage (Blob data Contributor)
  3. I can successfully call the function using postman using the function key.

I would like to store the functionKey in the KeyVault and call it from my mobile app

Question

As anybody got a walkthrough and snippet how to integrate the keyvault with a function key and call it from a mobile app (xamarin forms) c#?

I do not want to hardcode any keys in my mobile app.

I would be very grateful.Lots of googling and nothing.

thanks

1

1 Answers

1
votes

Suppose your requirement is call the function from the code. Maybe you could refer to the below code.

            AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
            KeyVaultClient keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
            var secret = await keyVaultClient.GetSecretAsync("your Secret Identifier")
                    .ConfigureAwait(false);
            string functionkey = secret.Value;
            string functionhost = "https://your function.azurewebsites.net/api/function name";
            var param = new Dictionary<string, string>() { { "code", functionkey } ,{ "name","george"} };
            Uri functionurl = new Uri(QueryHelpers.AddQueryString(functionhost, param));

            var request = (HttpWebRequest)WebRequest.Create(functionurl);
            var response = (HttpWebResponse)request.GetResponse();
            string responseString;

            using (var stream = response.GetResponseStream())
            {
                using (var reader = new StreamReader(stream))
                {
                    responseString = reader.ReadToEnd();
                    Console.WriteLine(responseString);
                }
            }

enter image description here