Skip to content

Instantly share code, notes, and snippets.

View LauraKokkarinen's full-sized avatar

Laura Kokkarinen LauraKokkarinen

View GitHub Profile
using AzureFunctionsDependencyInjection.Services;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
// Required if you want to add custom services
[assembly: FunctionsStartup(typeof(AzureFunctionsDependencyInjection.Startup))]
namespace AzureFunctionsDependencyInjection
{
public class Startup : FunctionsStartup
using System;
using System.Security.Claims;
using AzureFunctionsDependencyInjection.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace AzureFunctionsDependencyInjection.Services
{
public class DataService : IDataService
{
private readonly IBlobService _blobCache;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
namespace AzureFunctionsDependencyInjection.Services
{
public class BlobService : IBlobService
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace AzureFunctionsDependencyInjection
{
public class Warmup
{
private readonly IConfiguration _configuration;
using System;
using System.Threading.Tasks;
using AzureFunctionsDependencyInjection.Services;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace AzureFunctionsDependencyInjection
{
public class CacheRefresh
{
# Replace with your managed identity object ID
$miObjectID = "17707c90-dab4-483d-a57f-65e91ac3d94f"
# The app ID of the API where you want to assign the permissions
$appId = "00000003-0000-0000-c000-000000000000"
# The app IDs of the Microsoft APIs are the same in all tenants:
# Microsoft Graph: 00000003-0000-0000-c000-000000000000
# SharePoint Online: 00000003-0000-0ff1-ce00-000000000000
# Replace with your managed identity object ID
$miObjectID = "17707c90-dab4-483d-a57f-65e91ac3d94f"
# The app ID of the API where you want to assign the permissions
$appId = "00000003-0000-0000-c000-000000000000"
# The app IDs of the Microsoft APIs are the same in all tenants:
# Microsoft Graph: 00000003-0000-0000-c000-000000000000
# SharePoint Online: 00000003-0000-0ff1-ce00-000000000000
# Replace with your managed identity object ID
$miObjectID = "17707c90-dab4-483d-a57f-65e91ac3d94f"
# The app ID of the API where you want to assign the permissions
$appId = "00000003-0000-0000-c000-000000000000"
# The app IDs of the Microsoft APIs are the same in all tenants:
# Microsoft Graph: 00000003-0000-0000-c000-000000000000
# SharePoint Online: 00000003-0000-0ff1-ce00-000000000000
using Azure.Identity;
public async Task<string> GetAccessTokenAsync(string resourceUrl)
{
var credential = new DefaultAzureCredential(); // Or new ManagedIdentityCredential();
var accessToken = await credential.GetTokenAsync(new TokenRequestContext(scopes: [resourceUrl + "/.default"]) { });
return accessToken.Token;
}