Xamarin Plaid OAuth - Does Xamarin's WebAuthenticator support redirects with https://?

269 Views Asked by At

I am trying to implement the banking Plaid OAuth portion of the API into my Xamarin app and have had plenty of troubles. For starters, Plaid requires an OAuth callback URL of https://yoururlhere.com which I cannot figure out for the life of me, if WebAuthenticator supports it. I have only seen examples of the packagename

Plaid does allow Android package names but not iOS... Should I be doing that instead? What happens then with iOS? I need to implement this for both Android and iOS. From my understanding, I am not leaving my Xamarin app as this is all done through a webview, therefore it doesnt really make sense to follow this approach correct?

To get a better sense of what I am trying to do, I have simplified my code and names below.
MainViewModel.cs

// successfully has linkToken before this point

var authResult = await WebAuthenticator.AuthenticateAsync(
    new Uri("https://cdn.plaid.com/link/v2/stable/link.html?isWebview=true&token=" + linkToken),
    new Uri("https://someurl.net/link/v2/oauth/redirect")
);

WebAuthenticationCallbackActivity.cs.

[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
     Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
     DataScheme = "https")]
public class WebAuthenticationCallbackActivity : Xamarin.Essentials.WebAuthenticatorCallbackActivity
{
     public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
     {
          base.OnCreate(savedInstanceState, persistentState);
     }
}

What should my datascheme be here? Just https://? or is it my full URL?

AndroidManifest.xaml
I have added the correct necessities here
I have not had a chance to look at the iOS necessities but we can ignore those for now.

I will also need to intercept this callback and make new http requests from the redirected URL to finalize the token, I am not sure how to do that either

Any help with implementing any part of this would be greatly appreciated

1

There are 1 best solutions below

0
Guangyu Bai - MSFT On

The Microsoft document provide the example about Xamarin.Essentials: Web Authenticator

For Android, Android requires an Intent Filter setup to handle your callback URI. This is easily accomplished by subclassing the WebAuthenticatorCallbackActivity class.

const string CALLBACK_SCHEME = "myapp";

[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
    Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
    DataScheme = CALLBACK_SCHEME)]
public class WebAuthenticationCallbackActivity : Xamarin.Essentials.WebAuthenticatorCallbackActivity
{
}