Skip to content

Commit e90e844

Browse files
committed
Updated code to use MID for SQL DB access
1 parent 98e6ff0 commit e90e844

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

ClaimsApi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
2828
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4" />
2929
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4" />
30+
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.4.0" />
3031
<!-- <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" /> -->
3132
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
3233
</ItemGroup>

Models/ClaimsContext.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
namespace ClaimsApi.Models {
33
public class ClaimsContext : DbContext {
44
public ClaimsContext(DbContextOptions<ClaimsContext> options) : base(options) {
5+
var conn = (Microsoft.Data.SqlClient.SqlConnection) Database.GetDbConnection();
6+
conn.AccessToken = (new Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider()).GetAccessTokenAsync("https://database.windows.net/").Result;
57

68
}
79
public DbSet<ClaimItem> ClaimItems { get; set; }
@@ -62,4 +64,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) {
6264
.HasDefaultValueSql("NEXT VALUE FOR ServiceLineNumbers");
6365
}
6466
}
65-
}
67+
}

appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"AllowedHosts": "*",
1010
"ConnectionStrings": {
11-
"SqlServerDb": "Server=tcp:#{SQL_SRV_PREFIX}#.database.windows.net;Initial Catalog=ClaimsDB;Persist Security Info=False;User ID=#{SQL_USER_ID}#;Password=#{SQL_USER_PWD}#;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
11+
"SqlServerDb": "Server=tcp:graksdb.database.windows.net,1433;Database=grakslab;"
1212
},
1313
"ApplicationInsights": {
1414
"InstrumentationKey": "<Instrumentation Key>"

0 commit comments

Comments
 (0)