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

Commit 737ef12

Browse files
committed
Add logout command
1 parent 625072d commit 737ef12

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

src/Authentication/ILoginService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ namespace Microsoft.Graph.Cli.Authentication;
44

55
interface ILoginService {
66
Task LoginAsync(string[] scopes);
7-
8-
void Logout();
97
}

src/Authentication/LoginServiceBase.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ public async Task LoginAsync(string[] scopes) {
1111
await this.SaveSessionAsync(record);
1212
}
1313

14-
public void Logout() {
15-
if (File.Exists(Constants.AuthRecordPath)) {
16-
File.Delete(Constants.AuthRecordPath);
17-
}
18-
}
19-
2014
protected abstract Task<AuthenticationRecord> DoLoginAsync(string[] scopes);
2115

2216
public async Task SaveSessionAsync(AuthenticationRecord record) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.IO;
2+
using Microsoft.Graph.Cli.Utils;
3+
4+
namespace Microsoft.Graph.Cli.Authentication;
5+
6+
public class LogoutService {
7+
public void Logout() {
8+
if (File.Exists(Constants.AuthRecordPath)) {
9+
File.Delete(Constants.AuthRecordPath);
10+
}
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.Graph.Cli.Authentication;
2+
using Microsoft.Graph.Cli.Utils;
3+
using System.CommandLine;
4+
using System.CommandLine.Invocation;
5+
6+
namespace Microsoft.Graph.Cli.Commands.Authentication;
7+
8+
class LogoutCommand
9+
{
10+
private readonly LogoutService logoutService;
11+
12+
public LogoutCommand(LogoutService logoutService) {
13+
this.logoutService = logoutService;
14+
}
15+
16+
public Command Build() {
17+
var logoutCommand = new Command("logout", "Logout by deleting the stored session used in commands");
18+
19+
logoutCommand.Handler = CommandHandler.Create(() =>
20+
{
21+
this.logoutService.Logout();
22+
});
23+
24+
return logoutCommand;
25+
}
26+
}

src/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ static async Task<int> Main(string[] args) {
2525

2626
var loginCommand = new LoginCommand(authServiceFactory);
2727
rootCommand.AddCommand(loginCommand.Build());
28+
29+
var logoutCommand = new LogoutCommand(new LogoutService());
30+
rootCommand.AddCommand(logoutCommand.Build());
2831
return await rootCommand.InvokeAsync(args);
2932
}
3033
}

0 commit comments

Comments
 (0)