我们的应用程序的毛伊岛版本中的 Azure 登录不起作用。 它与 Xamarin 配合良好(过去 4 年)。 在毛伊岛,当我们登录 Azure 时,系统永远不会提示我们输入应用程序。 相反,它只是弹回到应用程序,而不发出令牌。
这说明了问题:
如上所示,从 Xamarin 启动序列时,最后一步是提示选择应用程序“仅一次”或“始终”。 由于某些奇怪的原因,该应用程序的 MAUI 版本从未发生过最后一步。
应用程序中启动序列的代码如下所示:
try
{
AuthResult = await PCA.AcquireTokenInteractive(_scopes)
.WithAuthority(AUTHORITY_URI)
.WithParentActivityOrWindow(theParentWindow)
.WithPrompt(Prompt.ForceLogin)
.ExecuteAsync();
}
catch (Exception ex2)
{
SetAuthToken(null);
throw new ApplicationException("Interactive login failed", ex2);
}
SetAuthToken(AuthResult?.AccessToken);
Xamarin 下的清单看起来像这样
<application android:label="Our App" android:icon="@drawable/Logo_Sized" android:debuggable="true" android:networkSecurityConfig="@xml/network_security_config">
<activity android:name="microsoft.identity.client.BrowserTabActivity" android:configChanges="orientation|screenSize">
<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="msal5af1aeaa-5a52-4699-8273-ec10b68ebfb2" android:host="auth" />
</intent-filter>
</activity>
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.company.ourapp.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
MAUI 下的清单基本相同:
<application android:allowBackup="true" android:icon="@mipmap/app_logo" android:supportsRtl="true" android:label="Our App" android:usesCleartextTraffic="true" android:debuggable="true">
<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="msal5af1aeaa-5a52-4699-8273-ec10b68ebfb2" android:host="auth" />
</intent-filter>
</activity>
<provider android:name="androidx.core.content.FileProvider" android:authorities="com.company.ourapp.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
我不知道为什么从 Xamarin 与毛伊岛版本的应用程序启动时,Azure 中的行为会有所不同。 有人能看出毛伊岛版本有什么不同吗?
在这里发现问题。 MsalActivity 未包含在移植的 Maui 项目中。 在 MainActivity 中添加该类以及代码行以继续授权解决了问题:
[Activity( Exported=true )]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault },
DataHost = "auth",
DataScheme = "msal5af1aeaa-5a52-4699-8273-ec10b68ebfb2")]
public class MsalActivity : BrowserTabActivity
{
}
MainActivity 中的代码...
protected override void OnActivityResult(int requestCode, Result resultCode, Intent? data)
{
// this was already here...
if (requestCode == CheckPermissionManager.CheckPermission.RequestCode)
CheckPermissionManager.CheckPermission.OnActivityResult();
base.OnActivityResult(requestCode, resultCode, data);
// added this...
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
}