Neighbourhood.omg.lol/LoginWebViewPage.xaml.cs
Gordon Pedersen 5fb95c8305 Added auth.
Unfortunately it does not refresh at first login. Have to figure out how to make it refresh
2024-05-31 23:16:09 +10:00

37 lines
No EOL
1.3 KiB
C#

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; }
public LoginWebViewPage(AuthenticationStateProvider authStateProvider)
{
this.AuthStateProvider = authStateProvider;
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);
await Shell.Current.GoToAsync("..");
}
}
}
}
}