37 lines
1.3 KiB
C#
37 lines
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("..");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|