From 6231e893e40d23ff2b3771b25cddeee481ba6bba Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 28 Nov 2023 22:44:58 +0100 Subject: [PATCH] Enable authentication on Android --- .../MZikmund.Mobile/Android/AndroidManifest.xml | 7 ++++++- src/app/MZikmund.Mobile/Android/Main.Android.cs | 1 + .../Android/MainActivity.Android.cs | 7 +++++++ .../Android/MsalActivity.Android.cs | 15 +++++++++++++++ .../ViewModels/Admin/BlogPostsManagerViewModel.cs | 2 +- 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/app/MZikmund.Mobile/Android/MsalActivity.Android.cs diff --git a/src/app/MZikmund.Mobile/Android/AndroidManifest.xml b/src/app/MZikmund.Mobile/Android/AndroidManifest.xml index 95ae0753..c00ebe1e 100644 --- a/src/app/MZikmund.Mobile/Android/AndroidManifest.xml +++ b/src/app/MZikmund.Mobile/Android/AndroidManifest.xml @@ -1,4 +1,9 @@ - + + + + + + diff --git a/src/app/MZikmund.Mobile/Android/Main.Android.cs b/src/app/MZikmund.Mobile/Android/Main.Android.cs index f88a136d..76430dde 100644 --- a/src/app/MZikmund.Mobile/Android/Main.Android.cs +++ b/src/app/MZikmund.Mobile/Android/Main.Android.cs @@ -12,6 +12,7 @@ using Microsoft.UI.Xaml.Media; namespace MZikmund.Droid; + [global::Android.App.ApplicationAttribute( Label = "@string/ApplicationName", Icon = "@mipmap/icon", diff --git a/src/app/MZikmund.Mobile/Android/MainActivity.Android.cs b/src/app/MZikmund.Mobile/Android/MainActivity.Android.cs index 10e38257..3d276739 100644 --- a/src/app/MZikmund.Mobile/Android/MainActivity.Android.cs +++ b/src/app/MZikmund.Mobile/Android/MainActivity.Android.cs @@ -3,8 +3,10 @@ using Android.OS; using Android.Views; using Android.Widget; +using Microsoft.Identity.Client; namespace MZikmund.Droid; + [Activity( MainLauncher = true, ConfigurationChanges = global::Uno.UI.ActivityHelper.AllConfigChanges, @@ -12,4 +14,9 @@ namespace MZikmund.Droid; )] public class MainActivity : Microsoft.UI.Xaml.ApplicationActivity { + protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data) + { + base.OnActivityResult(requestCode, resultCode, data); + AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data); + } } diff --git a/src/app/MZikmund.Mobile/Android/MsalActivity.Android.cs b/src/app/MZikmund.Mobile/Android/MsalActivity.Android.cs new file mode 100644 index 00000000..8bb74592 --- /dev/null +++ b/src/app/MZikmund.Mobile/Android/MsalActivity.Android.cs @@ -0,0 +1,15 @@ +using Android.App; +using Android.Content.PM; +using Microsoft.Identity.Client; + +namespace MZikmund.Droid; + +[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)] +[IntentFilter( + new[] { Android.Content.Intent.ActionView }, + Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable }, + DataHost = "auth", + DataScheme = "msal7e13557a-4799-46b8-9e2b-0f31c41a051e")] +public class MsalActivity : BrowserTabActivity +{ +} diff --git a/src/app/MZikmund/ViewModels/Admin/BlogPostsManagerViewModel.cs b/src/app/MZikmund/ViewModels/Admin/BlogPostsManagerViewModel.cs index b854f873..4945d539 100644 --- a/src/app/MZikmund/ViewModels/Admin/BlogPostsManagerViewModel.cs +++ b/src/app/MZikmund/ViewModels/Admin/BlogPostsManagerViewModel.cs @@ -5,5 +5,5 @@ namespace MZikmund.ViewModels.Admin; public class BlogPostsManagerViewModel : PageViewModel { - public override string Title => Localizer.Instance.GetString("Posts"); + public override string Title => Localizer.Instance.GetString("BlogPosts"); }