Reputation: 946
I have a Xamarin Forms application that uses azure active directory authentication.
I was using NuGet packet Microsoft.Azure.Mobile.Client version 3.1.0, and the signature for the LoginAsync
function for the class MobileServiceClient
was
Task<MobileServiceUser> LoginAsync(UIViewController view, MobileServiceAuthenticationProvider provider);
for iOS and a similar signature for Android. Therefore, my Login function on iOS was like this:
var window = UIKit.UIApplication.SharedApplication.KeyWindow;
var current = window.RootViewController;
while(current.PresentedViewController != null) {
current = current.PresentedViewController;
}
var user = await MSC.LoginAsync(current, MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
return user;
Using this function, the library would send the application to the azure active directory web page for login or signup and return a MobileServiceUser
instance.
That version was working as expected.
However, due to some issues in other parts of the app, I had to update the NuGet packet to a newer version, in this case it's 4.0.2. The Login function changed signature to
Task<MobileServiceUser> LoginAsync(MobileServiceAuthenticationProvider provider, JObject token);
I don't know what to do with the last parameter in order to have the same behavior it used to have. Passing null
throws an exception and passing a new JObject class does not work.
Upvotes: 0
Views: 728
Reputation: 18465
var user = await MSC.LoginAsync(current, MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
Based on the parameter you passed for logging under Microsoft.Azure.Mobile.Client v3.1.0, you are using Server-managed authentication which means that your mobile backend would help you to contact with the related identity provider and directly receive the token, then generate a authenticationToken
and return to the mobile client for subsequent authorized requests.
As Azure Mobile Apps Managed SDK Change Log about Version 4.0.0:
- Support of .NET Standard 1.4
- [Xamarin.Android] Support of server login flow to use Chrome CustomTabs on Android. It supports OAuth 2.0 PKCE extension.
- [Xamarin.iOS] Support of server login flow to use SafariViewController on iOS. It supports OAuth 2.0 PKCE extension.
- [UWP] Support of server login flow to use browser on Windows. It supports OAuth 2.0 PKCE extension.
In order to use the same authentication flow under version 4.0.0+, you need to use the following method overload:
var user = await TodoItemManager.DefaultManager.CurrentClient
.LoginAsync(MobileServiceAuthenticationProvider.Facebook, "{url_scheme_of_your_app}");
You could follow here for defining the URL scheme for your app on Azure Portal. For detailed steps, you could follow Add authentication to your Xamarin Forms app.
Task LoginAsync(MobileServiceAuthenticationProvider provider, JObject token);
For the above method overload of LoginAsync
which would use Client-managed authentication, for this approach, you need to directly contact with your identity provider for retrieving the token, then you need to send the token to your mobile backend for exchanging a authenticationToken
.
Upvotes: 1