Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin Forms, iOS Authentication with Azure Active Directory issue.

$
0
0

Hi. I have faced the issue while implementing authentication by using Azure AD with Xamarin Forms Application.
Application structure is following:
1. Application code and UI -layouts are implemented in PCL library.
2. Authentication uses "Dependency Service" and platform specific classes to perform authentication calls to Azure Mobile Service, which is used to as authentication source to client app.

Main issue is that call to Mobile Service authentication require UIViewController as parameter. I am not sure how get instance to that.
Can I create the Controller dynamically "On fly" and inject that to application during the execution.

Here is my iOS specific code for authentication:
[assembly: Dependency(typeof(Authenticate_iOS))]
namespace XamarinAzureMobileServiceDemo.iOS
{
public class Authenticate_iOS : IAuthentication
{
public MobileServiceUser user;
private MobileServiceClient MobileService = new MobileServiceClient("https://service..azure-mobile.net", "xxxxxxxxxxxxxxx");

    public async Task<MobileServiceUser> Authenticate(object view)
    {
        try
        {
            user = await MobileService.LoginAsync((UIViewController)view, MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory);
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(@"ERROR - AUTHENTICATION FAILED {0}", ex.Message);
        }

        return user;
    }
}

}

I have tried following to get UIViewControler required in above method example LoginAsync call:

namespace XamarinAzureMobileServiceDemo.iOS
{
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
UIWindow window;

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());

        window = new UIWindow(UIScreen.MainScreen.Bounds);

        window.RootViewController = App.GetMainPage().CreateViewController();
        window.MakeKeyAndVisible();

        CurrentPlatform.Init();

        return base.FinishedLaunching(app, options);
    }
}

}

But approach fills wrong since whole application is loaded from PCL project. Obviously the "Server authentication flow" is not way to go here?
For "Client authentication flow" there is Azure AD SDK code required and I found that iOS version SDK has being implemented in component store, but that requires some project building in xcode first then reference has to added to our iOS project, this sounds quite hazard approach.

Br, RMR


Viewing all articles
Browse latest Browse all 58056

Trending Articles