Login-AzureRmAccount command does not work with hosted C # application

I use powershell script to enter azure, and for this I write a simple command "Login-AzureRmAccount" and call that script in C # code when the button is clicked. It works fine locally, but when I host this page on the server, the authentication popup does not open and I get an error message, that is, "Displaying a modal dialog box or form when the application is not working in UserInteractive mode is not a valid operation. ServiceNotification or DefaultDesktopOnly to display a notification from a service application "

+2
source share
1 answer

Since your code is running on a server, a popup will try to appear on the local system (server), and this is obviously not possible because you are not logged in.

The proper way to do this is to use the Credential object according to the code posted at the end of this answer. You will need to create your own mechanism (form) to capture the username and password.

Unfortunately, at the time of publication, Microsoft IDs do not support non-interactive flow (what are you trying to do). You will need to run your script on your client machine, log in to your server, or set up an Azure AD account with the appropriate credentials.

Using the Credential Object to Log in to Azure:

#Set up a PSCredential:
$yourPassword = ConvertTo-SecureString "<Your Password>" -AsPlainText –Force
$yourCredential = 
    New-Object -TypeName pscredential –ArgumentList "<Your UserName>", $yourPassword

# Then use that credential to log in to your Azure account 
Login-AzureRmAccount -Credential $yourCredential 
      -ServicePrincipal –TenantId <Your TenantId>
0
source

Source: https://habr.com/ru/post/1671673/


All Articles