public async Task <ActionResult> AssignRole() { string signedInUserID = ClaimsPrincipal.Current.FindFirst(JwtRegisteredClaimNames.Sub).Value; var confidentialClientApplication = MSALAppBuilder.GetAppBuilder(signedInUserID, this.HttpContext); var user = await confidentialClientApplication.GetAccountsAsync(); AuthenticationResult result = await confidentialClientApplication.AcquireTokenSilentAsync(new List <string>() { AuthenticationConfig.azureManagementScope }, user.FirstOrDefault(), AuthenticationConfig.authority, false); var roleAssignmentModel = new RoleAssignmentModel() { SubscriptionId = "47ca3602-b986-46de-a99a-e473c26bd588", ResourceGroupName = "AdityaAzureRG", StorageAccountName = "researchstorageacct", ContainerName = "research", RoleId = "2a2b9908-6ea1-4ae2-8e65-a410df84e7d1", ServicePrincipalObjectId = "04f300cc-5632-4820-8fd2-9d36e7efd020", RoleAssignmentName = Guid.NewGuid().ToString() }; var roleAssignmentService = new RoleAssignmentService(roleAssignmentModel); var httpResponseMessage = await roleAssignmentService.AssignRole(result.AccessToken); var responeFromazureAPi = await httpResponseMessage.Content.ReadAsStringAsync(); var deserializeResponse = JsonConvert.DeserializeObject(responeFromazureAPi).ToString(); return(View("AssignRole", (object)deserializeResponse)); }
public HomeController(IMemoryCache cache, IFileProvider fileProvider, ILogger <DiagnoseIssuesController> logger, IHostingEnvironment hostingEnvironment, RoleAssignmentService roleAssignmentService) { _fileProvider = fileProvider; _logger = logger; _hostingEnvironment = hostingEnvironment; _roleAssignmentService = roleAssignmentService; }