Skip to content

Commit

Permalink
Use AAD auth to connect to storage account
Browse files Browse the repository at this point in the history
  • Loading branch information
mderriey committed Feb 19, 2021
1 parent c32e1f6 commit b197ed7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.3.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.8.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
</ItemGroup>
Expand Down
18 changes: 17 additions & 1 deletion src/AzureIdentityLivestream.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using Azure.Identity;
using Azure.Storage.Blobs;
using AzureIdentityLivestream.Web.Services;
using AzureIdentityLivestream.Web.Services.AzureBlobStorage;
Expand All @@ -22,7 +24,21 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();

services.AddSingleton(_ => new BlobServiceClient(Configuration.GetValue<string>("StorageConnectionString")));
services.AddSingleton(_ =>
{
var storageConnectionString = Configuration.GetValue<string>("StorageConnectionString");
if (Uri.TryCreate(storageConnectionString, UriKind.Absolute, out var storageEndpointUri))
{
var credential = new ChainedTokenCredential(
new ManagedIdentityCredential(),
new VisualStudioCodeCredential());

return new BlobServiceClient(storageEndpointUri, credential);
}

return new BlobServiceClient(storageConnectionString);
});

services.AddSingleton<IPersonProvider, AzureBlobStoragePersonProvider>();

services.AddRazorPages();
Expand Down
2 changes: 1 addition & 1 deletion src/AzureIdentityLivestream.Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"StorageConnectionString": "UseDevelopmentStorage=true",
"StorageConnectionString": "https://azureidentitylivestream.blob.core.windows.net",
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down

0 comments on commit b197ed7

Please sign in to comment.