-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename LfNext solution dir to FwLite to match folders * pull code out of LocalWebApp and into new FwLiteShared project * move import project service into FwLiteShared * rename ProjectsService.cs to CrdtProjectsService.cs * create CombinedProjectsService and call new methods from ProjectRoutes * move history code into HistoryService and out of LocalWebApp routes * fix history service query because it wasn't being executed by linq2db * add method for creating an example CRDT project from scratch * create AuthService and rename AuthHelpers to OAuthClient
- Loading branch information
Showing
44 changed files
with
639 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...end/FwLite/LocalWebApp/Auth/AuthConfig.cs → ...nd/FwLite/FwLiteShared/Auth/AuthConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using FwLiteShared.Projects; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace FwLiteShared.Auth; | ||
|
||
public record ServerStatus(string DisplayName, bool LoggedIn, string? LoggedInAs, string? Authority); | ||
public class AuthService(LexboxProjectService lexboxProjectService, OAuthClientFactory clientFactory, IOptions<AuthConfig> options) | ||
{ | ||
public IAsyncEnumerable<ServerStatus> Servers() | ||
{ | ||
return lexboxProjectService.Servers().ToAsyncEnumerable().SelectAwait(async s => | ||
{ | ||
var currentName = await clientFactory.GetClient(s).GetCurrentName(); | ||
return new ServerStatus(s.DisplayName, | ||
!string.IsNullOrEmpty(currentName), | ||
currentName, | ||
s.Authority.Authority); | ||
}); | ||
} | ||
|
||
public async Task SignInWebView(LexboxServer server) | ||
{ | ||
var result = await clientFactory.GetClient(server).SignIn(string.Empty);//does nothing here | ||
if (!result.HandledBySystemWebView) throw new InvalidOperationException("Sign in not handled by system web view"); | ||
} | ||
|
||
public async Task<string> SignInWebApp(LexboxServer server, string returnUrl) | ||
{ | ||
var result = await clientFactory.GetClient(server).SignIn(returnUrl); | ||
if (result.HandledBySystemWebView) throw new InvalidOperationException("Sign in handled by system web view"); | ||
if (result.AuthUri is null) throw new InvalidOperationException("AuthUri is null"); | ||
return result.AuthUri.ToString(); | ||
} | ||
|
||
public async Task Logout(LexboxServer server) | ||
{ | ||
await clientFactory.GetClient(server).Logout(); | ||
} | ||
|
||
public async Task<string?> GetLoggedInName(LexboxServer server) | ||
{ | ||
return await clientFactory.GetClient(server).GetCurrentName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace FwLiteShared.Auth; | ||
|
||
public interface IRedirectUrlProvider | ||
{ | ||
string? GetRedirectUrl(); | ||
bool ShouldRecreateAuthHelper(string? redirectUrl); | ||
} |
5 changes: 3 additions & 2 deletions
5
.../FwLite/LocalWebApp/Auth/LoggerAdapter.cs → ...FwLite/FwLiteShared/Auth/LoggerAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Concurrent; | ||
using LcmCrdt; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace FwLiteShared.Auth; | ||
|
||
public class OAuthClientFactory(IServiceProvider provider, | ||
IOptions<AuthConfig> options, | ||
IRedirectUrlProvider? redirectUrlProvider, | ||
ILogger<OAuthClientFactory> logger) | ||
{ | ||
private readonly ConcurrentDictionary<string, OAuthClient> _helpers = new(); | ||
|
||
private string AuthorityKey(LexboxServer server) => "AuthHelper|" + server.Authority.Authority; | ||
|
||
/// <summary> | ||
/// gets an Auth Helper for the given server | ||
/// </summary> | ||
public OAuthClient GetClient(LexboxServer server) | ||
{ | ||
var helper = _helpers.GetOrAdd(AuthorityKey(server), | ||
static (host, arg) => ActivatorUtilities.CreateInstance<OAuthClient>(arg.provider, arg.server), | ||
(server, provider)); | ||
//an auth helper can get created based on the server host, however in development that will not be the same as the client host | ||
//so we need to recreate it if the host is not valid, this is only required when not using system web view login | ||
if (!options.Value.SystemWebViewLogin && redirectUrlProvider is not null && redirectUrlProvider.ShouldRecreateAuthHelper(helper.RedirectUrl)) | ||
{ | ||
logger.LogInformation("Recreating auth helper with Redirect Url {RedirectUrl}", helper.RedirectUrl); | ||
_helpers.TryRemove(AuthorityKey(server), out _); | ||
return GetClient(server); | ||
} | ||
|
||
return helper; | ||
} | ||
|
||
/// <summary> | ||
/// get auth helper for a given project | ||
/// </summary> | ||
public OAuthClient GetClient(ProjectData project) | ||
{ | ||
var originDomain = project.OriginDomain; | ||
if (string.IsNullOrEmpty(originDomain)) throw new InvalidOperationException("No origin domain in project data"); | ||
return GetClient(options.Value.GetServer(project)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...bApp/Utils/CancellationTokenExtensions.cs → ...LiteShared/CancellationTokenExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace LocalWebApp.Utils; | ||
namespace FwLiteShared; | ||
|
||
public static class CancellationTokenExtensions | ||
{ | ||
|
Oops, something went wrong.