using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using System.Diagnostics; using System.Web; namespace Neighbourhood.omg.lol; public partial class LoginWebViewPage : ContentPage { private AuthenticationStateProvider AuthStateProvider { get; set; } private NavigatorService NavigatorService { get; set; } public LoginWebViewPage(AuthenticationStateProvider authStateProvider, NavigatorService navigatorService) { this.AuthStateProvider = authStateProvider; this.NavigatorService = navigatorService; InitializeComponent(); this.loginwebview.Source = "https://home.omg.lol/oauth/authorize?client_id=ea14dafd3e92cbcf93750c35cd81a031&scope=everything&redirect_uri=https://neatnik.net/adam/bucket/omgloloauth/&response_type=code"; } public async void loginwebview_Navigating(object sender, WebNavigatingEventArgs e) { if(e.Url.StartsWith("https://neatnik.net/adam/bucket/omgloloauth/")) { Debug.WriteLine("And here we go..."); Uri uri = new Uri(e.Url); var query = HttpUtility.ParseQueryString(uri.Query); string? code = query.Get("code"); if (!string.IsNullOrEmpty(code)) { RestService api = new RestService(); string? token = await api.OAuth(code); if (!string.IsNullOrEmpty(token)) { Debug.WriteLine($"Fuck yeah, a token! {token}"); await ((CustomAuthenticationStateProvider)this.AuthStateProvider).Login(token); NavigatorService.NavigationManager.NavigateTo(NavigatorService.NavigationManager.Uri, forceLoad: true); await Shell.Current.GoToAsync(".."); } } } } }