Skip to content
This repository was archived by the owner on Jun 19, 2026. It is now read-only.

Commit 1aa756e

Browse files
committed
Add support for "no authentication" mode
Introduced a `None` authentication type in the `AuthenticationType` enum to allow users to explicitly opt out of authentication. Added a `LoginNone` method in `IAuthenticationManager` and implemented it in `AuthenticationManager`. Updated the `IsLoggedIn` property and authentication logic to handle `None` authentication. Enhanced the `LoginCommand` with a new `--noauth` option and updated `LoginCommandOptions` to include a `NoAuth` property. Refactored the `AuthenticateClient` method in `AuthenticationExtensions` to handle `None` authentication using a `switch` statement. Updated resource strings to include descriptions for the `--noauth` option and removed redundant strings. Performed general cleanup and refactoring to improve code clarity and maintainability. #128
1 parent c6d5c15 commit 1aa756e

8 files changed

Lines changed: 71 additions & 23 deletions

File tree

src/FlowCtl.Core/Services/Authentication/AuthenticationType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public enum AuthenticationType
44
{
5+
None = 0,
56
Basic,
67
Bearer
78
}

src/FlowCtl.Core/Services/Authentication/IAuthenticationManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public interface IAuthenticationManager
44
{
55
bool IsLoggedIn { get; }
66
bool IsBasicAuthenticationUsed { get; }
7+
AuthenticationData LoginNone();
78
AuthenticationData LoginBasic(string username, string password);
89
AuthenticationData LoginBearer(string token);
910
AuthenticationData? GetData();

src/FlowCtl.Infrastructure/Services/Authentication/AuthenticationManager.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,29 @@ public AuthenticationManager(
2121
}
2222

2323
public bool IsLoggedIn => File.Exists(ConfigPath) && Load() is { } data && (
24-
data.Type == AuthenticationType.Basic || data.Expiry is null || data.Expiry > DateTime.UtcNow
24+
data.Type == AuthenticationType.Basic
25+
|| data.Type == AuthenticationType.None
26+
|| data.Expiry is null
27+
|| data.Expiry > DateTime.UtcNow
2528
);
2629

2730
public bool IsBasicAuthenticationUsed => File.Exists(ConfigPath) && Load() is { } data &&
2831
data.Type == AuthenticationType.Basic;
2932

33+
public AuthenticationData LoginNone()
34+
{
35+
var data = new AuthenticationData
36+
{
37+
Type = AuthenticationType.None,
38+
Username = null,
39+
Password = null,
40+
AccessToken = null,
41+
Expiry = null
42+
};
43+
Save(data);
44+
return data;
45+
}
46+
3047
public AuthenticationData LoginBasic(string username, string password)
3148
{
3249
var data = new AuthenticationData

src/FlowCtl/Commands/Login/LoginCommand.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ internal class LoginCommand : BaseCommand<LoginCommandOptions, LoginCommandOptio
66
{
77
public LoginCommand() : base("login", Resources.Commands_Login_Description)
88
{
9+
var noneOption = new Option<bool?>("--noauth",
10+
getDefaultValue: () => false,
11+
description: Resources.Commands_Login_NoAuthenticationOption);
12+
913
var basicOption = new Option<bool?>("--basic",
1014
getDefaultValue: () => false,
1115
description: Resources.Commands_Login_BasicAuthenticationOption);

src/FlowCtl/Commands/Login/LoginCommandOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
internal class LoginCommandOptions : ICommandOptions
44
{
5+
public bool? NoAuth { get; set; } = false;
56
public bool? Basic { get; set; } = false;
67
public bool? Bearer { get; set; } = false;
78
public string? Username { get; set; }
Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
using FlowCtl.Core.Services.Authentication;
22
using FlowSynx.Client;
33
using FlowSynx.Client.Authentication;
4-
using System.Security.Authentication;
54

65
namespace FlowCtl.Extensions;
76

87
public static class AuthenticationExtensions
98
{
109
public static void AuthenticateClient(this IAuthenticationManager authenticationManager, IFlowSynxClient flowSynxClient)
1110
{
12-
if (!authenticationManager.IsLoggedIn)
13-
throw new AuthenticationException(Resources.AuthenticationExtensions_AuthenticationIsRequired);
14-
1511
var authenticationData = authenticationManager.GetData();
12+
if (authenticationData is null || authenticationData.Type == AuthenticationType.None)
13+
{
14+
// No credentials or explicitly no-auth: leave client unauthenticated.
15+
return;
16+
}
1617

17-
IAuthenticationStrategy authenticationStrategy;
18-
if (authenticationManager.IsBasicAuthenticationUsed)
19-
authenticationStrategy = new BasicAuthenticationStrategy(authenticationData?.Username!, authenticationData?.Password!);
20-
else
21-
authenticationStrategy = new BearerTokenAuthStrategy(authenticationData?.AccessToken!);
22-
23-
flowSynxClient.SetAuthenticationStrategy(authenticationStrategy);
18+
switch (authenticationData.Type)
19+
{
20+
case AuthenticationType.Basic:
21+
{
22+
var auth = new BasicAuthenticationStrategy(authenticationData.Username!, authenticationData.Password!);
23+
flowSynxClient.SetAuthenticationStrategy(auth);
24+
break;
25+
}
26+
case AuthenticationType.Bearer:
27+
{
28+
var auth = new BearerTokenAuthStrategy(authenticationData.AccessToken!);
29+
flowSynxClient.SetAuthenticationStrategy(auth);
30+
break;
31+
}
32+
default:
33+
// Unknown type: no auth
34+
break;
35+
}
2436
}
2537
}

src/FlowCtl/Resources.Designer.cs

Lines changed: 19 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/FlowCtl/Resources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@
237237
<data name="Commands_Login_Description" xml:space="preserve">
238238
<value>Authenticates the user and establishes a session with the FlowSynx system</value>
239239
</data>
240+
<data name="Commands_Login_NoAuthenticationOption" xml:space="preserve">
241+
<value>Use no authentication. Sends requests without credentials and overrides any saved login.</value>
242+
</data>
240243
<data name="Commands_Login_SpecifyAuthenticationType" xml:space="preserve">
241244
<value>Please specify one of the authentication type: --basic, --bearer, or --oauth</value>
242245
</data>
@@ -525,4 +528,4 @@
525528
<data name="LocationService_ErrorDuringGettingRootLocation" xml:space="preserve">
526529
<value>The base location could not be found.</value>
527530
</data>
528-
</root>
531+
</root>

0 commit comments

Comments
 (0)