Skip to content

Commit

Permalink
Added Auth.UI.WinUI3 and WinUI3 sample (#202)
Browse files Browse the repository at this point in the history
* Initial code for WinUI3 library and sample.

* Fixed some namespaces and resource names.

* Fixed Dispatcher and resource dictionary issues.

* Updated message boxes and dispatcher queue to WinUI3.
Temporarily commented ProgressBar.

* WebAuthenticationBroker implementation for WinUi3.

* Added full-trust permission to WinUI3 sample.

* Fixed launchSettings.json

* Added nuget information for Auth.UI.WinUI3.

* dispatcherQueue and Anonymous user changes.
  • Loading branch information
anovik authored Sep 6, 2023
1 parent f0d02ee commit 0dd924b
Show file tree
Hide file tree
Showing 88 changed files with 7,327 additions and 2 deletions.
59 changes: 57 additions & 2 deletions Firebase.Auth.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29409.12
# Visual Studio Version 17
VisualStudioVersion = 17.6.33815.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.UI.UWP", "src\Auth.UI.UWP\Auth.UI.UWP.csproj", "{5DA67B23-1735-4021-A6A1-0637FEE30A4C}"
EndProject
Expand Down Expand Up @@ -43,6 +43,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D29A8029
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.Tests.Integration", "tests\Auth.Tests.Integration\Auth.Tests.Integration.csproj", "{69BFF1A9-8384-4DD8-BD23-31E384D57499}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.UI.WinUI3", "src\Auth.UI.WinUI3\Auth.UI.WinUI3.csproj", "{8EF123F6-49F8-483A-B317-B2773F64F1A8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.WinUI3.Sample", "samples\WinUI3\Auth.WinUI3.Sample.csproj", "{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -245,6 +249,56 @@ Global
{69BFF1A9-8384-4DD8-BD23-31E384D57499}.Release|x64.Build.0 = Release|Any CPU
{69BFF1A9-8384-4DD8-BD23-31E384D57499}.Release|x86.ActiveCfg = Release|Any CPU
{69BFF1A9-8384-4DD8-BD23-31E384D57499}.Release|x86.Build.0 = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM.ActiveCfg = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM.Build.0 = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM64.Build.0 = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x64.ActiveCfg = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x64.Build.0 = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x86.ActiveCfg = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x86.Build.0 = Debug|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|Any CPU.Build.0 = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM.ActiveCfg = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM.Build.0 = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM64.ActiveCfg = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM64.Build.0 = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x64.ActiveCfg = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x64.Build.0 = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x86.ActiveCfg = Release|Any CPU
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x86.Build.0 = Release|Any CPU
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|Any CPU.ActiveCfg = Debug|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|Any CPU.Build.0 = Debug|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|Any CPU.Deploy.0 = Debug|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM.ActiveCfg = Debug|ARM
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM.Build.0 = Debug|ARM
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM.Deploy.0 = Debug|ARM
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM64.ActiveCfg = Debug|ARM64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM64.Build.0 = Debug|ARM64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM64.Deploy.0 = Debug|ARM64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x64.ActiveCfg = Debug|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x64.Build.0 = Debug|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x64.Deploy.0 = Debug|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x86.ActiveCfg = Debug|x86
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x86.Build.0 = Debug|x86
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x86.Deploy.0 = Debug|x86
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|Any CPU.ActiveCfg = Release|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|Any CPU.Build.0 = Release|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|Any CPU.Deploy.0 = Release|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM.ActiveCfg = Release|ARM
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM.Build.0 = Release|ARM
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM.Deploy.0 = Release|ARM
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM64.ActiveCfg = Release|ARM64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM64.Build.0 = Release|ARM64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM64.Deploy.0 = Release|ARM64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x64.ActiveCfg = Release|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x64.Build.0 = Release|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x64.Deploy.0 = Release|x64
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x86.ActiveCfg = Release|x86
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x86.Build.0 = Release|x86
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -255,6 +309,7 @@ Global
{E6905FEE-0871-48BE-933D-7F7102C06648} = {CF8B7ECC-0E53-4B26-ABB3-0D74BDBB642F}
{31FAEF42-D294-4269-94B8-D5AE76CDF964} = {5528D6EA-402F-4FD9-9A01-0B799AFFC14B}
{69BFF1A9-8384-4DD8-BD23-31E384D57499} = {5528D6EA-402F-4FD9-9A01-0B799AFFC14B}
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D} = {CF8B7ECC-0E53-4B26-ABB3-0D74BDBB642F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EBE8EC40-A988-4401-8C7E-61E1165C7D46}
Expand Down
17 changes: 17 additions & 0 deletions samples/WinUI3/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Application
x:Class="Auth.WinUI3.Sample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Auth.WinUI3.Sample">

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="FuiErrorTextBlockForeground" Color="Blue" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>

</Application>
107 changes: 107 additions & 0 deletions samples/WinUI3/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Firebase.Auth;
using Firebase.Auth.Providers;
using Firebase.Auth.Repository;
using Firebase.Auth.UI;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.AppLifecycle;
using System;
using Windows.Globalization;

namespace Auth.WinUI3.Sample
{
public partial class App : Application
{
public App()
{
this.InitializeComponent();

// Force override culture & language
ApplicationLanguages.PrimaryLanguageOverride = "cs";

// Firebase UI initialization
FirebaseUI.Initialize(new FirebaseUIConfig
{
ApiKey = "<YOUR API KEY>",
AuthDomain = "<YOUR PROJECT DOMAIN>.firebaseapp.com",
Providers = new FirebaseAuthProvider[]
{
new GoogleProvider(),
new FacebookProvider(),
new AppleProvider(),
new TwitterProvider(),
new GithubProvider(),
new MicrosoftProvider(),
new EmailProvider()
},
PrivacyPolicyUrl = "https://github.com/step-up-labs/firebase-authentication-dotnet",
TermsOfServiceUrl = "https://github.com/step-up-labs/firebase-database-dotnet",
IsAnonymousAllowed = true,
AutoUpgradeAnonymousUsers = true,
UserRepository = new StorageRepository(),
// Func called when upgrade of anonymous user fails because the user already exists
// You should grab any data created under your anonymous user, sign in with the pending credential
// and copy the existing data to the new user
// see details here: https://github.com/firebase/firebaseui-web#upgrading-anonymous-users
AnonymousUpgradeConflict = conflict => conflict.SignInWithPendingCredentialAsync(true)
});
}

private void AuthStateChanged(object sender, UserEventArgs e)
{
dispatcherQueue.TryEnqueue(
async () =>
{
if (e.User == null)
{
await FirebaseUI.Instance.Client.SignInAnonymouslyAsync();
(Window.Content as Frame).Navigate(typeof(LoginPage));
}
else if (e.User.IsAnonymous)
{
(Window.Content as Frame).Navigate(typeof(LoginPage));
}
else if (Window.Content == null || Window.Content.GetType() != typeof(MainPage))
{
(Window.Content as Frame).Navigate(typeof(MainPage));
}
});
}


protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
var mainInstance = AppInstance.FindOrRegisterForKey("main");
var activatedEventArgs = AppInstance.GetCurrent().GetActivatedEventArgs();

if (!mainInstance.IsCurrent)
{
// Redirect the activation (and args) to the "main" instance, and exit.
await mainInstance.RedirectActivationToAsync(activatedEventArgs);
System.Diagnostics.Process.GetCurrentProcess().Kill();
return;
}

dispatcherQueue = DispatcherQueue.GetForCurrentThread();

if (Window == null)
{
FirebaseUI.Instance.Client.AuthStateChanged += this.AuthStateChanged;
}

Window = new MainWindow();
Frame rootFrame = new Frame();
rootFrame.Navigate(typeof(MainPage));
Window.Content = rootFrame;
Window.Activate();
WindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(Window);
}

private DispatcherQueue dispatcherQueue;

public static MainWindow Window { get; private set; }

public static IntPtr WindowHandle { get; private set; }
}
}
Binary file added samples/WinUI3/Assets/SplashScreen.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/WinUI3/Assets/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/WinUI3/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/WinUI3/Assets/StoreLogo.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/WinUI3/Assets/firebase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0dd924b

Please sign in to comment.