-
-
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.
rework auth to use a list of servers (#1040)
* configure maui to use the system web view for oauth * rework servers to have a list of them. * rework home page to have a list of servers with each project on those servers. * don't push entry selection changes into browser history, back should take you home after you load a project * ensure only crdt projects are shown as synced * split loading local project and remote projects into two separate endpoints, this means the local list will load faster and not wait for a timeout if the user is offline * provide feedback indicating that remote projects are loading * use the Resilience extensions to retry on transient http failures
- Loading branch information
Showing
21 changed files
with
402 additions
and
217 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
using System.Security.AccessControl; | ||
using System.Web; | ||
using LocalWebApp.Auth; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace LocalWebApp.Routes; | ||
|
||
public static class AuthRoutes | ||
{ | ||
public const string CallbackRoute = "AuthRoutes_Callback"; | ||
public record ServerStatus(string DisplayName, bool LoggedIn, string? LoggedInAs); | ||
public static IEndpointConventionBuilder MapAuthRoutes(this WebApplication app) | ||
{ | ||
var group = app.MapGroup("/api/auth").WithOpenApi(); | ||
group.MapGet("/login/default", async (AuthHelpersFactory factory) => Results.Redirect(await factory.GetDefault().SignIn())); | ||
group.MapGet("/servers", (IOptions<AuthConfig> options, AuthHelpersFactory factory) => | ||
{ | ||
return options.Value.LexboxServers.ToAsyncEnumerable().SelectAwait(async s => | ||
{ | ||
var currentName = await factory.GetHelper(s).GetCurrentName(); | ||
return new ServerStatus(s.DisplayName, | ||
!string.IsNullOrEmpty(currentName), | ||
currentName); | ||
}); | ||
}); | ||
group.MapGet("/login/{server}", | ||
async (AuthHelpersFactory factory, string server, IOptions<AuthConfig> options) => | ||
{ | ||
var result = await factory.GetHelper(options.Value.GetServer(server)).SignIn(); | ||
if (result.HandledBySystemWebView) | ||
{ | ||
return Results.Redirect("/"); | ||
} | ||
if (result.AuthUri is null) throw new InvalidOperationException("AuthUri is null"); | ||
return Results.Redirect(result.AuthUri.ToString()); | ||
}); | ||
group.MapGet("/oauth-callback", | ||
async (OAuthService oAuthService, HttpContext context) => | ||
{ | ||
var uriBuilder = new UriBuilder(context.Request.Scheme, context.Request.Host.Host, context.Request.Host.Port ?? 80, context.Request.Path); | ||
var uriBuilder = new UriBuilder(context.Request.Scheme, | ||
context.Request.Host.Host, | ||
context.Request.Host.Port ?? 80, | ||
context.Request.Path); | ||
uriBuilder.Query = context.Request.QueryString.ToUriComponent(); | ||
await oAuthService.FinishLoginRequest(uriBuilder.Uri); | ||
return Results.Redirect("/"); | ||
}).WithName(CallbackRoute); | ||
group.MapGet("/me", async (AuthHelpersFactory factory) => new { name = await factory.GetDefault().GetCurrentName() }); | ||
group.MapGet("/logout/default", async (AuthHelpersFactory factory) => | ||
{ | ||
await factory.GetDefault().Logout(); | ||
return Results.Redirect("/"); | ||
}); | ||
group.MapGet("/me/{server}", | ||
async (AuthHelpersFactory factory, string server, IOptions<AuthConfig> options) => | ||
{ | ||
return new { name = await factory.GetHelper(options.Value.GetServer(server)).GetCurrentName() }; | ||
}); | ||
group.MapGet("/logout/{server}", | ||
async (AuthHelpersFactory factory, string server, IOptions<AuthConfig> options) => | ||
{ | ||
await factory.GetHelper(options.Value.GetServer(server)).Logout(); | ||
return Results.Redirect("/"); | ||
}); | ||
return group; | ||
} | ||
} |
Oops, something went wrong.