This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Graph; | |
using Microsoft.Identity.Client; | |
using Microsoft.IdentityModel.Tokens; | |
using System; | |
using System.IdentityModel.Tokens.Jwt; | |
using System.Linq; | |
using System.Net.Http.Headers; | |
using System.Security.Cryptography.X509Certificates; | |
using System.Threading.Tasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private KeyCredential CreateKeyCredential(X509Certificate2 certificate) | |
{ | |
return new KeyCredential() | |
{ | |
Key = certificate.RawData, | |
Usage = "Verify", | |
Type = "AsymmetricX509Cert" | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string GetJwtTokenProof(X509Certificate2 signingCert, string appId) | |
{ | |
var notBefore = DateTime.Now; | |
var expires = notBefore.AddMinutes(10); | |
var handler = new JwtSecurityTokenHandler(); | |
var credentials = new X509SigningCredentials(signingCert); | |
var jwtToken = handler.CreateJwtSecurityToken(appId, "https://graph.windows.net", null, notBefore, expires, null, credentials); | |
return handler.WriteToken(jwtToken); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task<string> GetTokenAsync(string appId, X509Certificate2 certificate, string tenantId) | |
{ | |
var app = ConfidentialClientApplicationBuilder.Create(appId) | |
.WithAuthority($"https://login.microsoftonline.com/{tenantId}/") | |
.WithCertificate(certificate) | |
.Build(); | |
var scopes = new[] { "https://graph.microsoft.com/.default" }; | |
var result = await app.AcquireTokenForClient(scopes).ExecuteAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"isUpdate": { | |
"type": "bool" | |
}, | |
"throughput": { | |
"type": "int", | |
"minValue": 400, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "Microsoft.DocumentDB/databaseAccounts/apis/databases", | |
"name": "[concat(variables('databaseAccountName'), '/sql/', variables('databaseName'))]", | |
"apiVersion": "2016-03-31", | |
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('databaseAccountName'))]" ], | |
"properties": { | |
"resource": { | |
"id": "[variables('databaseName')]" | |
}, | |
"options": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "Microsoft.DocumentDB/databaseAccounts/apis/databases/settings", | |
"name": "[concat(variables('databaseAccountName'), '/sql/', variables('databaseName'), '/throughput')]", | |
"apiVersion": "2016-03-31", | |
"dependsOn": [ | |
"[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('databaseAccountName'), 'sql', variables('databaseName'))]" | |
], | |
"properties": { | |
"resource": { | |
"throughput": "500" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "Microsoft.DocumentDB/databaseAccounts/apis/databases", | |
"name": "[concat(variables('databaseAccountName'), '/sql/', variables('databaseName'))]", | |
"apiVersion": "2016-03-31", | |
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('databaseAccountName'))]" ], | |
"properties": { | |
"resource": { | |
"id": "[variables('databaseName')]" | |
}, | |
"options": { |