Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MAUI beta SDK #13

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions Auth0/Auth0Client.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Auth0/Auth0ClientOptions.cs

This file was deleted.

40 changes: 0 additions & 40 deletions Auth0/WebBrowserAuthenticator.cs

This file was deleted.

42 changes: 0 additions & 42 deletions Auth0/WebViewBrowserAuthenticator.cs

This file was deleted.

2 changes: 0 additions & 2 deletions MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
SemanticProperties.Hint="Click to log in"
Clicked="OnLoginClicked"
HorizontalOptions="Center" />

<WebView x:Name="WebViewInstance" />
</StackLayout>

<StackLayout
Expand Down
62 changes: 30 additions & 32 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
using MauiAuth0App.Auth0;

namespace MauiAuth0App;

public partial class MainPage : ContentPage
{
int count = 0;
using Auth0.OidcClient;
using IdentityModel.OidcClient;
using IdentityModel.OidcClient.Browser;

namespace MauiAuth0App;

public partial class MainPage : ContentPage
{
int count = 0;
private readonly Auth0Client auth0Client;

public MainPage(Auth0Client client)
{
InitializeComponent();
public MainPage(Auth0Client client)
{
InitializeComponent();
auth0Client = client;
}

private void OnCounterClicked(object sender, EventArgs e)
{
count++;

#if WINDOWS
auth0Client.Browser = new WebViewBrowserAuthenticator(WebViewInstance);
#endif
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";

SemanticScreenReader.Announce(CounterBtn.Text);
}

private void OnCounterClicked(object sender, EventArgs e)
{
count++;

if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";

SemanticScreenReader.Announce(CounterBtn.Text);
}

private async void OnLoginClicked(object sender, EventArgs e)
{
var loginResult = await auth0Client.LoginAsync();
Expand All @@ -46,21 +44,21 @@ private async void OnLoginClicked(object sender, EventArgs e)
{
await DisplayAlert("Error", loginResult.ErrorDescription, "OK");
}
}
}

private async void OnLogoutClicked(object sender, EventArgs e)
{
var logoutResult = await auth0Client.LogoutAsync();

if (!logoutResult.IsError)
if (logoutResult == BrowserResultType.Success)
{
HomeView.IsVisible = false;
LoginView.IsVisible = true;
}
else
{
await DisplayAlert("Error", logoutResult.ErrorDescription, "OK");
await DisplayAlert("Error", logoutResult.ToString(), "OK");
}
}
}
}
}

3 changes: 2 additions & 1 deletion MauiAuth0App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="IdentityModel.OidcClient" Version="5.0.2" />
<PackageReference Include="Auth0.OidcClient.MAUI" Version="1.0.0-beta.1" />
<PackageReference Include="IdentityModel.OidcClient" Version="5.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0-rc.2.22472.3" />
</ItemGroup>

Expand Down
9 changes: 3 additions & 6 deletions MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Logging;
using MauiAuth0App.Auth0;
using Auth0.OidcClient;

namespace MauiAuth0App;

Expand Down Expand Up @@ -27,11 +27,8 @@ public static MauiApp CreateMauiApp()
Domain = "<YOUR_AUTH0_DOMAIN>",
ClientId = "<YOUR_CLIENT_ID>",
Scope = "openid profile",
#if WINDOWS
RedirectUri = "http://localhost/callback"
#else
RedirectUri = "myapp://callback"
#endif
RedirectUri = "myapp://callback",
PostLogoutRedirectUri = "myapp://callback"
}));

return builder.Build();
Expand Down
3 changes: 3 additions & 0 deletions Platforms/Windows/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public partial class App : MauiWinUIApplication
/// </summary>
public App()
{
if (Auth0.OidcClient.Platforms.Windows.Activator.Default.CheckRedirectionActivation())
return;

this.InitializeComponent();
}

Expand Down