Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

feat: Adding Uno sample #629

Merged
merged 10 commits into from
Apr 7, 2023
Merged

feat: Adding Uno sample #629

merged 10 commits into from
Apr 7, 2023

Conversation

nickrandolph
Copy link
Contributor

No description provided.

@adrianhall adrianhall self-requested a review February 24, 2023 16:23
@adrianhall
Copy link
Member

When I first loaded the solution, I got a brown banner at the top that said "one or more projects have changes that cannot be resolved by the project manager. Reload projects" - the "Todo.Uno.Mobile" project had errors related to missing targets.

Clicking the "Reload projects" solved the problem. Is this something we can do for the user, or do I need to instruct the user to do this?

@adrianhall
Copy link
Member

Solved the MSAL issues (including the TFM stuff) by simplifying the PublicClientApplicationBuilder to the following, and switching to Uno.WinUI.MSAL:

#if ANDROID || IOS
        string redirectUri = $"msal{Constants.ApplicationId}://auth";
#else
        string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient";
#endif
        _identityClient = PublicClientApplicationBuilder
            .Create(Constants.ApplicationId)
            .WithAuthority(AzureCloudInstance.AzurePublic, "common")
            .WithRedirectUri(redirectUri)
            .WithUnoHelpers()
            .Build();

New error during build:

3>obj\Debug\net7.0-android\android\AndroidManifest.xml : warning XA4218: Unable to find //manifest/application/uses-library at path: C:\Program Files (x86)\Android\android-sdk\platforms\android-33\optional\androidx.window.extensions.jar
3>obj\Debug\net7.0-android\android\AndroidManifest.xml : warning XA4218: Unable to find //manifest/application/uses-library at path: C:\Program Files (x86)\Android\android-sdk\platforms\android-33\optional\androidx.window.sidecar.jar

My AndroidManifest.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <application>
	  <activity android:name="microsoft.identity.client.BrowserTabActivity" android:configChanges="orientation|screenSize" android:exported="true">
		  <intent-filter>
			  <action android:name="android.intent.action.VIEW" />
			  <category android:name="android.intent.category.DEFAULT" />
			  <category android:name="android.intent.category.BROWSABLE" />
			  <data android:scheme="msal2160b3eb-9ce1-4d3a-abc0-d37a45cd2e59" android:host="auth" />
		  </intent-filter>
	  </activity>
  </application>
</manifest>

And MainActivity.Android.cs looks like this:

using Android.App;
using Android.Content;
using Android.Views;
using Microsoft.Identity.Client;

namespace TodoApp.Uno
{
    [Activity(
			MainLauncher = true,
			ConfigurationChanges = global::Uno.UI.ActivityHelper.AllConfigChanges,
			WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden
		)]
	public class MainActivity : Microsoft.UI.Xaml.ApplicationActivity
	{
		protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
		{
			base.OnActivityResult(requestCode, resultCode, data);
			AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
		}
	}
}

@nickrandolph
Copy link
Contributor Author

When I first loaded the solution, I got a brown banner at the top that said "one or more projects have changes that cannot be resolved by the project manager. Reload projects" - the "Todo.Uno.Mobile" project had errors related to missing targets.

Clicking the "Reload projects" solved the problem. Is this something we can do for the user, or do I need to instruct the user to do this?

There doesn't seem to be a workaround for this at the moment, so just need to flag as known warning for the user

@nickrandolph
Copy link
Contributor Author

Solved the MSAL issues (including the TFM stuff) by simplifying the PublicClientApplicationBuilder to the following, and switching to Uno.WinUI.MSAL:

#if ANDROID || IOS
        string redirectUri = $"msal{Constants.ApplicationId}://auth";
#else
        string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient";
#endif
        _identityClient = PublicClientApplicationBuilder
            .Create(Constants.ApplicationId)
            .WithAuthority(AzureCloudInstance.AzurePublic, "common")
            .WithRedirectUri(redirectUri)
            .WithUnoHelpers()
            .Build();

New error during build:

3>obj\Debug\net7.0-android\android\AndroidManifest.xml : warning XA4218: Unable to find //manifest/application/uses-library at path: C:\Program Files (x86)\Android\android-sdk\platforms\android-33\optional\androidx.window.extensions.jar 3>obj\Debug\net7.0-android\android\AndroidManifest.xml : warning XA4218: Unable to find //manifest/application/uses-library at path: C:\Program Files (x86)\Android\android-sdk\platforms\android-33\optional\androidx.window.sidecar.jar

My AndroidManifest.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <application>
	  <activity android:name="microsoft.identity.client.BrowserTabActivity" android:configChanges="orientation|screenSize" android:exported="true">
		  <intent-filter>
			  <action android:name="android.intent.action.VIEW" />
			  <category android:name="android.intent.category.DEFAULT" />
			  <category android:name="android.intent.category.BROWSABLE" />
			  <data android:scheme="msal2160b3eb-9ce1-4d3a-abc0-d37a45cd2e59" android:host="auth" />
		  </intent-filter>
	  </activity>
  </application>
</manifest>

And MainActivity.Android.cs looks like this:

using Android.App;
using Android.Content;
using Android.Views;
using Microsoft.Identity.Client;

namespace TodoApp.Uno
{
    [Activity(
			MainLauncher = true,
			ConfigurationChanges = global::Uno.UI.ActivityHelper.AllConfigChanges,
			WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden
		)]
	public class MainActivity : Microsoft.UI.Xaml.ApplicationActivity
	{
		protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
		{
			base.OnActivityResult(requestCode, resultCode, data);
			AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
		}
	}
}

Yes, Uno.WinUI.MSAL is the main fix for getting auth to work. I'll send you the details

@nickrandolph nickrandolph marked this pull request as ready for review April 3, 2023 06:45
@adrianhall adrianhall merged commit 05ec3ba into Azure:main Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants