Started testing oauth2 handler from mooncore
This commit is contained in:
78
Moonlight.Client/UI/Components/TestyHmm.razor
Normal file
78
Moonlight.Client/UI/Components/TestyHmm.razor
Normal file
@@ -0,0 +1,78 @@
|
||||
@using Microsoft.AspNetCore.WebUtilities
|
||||
@using MoonCore.Blazor.Services
|
||||
@using MoonCore.Exceptions
|
||||
@using MoonCore.Helpers
|
||||
@inherits ErrorBoundaryBase
|
||||
|
||||
@inject NavigationManager Navigation
|
||||
@inject OAuth2FrontendService OAuth2FrontendService
|
||||
|
||||
@if (IsCompleting)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ChildContent
|
||||
}
|
||||
|
||||
@code
|
||||
{
|
||||
private bool IsCompleting = false;
|
||||
private string Code;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var uri = new Uri(Navigation.Uri);
|
||||
|
||||
if (!QueryHelpers.ParseQuery(uri.Query).TryGetValue("code", out var codeSv))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (codeSv.Count == 0 || string.IsNullOrEmpty(codeSv.First()))
|
||||
return;
|
||||
|
||||
var code = codeSv.First();
|
||||
|
||||
Code = code!;
|
||||
IsCompleting = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("FUUCK");
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender)
|
||||
return;
|
||||
|
||||
if(!IsCompleting)
|
||||
return;
|
||||
|
||||
if (!await OAuth2FrontendService.Complete(Code))
|
||||
await RedirectToAuth();
|
||||
|
||||
IsCompleting = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
protected override async Task OnErrorAsync(Exception exception)
|
||||
{
|
||||
if (exception is not HttpApiException httpApiException || httpApiException.Status != 401)
|
||||
throw exception;
|
||||
|
||||
// If we reach this point, we got a 401 unauthenticated, so we need to log in
|
||||
await RedirectToAuth();
|
||||
}
|
||||
|
||||
private async Task RedirectToAuth()
|
||||
{
|
||||
var url = await OAuth2FrontendService.Start();
|
||||
Navigation.NavigateTo(url, true);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
@using Moonlight.Client.Interfaces
|
||||
@using Moonlight.Client.Services
|
||||
@using Moonlight.Client.UI.Partials
|
||||
@using MoonCore.Blazor.Components
|
||||
@using Moonlight.Client.UI.Components
|
||||
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@@ -35,17 +37,19 @@ else
|
||||
<div class="px-4 sm:px-6 lg:px-8">
|
||||
<ErrorHandler CustomHandler="HandleException">
|
||||
|
||||
<PermissionHandler CheckFunction="CheckPermission">
|
||||
<CascadingValue Value="this" IsFixed="true">
|
||||
@Body
|
||||
</CascadingValue>
|
||||
</PermissionHandler>
|
||||
|
||||
<TestyHmm>
|
||||
<PermissionHandler CheckFunction="CheckPermission">
|
||||
<CascadingValue Value="this" IsFixed="true">
|
||||
@Body
|
||||
</CascadingValue>
|
||||
</PermissionHandler>
|
||||
</TestyHmm>
|
||||
|
||||
</ErrorHandler>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -72,9 +76,9 @@ else
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(!firstRender)
|
||||
if (!firstRender)
|
||||
return;
|
||||
|
||||
|
||||
await Load();
|
||||
}
|
||||
|
||||
@@ -82,7 +86,7 @@ else
|
||||
{
|
||||
IsLoading = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
|
||||
//
|
||||
await RunLoaders();
|
||||
|
||||
@@ -126,7 +130,7 @@ else
|
||||
continue;
|
||||
|
||||
CurrentScreen = screen.Render();
|
||||
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
return;
|
||||
}
|
||||
@@ -143,7 +147,7 @@ else
|
||||
Task.Run(Load);
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user