File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
App/backend-api/Microsoft.GS.DPS.Host Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11using Azure . Identity ;
22using Microsoft . Extensions . Azure ;
33using Microsoft . GS . DPSHost . AppConfiguration ;
4+ using Microsoft . GS . DPSHost . Helpers ;
45
56namespace Microsoft . GS . DPSHost . AppConfiguration
67{
@@ -16,7 +17,7 @@ public static void Config(IHostApplicationBuilder builder)
1617 //Read AppConfiguration with managed Identity
1718 builder . Configuration . AddAzureAppConfiguration ( options =>
1819 {
19- options . Connect ( new Uri ( builder . Configuration [ "ConnectionStrings:AppConfig" ] ) , new DefaultAzureCredential ( ) ) ;
20+ options . Connect ( new Uri ( builder . Configuration [ "ConnectionStrings:AppConfig" ] ) , AzureCredentialHelper . GetAzureCredential ( ) ) ;
2021 } ) ;
2122
2223 //Read ServiceConfiguration
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Azure . Core ;
4+ using Azure . Identity ;
5+
6+ namespace Microsoft . GS . DPSHost . Helpers
7+ {
8+ public static class AzureCredentialHelper
9+ {
10+ public static TokenCredential GetAzureCredential ( string clientId = null )
11+ {
12+ var env = Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ?? "Production" ;
13+
14+ if ( string . Equals ( env , "Development" , StringComparison . OrdinalIgnoreCase ) )
15+ {
16+ return new DefaultAzureCredential ( ) ; // For local development
17+ }
18+ else
19+ {
20+ return clientId != null
21+ ? new ManagedIdentityCredential ( clientId )
22+ : new ManagedIdentityCredential ( ) ;
23+ }
24+ }
25+
26+ public static Task < TokenCredential > GetAzureCredentialAsync ( string clientId = null )
27+ {
28+ return Task . FromResult ( GetAzureCredential ( clientId ) ) ;
29+ }
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments