@@ -7,13 +7,15 @@ namespace Microsoft.Authentication.AzureAuth.Commands.Ado
77 using System . Collections . Generic ;
88 using System . Collections . Immutable ;
99 using System . IO ;
10+ using System . Linq ;
1011 using McMaster . Extensions . CommandLineUtils ;
1112
1213 using Microsoft . Authentication . AdoPat ;
1314 using Microsoft . Authentication . AzureAuth . Ado ;
1415 using Microsoft . Authentication . MSALWrapper ;
1516 using Microsoft . Extensions . Logging ;
1617 using Microsoft . Identity . Client . Extensions . Msal ;
18+ using Microsoft . Office . Lasso . Interfaces ;
1719 using Microsoft . Office . Lasso . Telemetry ;
1820 using Microsoft . VisualStudio . Services . DelegatedAuthorization ;
1921 using Microsoft . VisualStudio . Services . OAuth ;
@@ -92,7 +94,7 @@ private enum OutputMode
9294 private string Tenant { get ; set ; } = AzureAuth . Ado . Constants . Tenant . Microsoft ;
9395
9496 [ Option ( CommandAad . ModeOption , CommandAad . AuthModeHelperText , CommandOptionType . MultipleValue ) ]
95- private IEnumerable < AuthMode > AuthModes { get ; set ; } = new [ ] { AuthMode . Default } ;
97+ private IEnumerable < AuthMode > AuthModes { get ; set ; }
9698
9799 [ Option ( CommandAad . DomainOption , $ "{ CommandAad . DomainHelpText } \n [default: { AzureAuth . Ado . Constants . PreferredDomain } ]", CommandOptionType . SingleValue ) ]
98100 private string Domain { get ; set ; } = AzureAuth . Ado . Constants . PreferredDomain ;
@@ -120,14 +122,23 @@ private ImmutableSortedSet<string> Scopes
120122 /// <param name="logger">The <see cref="ILogger{T}"/> instance that is used for logging.</param>
121123 /// <param name="publicClientAuth">An <see cref="IPublicClientAuth"/>.</param>
122124 /// <param name="eventData">Lasso injected command event data.</param>
125+ /// <param name="env">An <see cref="IEnv"/> to use.</param>
123126 /// <returns>An integer status code. 0 for success and non-zero for failure.</returns>
124- public int OnExecute ( ILogger < CommandPat > logger , IPublicClientAuth publicClientAuth , CommandExecuteEventData eventData )
127+ public int OnExecute ( ILogger < CommandPat > logger , IPublicClientAuth publicClientAuth , CommandExecuteEventData eventData , IEnv env )
125128 {
126129 if ( ! this . ValidOptions ( logger ) )
127130 {
128131 return 1 ;
129132 }
130133
134+ // If command line options for mode are not specified, then use the environment variables.
135+ this . AuthModes ??= env . ReadAuthModeFromEnvOrSetDefault ( ) ;
136+ if ( ! this . AuthModes . Any ( ) )
137+ {
138+ logger . LogError ( $ "Invalid value specified for environment variable { EnvVars . AuthMode } . Allowed values are: { CommandAad . AuthModeHelperText } ") ;
139+ return 1 ;
140+ }
141+
131142 var accessToken = this . AccessToken ( publicClientAuth , eventData ) ;
132143 if ( accessToken == null )
133144 {
0 commit comments