public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var configuration = new ConfigurationSettings(); var storageService = new StorageService(configuration, log); var tokenCacheService = new TokenCacheService(configuration, storageService); var tokenManager = new TokenManager(configuration, tokenCacheService, log); var scopes = new string[] { $"api://{configuration["ClientId"]}/access_as_user" }; var siteCollection = new SiteCollection() { Url = $"https://{configuration["SharePointTenantPrefix"]}.sharepoint.com/sites/rztest123", Owner = $"{configuration["Username"]}", Title = "Test123", Template = "STS#0", StorageMaximumLevel = 100, UserCodeMaximumLevel = 300 }; var uri = await tokenManager.GetAuthUriAsync(scopes); //var authCode = await tokenRetriever.GetAuthCodeByMsalUriAsync(uri); var authenticationHeaderValue = req.Headers.Authorization; var authResult = await tokenManager.GetAccessTokenFromCodeAsync(authenticationHeaderValue.Parameter, scopes); var sharepointManager = new SharePointManager(configuration, tokenManager, authResult.AccessToken); var results = await sharepointManager.CreateSiteCollectionAsync(siteCollection); var httpContent = new StringContent(JsonConvert.SerializeObject(results)); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = httpContent, }); }