Xamarin.Auth (CustomTabsConfiguration) using of FLAG_IMMUTABLE for Android 12

Mattia Vicari 16 Reputation points
2022-12-03T12:13:16.647+00:00

Good day everyone,
since Android 12 my App crashes during the auhtentication process.
I see in the console the following error:

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

I'm using the CustomTabs feature but I'm not able to force the PendingIntentFlag to Immutable (see the CustomTabsConfiguration). This issue has been reported in the GitHub project (https://github.com/xamarin/Xamarin.Auth/issues/459) but it seems that it won't be fixed.

My code is the following:

UriBuilder uriBuilder = new UriBuilder(authorizeUrl);  
string stateUrl = EncodeToBase64("redirect_to=" + redirectUrl.AbsoluteUri);  
uriBuilder.Query += "apsl_login_id=" + Uri.EscapeUriString(provider) + "&redirect_to=" + Uri.EscapeDataString(redirectUrl.AbsoluteUri) + "&state=" + Uri.EscapeUriString(stateUrl);  
  
var oAuth2 = new NativeWebRedirectAuthenticator(uriBuilder.Uri, tokenUrl);  
oAuth2.ClearCookiesBeforeLogin = true;  
oAuth2.Completed += OnOAuth2Completed;  
oAuth2.Error += OnOAuth2Error;  
Auth = oAuth2;  
  
CustomTabsConfiguration.CustomTabsClosingMessage = null;  
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();  
presenter.Login(oAuth2);  

Is it possible to wor karound this or force the Immutable flag in another way?

Thank you,

Best Regards

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,319 questions
{count} votes