-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
88 changed files
with
7,327 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.