private async Task <int> OnExecuteAsync(CommandLineApplication app, CancellationToken cancellationToken = default) { var authenticationOptions = AuthenticationOptions.BuildFrom(this.UseAzCliDevAuth, this.TenantId); IAppServiceManager appServiceManager = AppServiceManagerSource.Get( authenticationOptions, this.SubscriptionId); IWebAppAuthentication webAppAuthConfig; ManagedServiceIdentity managedIdentity; IFunctionApp function = null; try { function = appServiceManager.FunctionApps.GetByResourceGroup(this.ResourceGroupName, this.AppName); } catch (NullReferenceException) { // Unhelpfully, we seem to get a null reference exception if the app isn't found } if (function != null) { managedIdentity = function.Inner.Identity; webAppAuthConfig = await function.GetAuthenticationConfigAsync(cancellationToken).ConfigureAwait(false); } else { IWebApp webApp = appServiceManager.WebApps.GetByResourceGroup(this.ResourceGroupName, this.AppName); if (webApp == null) { app.Error.WriteLine($"Unable to find either a Function or Web App in resource group '{this.ResourceGroupName}' called '{this.AppName}'"); return(-1); } managedIdentity = webApp.Inner.Identity; webAppAuthConfig = await webApp.GetAuthenticationConfigAsync(cancellationToken).ConfigureAwait(false); } if (webAppAuthConfig.Inner.Enabled == true) { app.Out.WriteLine($"Default Easy Auth: {webAppAuthConfig.Inner.DefaultProvider}"); app.Out.WriteLine($" Client ID: {webAppAuthConfig.Inner.ClientId}"); } else { app.Out.WriteLine("Easy Auth not enabled"); } if (managedIdentity == null) { app.Out.WriteLine("No managed identity"); } else { app.Out.WriteLine("Managed identity:"); app.Out.WriteLine($" Type: {managedIdentity.Type}"); app.Out.WriteLine($" TenantId: {managedIdentity.TenantId}"); app.Out.WriteLine($" PrincipalId: {managedIdentity.PrincipalId}"); if (managedIdentity.UserAssignedIdentities != null) { foreach ((string id, ManagedServiceIdentityUserAssignedIdentitiesValue value) in managedIdentity.UserAssignedIdentities) { app.Out.WriteLine($" UserAssignedIdentity: Id = {id}, ClientId = {value.ClientId}, PrincipalId = {value.PrincipalId}"); } } } return(0); }