private static AzureAADObject GetAzureAADObject() { AzureAADObject azureAADObject = new AzureAADObject(); azureAADObject.TenantId = ConfigurationManager.AppSettings[nameof(azureAADObject.TenantId)]; azureAADObject.ClientId = ConfigurationManager.AppSettings[nameof(azureAADObject.ClientId)]; azureAADObject.ResourceId = ConfigurationManager.AppSettings[nameof(azureAADObject.ResourceId)]; azureAADObject.RedirectUri = ConfigurationManager.AppSettings[nameof(azureAADObject.RedirectUri)]; azureAADObject.Authority = string.Format(ConfigurationManager.AppSettings[nameof(azureAADObject.Authority)], azureAADObject.TenantId); azureAADObject.StorageAccountName = ConfigurationManager.AppSettings[nameof(azureAADObject.StorageAccountName)]; azureAADObject.EndPointSuffix = ConfigurationManager.AppSettings[nameof(azureAADObject.EndPointSuffix)]; return(azureAADObject); }
private static void AuthenticateUser() { try { AzureAADObject azureAADObject = GetAzureAADObject(); AuthenticationContext authenticationContext = new AuthenticationContext(azureAADObject.Authority); AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(azureAADObject.ResourceId, azureAADObject.ClientId, new Uri(azureAADObject.RedirectUri), new PlatformParameters(PromptBehavior.Auto)).Result; StorageCredentials storageCredentials = new StorageCredentials(new TokenCredential(authenticationResult.AccessToken)); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentials, azureAADObject.StorageAccountName, azureAADObject.EndPointSuffix, true); _cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); } catch (Exception ex) { Console.WriteLine(ex); } }