Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure.Authenticate with interactive user login (Microsoft.Azure.Management.Fluent)

I used to manage Azure resources an old preview version. The authentication worked something like this:

// Authorize 
this.AuthenticationResult = this.Authorize();
this.Credentials = new TokenCloudCredentials(config.SubscriptionId, this.AuthenticationResult.AccessToken);
this.ResourceManagement = new ResourceManagementClient(this.Credentials, new Uri(config.ManagementBaseUrl));

That would pop up and interactive user login window. I'd like to do the same with the new fluent nuget package (Microsoft.Azure.Management.Fluent version="1.0.0")

Azure.Authenticate(???)

This seems to be the best documentation of the authentication method: https://github.com/Azure/azure-sdk-for-net/blob/Fluent/AUTH.md

But it only covers options that will store credentials on the HDD which I'd like to avoid. So that whatever user is using my program is needed to login.

So in summary: How do I authenticate using an interactive user login with the latest Azure management API?

like image 477
Sam7 Avatar asked May 15 '17 01:05

Sam7


People also ask

How do I use Microsoft Identity Azure AD to authenticate your users?

Enable Azure Active Directory in your App Service app. Sign in to the Azure portal and navigate to your app. Select Authentication in the menu on the left. Click Add identity provider.

How do I authenticate my Azure account?

The Azure CLI's default authentication method for logins uses a web browser and access token to sign in. Run the login command. If the CLI can open your default browser, it will initiate authorization code flow and open the default browser to load an Azure sign-in page.

What authentication and verification methods are available in Azure Active Directory?

Available verification methodsMicrosoft Authenticator app. Windows Hello for Business. FIDO2 security key. OATH hardware token (preview)

Which of the following is an automated process to authenticate Azure machine learning workspace?

Service principal: You create a service principal account in Azure Active Directory, and use it to authenticate or get a token. A service principal is used when you need an automated process to authenticate to the service without requiring user interaction.


2 Answers

According to SDK source code, there is no interactive user login currently.

 credentialsCache[adSettings.TokenAudience] = await UserTokenProvider.LoginSilentAsync(
                        userLoginInformation.ClientId, TenantId, userLoginInformation.UserName,
                        userLoginInformation.Password, adSettings, TokenCache.DefaultShared);

But it only covers options that will store credentials on the HDD which I'd like to avoid. So that whatever user is using my program is needed to login.

To avoid storing credentials on the HDD , if no interactive user login is accepted we could use Login Slient model with username and password.

var credentials = new AzureCredentials(new UserLoginInformation { ClientId = "Azure client Id",UserName = "username",Password = "Password"}, "tenant Id", AzureEnvironment.AzureGlobalCloud);  //AzureChinaCloud,AzureGermanCloud,AzureUSGovernment

var azure = Azure
            .Configure()
            .Authenticate(credentials)
            .WithDefaultSubscription();
like image 89
Tom Sun - MSFT Avatar answered Sep 20 '22 11:09

Tom Sun - MSFT


Fluent libraries does not support interactive login. If your project targets .Net Core then you can use Device Flow authentication, but that will require you to pop-up to the caller information received from Azure AD Source code in Fluent Repo

like image 37
hovsepm Avatar answered Sep 19 '22 11:09

hovsepm