Skip to content

Commit 0dd924b

Browse files
authored
Added Auth.UI.WinUI3 and WinUI3 sample (#202)
* 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.
1 parent f0d02ee commit 0dd924b

File tree

88 files changed

+7327
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+7327
-2
lines changed

Firebase.Auth.sln

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29409.12
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33815.320
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.UI.UWP", "src\Auth.UI.UWP\Auth.UI.UWP.csproj", "{5DA67B23-1735-4021-A6A1-0637FEE30A4C}"
77
EndProject
@@ -43,6 +43,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D29A8029
4343
EndProject
4444
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.Tests.Integration", "tests\Auth.Tests.Integration\Auth.Tests.Integration.csproj", "{69BFF1A9-8384-4DD8-BD23-31E384D57499}"
4545
EndProject
46+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.UI.WinUI3", "src\Auth.UI.WinUI3\Auth.UI.WinUI3.csproj", "{8EF123F6-49F8-483A-B317-B2773F64F1A8}"
47+
EndProject
48+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Auth.WinUI3.Sample", "samples\WinUI3\Auth.WinUI3.Sample.csproj", "{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}"
49+
EndProject
4650
Global
4751
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4852
Debug|Any CPU = Debug|Any CPU
@@ -245,6 +249,56 @@ Global
245249
{69BFF1A9-8384-4DD8-BD23-31E384D57499}.Release|x64.Build.0 = Release|Any CPU
246250
{69BFF1A9-8384-4DD8-BD23-31E384D57499}.Release|x86.ActiveCfg = Release|Any CPU
247251
{69BFF1A9-8384-4DD8-BD23-31E384D57499}.Release|x86.Build.0 = Release|Any CPU
252+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
253+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
254+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM.ActiveCfg = Debug|Any CPU
255+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM.Build.0 = Debug|Any CPU
256+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM64.ActiveCfg = Debug|Any CPU
257+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|ARM64.Build.0 = Debug|Any CPU
258+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x64.ActiveCfg = Debug|Any CPU
259+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x64.Build.0 = Debug|Any CPU
260+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x86.ActiveCfg = Debug|Any CPU
261+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Debug|x86.Build.0 = Debug|Any CPU
262+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
263+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|Any CPU.Build.0 = Release|Any CPU
264+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM.ActiveCfg = Release|Any CPU
265+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM.Build.0 = Release|Any CPU
266+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM64.ActiveCfg = Release|Any CPU
267+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|ARM64.Build.0 = Release|Any CPU
268+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x64.ActiveCfg = Release|Any CPU
269+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x64.Build.0 = Release|Any CPU
270+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x86.ActiveCfg = Release|Any CPU
271+
{8EF123F6-49F8-483A-B317-B2773F64F1A8}.Release|x86.Build.0 = Release|Any CPU
272+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|Any CPU.ActiveCfg = Debug|x64
273+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|Any CPU.Build.0 = Debug|x64
274+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|Any CPU.Deploy.0 = Debug|x64
275+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM.ActiveCfg = Debug|ARM
276+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM.Build.0 = Debug|ARM
277+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM.Deploy.0 = Debug|ARM
278+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM64.ActiveCfg = Debug|ARM64
279+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM64.Build.0 = Debug|ARM64
280+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|ARM64.Deploy.0 = Debug|ARM64
281+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x64.ActiveCfg = Debug|x64
282+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x64.Build.0 = Debug|x64
283+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x64.Deploy.0 = Debug|x64
284+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x86.ActiveCfg = Debug|x86
285+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x86.Build.0 = Debug|x86
286+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Debug|x86.Deploy.0 = Debug|x86
287+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|Any CPU.ActiveCfg = Release|x64
288+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|Any CPU.Build.0 = Release|x64
289+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|Any CPU.Deploy.0 = Release|x64
290+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM.ActiveCfg = Release|ARM
291+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM.Build.0 = Release|ARM
292+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM.Deploy.0 = Release|ARM
293+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM64.ActiveCfg = Release|ARM64
294+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM64.Build.0 = Release|ARM64
295+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|ARM64.Deploy.0 = Release|ARM64
296+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x64.ActiveCfg = Release|x64
297+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x64.Build.0 = Release|x64
298+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x64.Deploy.0 = Release|x64
299+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x86.ActiveCfg = Release|x86
300+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x86.Build.0 = Release|x86
301+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D}.Release|x86.Deploy.0 = Release|x86
248302
EndGlobalSection
249303
GlobalSection(SolutionProperties) = preSolution
250304
HideSolutionNode = FALSE
@@ -255,6 +309,7 @@ Global
255309
{E6905FEE-0871-48BE-933D-7F7102C06648} = {CF8B7ECC-0E53-4B26-ABB3-0D74BDBB642F}
256310
{31FAEF42-D294-4269-94B8-D5AE76CDF964} = {5528D6EA-402F-4FD9-9A01-0B799AFFC14B}
257311
{69BFF1A9-8384-4DD8-BD23-31E384D57499} = {5528D6EA-402F-4FD9-9A01-0B799AFFC14B}
312+
{4D7E8D5F-9DB9-46B3-99F3-2D768BBAA92D} = {CF8B7ECC-0E53-4B26-ABB3-0D74BDBB642F}
258313
EndGlobalSection
259314
GlobalSection(ExtensibilityGlobals) = postSolution
260315
SolutionGuid = {EBE8EC40-A988-4401-8C7E-61E1165C7D46}

