We want to import bacpac file from Blob storage into Azure SQL server thru Azure Functions which is Blob trigger function.
We have implemented it as follows
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
var apimUrl = "https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/sqlRG/providers/Microsoft.Sql/servers/sqldev/import?api-version=2014-04-01";
var content = "{'databaseName': 'TestDbImport'," +
"'edition': 'Basic'," +
"'serviceObjectiveName': 'Basic'," +
"'maxSizeBytes': '2147483648'," +
"'storageKeyType': 'SharedAccessKey'," +
"'storageKey': 'xxxxxxx'," +
"'storageUri': 'https://account.blob.core.windows.net/sql-backup/test.bacpac'," +
"'administratorLogin': 'user'," +
"'administratorLoginPassword': 'password'," +
"'authenticationType': 'SQL'}";
HttpClient Client = new HttpClient();
var AADToken = "token";
Client = new HttpClient();
Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AADToken);
Client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key","subKey");
var foo = Client.PostAsync(apimUrl, new StringContent(content.ToString())).Result;
log.Info($"result: {foo}");
I need help to understand how to get AADToken as well as subKey which needs to pass in header to authenticate this request (Also i am confused like why i need authenticate when everything will be executed within Azure itself)
If i do not pass header then getting 401 (unauthorized) error code.