Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit eef4059

Browse files
committed
Add environment login.
Update changelog.
1 parent a2848e3 commit eef4059

File tree

4 files changed

+104
-102
lines changed

4 files changed

+104
-102
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Add Environment login. Client secret login and certificate file login are now possible with this new strategy.
12+
13+
### Changed
14+
- Update login command help text.
15+
- Fix a bug where the CLI didn't send the Content-Type header when sending requests with bodies.
16+
1017
## [0.2.0-preview.1] - 2023-02-27
1118

1219
### Added

src/Program.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ class Program
4141
{
4242
static async Task<int> Main(string[] args)
4343
{
44-
var customCommands = new List<Command>();
45-
customCommands.Add(new LoginCommand().Build());
46-
customCommands.Add(new LogoutCommand().Build());
47-
48-
49-
var builder = BuildCommandLine(customCommands)
44+
var builder = BuildCommandLine()
5045
.UseDefaults()
5146
.UseHost(a =>
5247
{
@@ -75,7 +70,7 @@ static async Task<int> Main(string[] args)
7570
{
7671
var host = ic.GetHost();
7772

78-
ic.BindingContext.AddService(_ => host.Services.GetRequiredService<IAuthenticationCacheUtility>());
73+
ic.BindingContext.AddService(_ => host.Services.GetRequiredService<IAuthenticationCacheManager>());
7974
ic.BindingContext.AddService(_ => host.Services.GetRequiredService<AuthenticationServiceFactory>());
8075
// Needed by LogoutCommand
8176
ic.BindingContext.AddService(_ => host.Services.GetRequiredService<LogoutService>());
@@ -115,7 +110,7 @@ static async Task<int> Main(string[] args)
115110
return await parser.InvokeAsync(args);
116111
}
117112

118-
static CommandLineBuilder BuildCommandLine(IEnumerable<Command> commands)
113+
static CommandLineBuilder BuildCommandLine()
119114
{
120115
var rootCommand = new GraphClient().BuildRootCommand();
121116
rootCommand.Description = "Microsoft Graph CLI";
@@ -125,12 +120,11 @@ static CommandLineBuilder BuildCommandLine(IEnumerable<Command> commands)
125120
// --debug for configs.
126121
rootCommand.TreatUnmatchedTokensAsErrors = false;
127122

128-
foreach (var command in commands)
129-
{
130-
rootCommand.AddCommand(command);
131-
}
123+
var builder = new CommandLineBuilder(rootCommand);
124+
rootCommand.AddCommand(new LoginCommand(builder));
125+
rootCommand.AddCommand(new LogoutCommand());
132126

133-
return new CommandLineBuilder(rootCommand);
127+
return builder;
134128
}
135129

136130
static IHostBuilder CreateHostBuilder(string[] args) =>
@@ -188,13 +182,13 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
188182
return new HttpClientRequestAdapter(authProvider, httpClient: client);
189183
});
190184
services.AddSingleton<IPathUtility, PathUtility>();
191-
services.AddSingleton<IAuthenticationCacheUtility, AuthenticationCacheUtility>();
185+
services.AddSingleton<IAuthenticationCacheManager, AuthenticationCacheManager>();
192186
services.AddSingleton<LogoutService>();
193187
services.AddSingleton<AuthenticationServiceFactory>(p =>
194188
{
195189
var authSettings = p.GetRequiredService<IOptions<AuthenticationOptions>>()?.Value;
196190
var pathUtil = p.GetRequiredService<IPathUtility>();
197-
var cacheUtil = p.GetRequiredService<IAuthenticationCacheUtility>();
191+
var cacheUtil = p.GetRequiredService<IAuthenticationCacheManager>();
198192
return new AuthenticationServiceFactory(pathUtil, cacheUtil, authSettings);
199193
});
200194
}).ConfigureLogging((ctx, logBuilder) =>
@@ -214,7 +208,7 @@ static void ConfigureAppConfiguration(IConfigurationBuilder builder, string[] ar
214208
builder.Sources.Clear();
215209
builder.AddJsonFile(Path.Combine(System.AppContext.BaseDirectory, "app-settings.json"), optional: true);
216210
var pathUtil = new PathUtility();
217-
var authCache = new AuthenticationCacheUtility(pathUtil);
211+
var authCache = new AuthenticationCacheManager(pathUtil);
218212
var dataDir = pathUtil.GetApplicationDataDirectory();
219213
var userConfigPath = Path.Combine(dataDir, "settings.json");
220214
builder.AddJsonFile(userConfigPath, optional: true);

src/msgraph-cli.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ImplicitUsings>disable</ImplicitUsings>
88
<Nullable>enable</Nullable>
99
<AssemblyName>mgc</AssemblyName>
10-
<Version>0.2.0-preview.1</Version>
10+
<Version>0.3.0-preview.1</Version>
1111
</PropertyGroup>
1212

1313
<PropertyGroup>
@@ -26,7 +26,7 @@
2626
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
2727
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
2828
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
29-
<PackageReference Include="Microsoft.Graph.Cli.Core" Version="0.1.8-preview.1" />
29+
<PackageReference Include="Microsoft.Graph.Cli.Core" Version="0.2.0-preview.1" />
3030
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
3131
</ItemGroup>
3232
</Project>

0 commit comments

Comments
 (0)