samples/WinUI3/App.xaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Application
2+
x:Class="Auth.WinUI3.Sample.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Auth.WinUI3.Sample">
6+
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
<ResourceDictionary.ThemeDictionaries>
10+
<ResourceDictionary x:Key="Default">
11+
<SolidColorBrush x:Key="FuiErrorTextBlockForeground" Color="Blue" />
12+
</ResourceDictionary>
13+
</ResourceDictionary.ThemeDictionaries>
14+
</ResourceDictionary>
15+
</Application.Resources>
16+
17+
</Application>

samples/WinUI3/App.xaml.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using Firebase.Auth;
2+
using Firebase.Auth.Providers;
3+
using Firebase.Auth.Repository;
4+
using Firebase.Auth.UI;
5+
using Microsoft.UI.Dispatching;
6+
using Microsoft.UI.Xaml;
7+
using Microsoft.UI.Xaml.Controls;
8+
using Microsoft.Windows.AppLifecycle;
9+
using System;
10+
using Windows.Globalization;
11+
12+
namespace Auth.WinUI3.Sample
13+
{
14+
public partial class App : Application
15+
{
16+
public App()
17+
{
18+
this.InitializeComponent();
19+
20+
// Force override culture & language
21+
ApplicationLanguages.PrimaryLanguageOverride = "cs";
22+
23+
// Firebase UI initialization
24+
FirebaseUI.Initialize(new FirebaseUIConfig
25+
{
26+
ApiKey = "<YOUR API KEY>",
27+
AuthDomain = "<YOUR PROJECT DOMAIN>.firebaseapp.com",
28+
Providers = new FirebaseAuthProvider[]
29+
{
30+
new GoogleProvider(),
31+
new FacebookProvider(),
32+
new AppleProvider(),
33+
new TwitterProvider(),
34+
new GithubProvider(),
35+
new MicrosoftProvider(),
36+
new EmailProvider()
37+
},
38+
PrivacyPolicyUrl = "https://github.com/step-up-labs/firebase-authentication-dotnet",
39+
TermsOfServiceUrl = "https://github.com/step-up-labs/firebase-database-dotnet",
40+
IsAnonymousAllowed = true,
41+
AutoUpgradeAnonymousUsers = true,
42+
UserRepository = new StorageRepository(),
43+
// Func called when upgrade of anonymous user fails because the user already exists
44+
// You should grab any data created under your anonymous user, sign in with the pending credential
45+
// and copy the existing data to the new user
46+
// see details here: https://github.com/firebase/firebaseui-web#upgrading-anonymous-users
47+
AnonymousUpgradeConflict = conflict => conflict.SignInWithPendingCredentialAsync(true)
48+
});
49+
}
50+
51+
private void AuthStateChanged(object sender, UserEventArgs e)
52+
{
53+
dispatcherQueue.TryEnqueue(
54+
async () =>
55+
{
56+
if (e.User == null)
57+
{
58+
await FirebaseUI.Instance.Client.SignInAnonymouslyAsync();
59+
(Window.Content as Frame).Navigate(typeof(LoginPage));
60+
}
61+
else if (e.User.IsAnonymous)
62+
{
63+
(Window.Content as Frame).Navigate(typeof(LoginPage));
64+
}
65+
else if (Window.Content == null || Window.Content.GetType() != typeof(MainPage))
66+
{
67+
(Window.Content as Frame).Navigate(typeof(MainPage));
68+
}
69+
});
70+
}
71+
72+
73+
protected override async void OnLaunched(LaunchActivatedEventArgs e)
74+
{
75+
var mainInstance = AppInstance.FindOrRegisterForKey("main");
76+
var activatedEventArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
77+
78+
if (!mainInstance.IsCurrent)
79+
{
80+
// Redirect the activation (and args) to the "main" instance, and exit.
81+
await mainInstance.RedirectActivationToAsync(activatedEventArgs);
82+
System.Diagnostics.Process.GetCurrentProcess().Kill();
83+
return;
84+
}
85+
86+
dispatcherQueue = DispatcherQueue.GetForCurrentThread();
87+
88+
if (Window == null)
89+
{
90+
FirebaseUI.Instance.Client.AuthStateChanged += this.AuthStateChanged;
91+
}
92+
93+
Window = new MainWindow();
94+
Frame rootFrame = new Frame();
95+
rootFrame.Navigate(typeof(MainPage));
96+
Window.Content = rootFrame;
97+
Window.Activate();
98+
WindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(Window);
99+
}
100+
101+
private DispatcherQueue dispatcherQueue;
102+
103+
public static MainWindow Window { get; private set; }
104+
105+
public static IntPtr WindowHandle { get; private set; }
106+
}
107+
}
15.5 KB
Loading
10.7 KB
Loading
1.34 KB
Loading
6.52 KB
Loading
1.4 KB
Loading
5.56 KB
Loading

samples/WinUI3/Assets/firebase.png

11.5 KB
Loading

0 commit comments

Comments
 (0)