auth0-samples / auth0-xamarin-oidc-samples

Auth0 OIDC Client with Xamarin applications
MIT License
30 stars 38 forks source link

Support for Xamarin.Forms on Android #6

Closed gitizenme closed 6 years ago

gitizenme commented 7 years ago

We have a use case that requires integration between Auth0 and Xamarin Forms. I have implemented the iOS version per the Xamarin SDK Quickstarts and it is working well. However, I am unable to implement the Android integration using the PageRenderer (see below) technique that is recommended by Xamarin. Guidance in the area would be really helpful.

`public class Auth0LoginPageRenderer : PageRenderer { Auth0LoginPage page; Auth0Client auth0;

    public Auth0LoginPageRenderer()
    {
        var options = new Auth0ClientOptions
        {
            Domain = ApiConfig.Auth0Domain,
            ClientId = ApiConfig.Auth0ClientId,
            Activity = Context as Android.App.Activity
        };
        auth0 = new Auth0Client(options);
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        Console.WriteLine("OnElementChanged: BEGIN");
        base.OnElementChanged(e);
        if (Element == null)
        {
            return;
        }
        page = Element as Auth0LoginPage;
    }

    protected override void OnAttachedToWindow()
    {
        Console.WriteLine("OnAttachedToWindow: BEGIN");
        base.OnAttachedToWindow();
        if (auth0 != null)
        {
            Task.FromResult(Login());
        }
    }

    async Task Login()
    {
        Console.WriteLine("Login: BEGIN");
        try
        {
            var loginResult = await auth0.LoginAsync(null);

            if (loginResult.IsError)
            {
                page.LoginFailed();
                MessagingCenter.Send("Failed", "LoginPageDone");
                Console.WriteLine("User login failed!");
            }
            else
            {
                UserProfile userProfile = new UserProfile();
                userProfile.AccessToken = loginResult.AccessToken;
                userProfile.IdToken = loginResult.IdentityToken;
                userProfile.RefreshToken = loginResult.RefreshToken;
                userProfile.AuthenticationTime = loginResult.AuthenticationTime;
                userProfile.AccessTokenExpiration = loginResult.AccessTokenExpiration;

                page.LoginSuccess(userProfile);
                MessagingCenter.Send("Success", "LoginPageDone");
            }
        }
        catch (TaskCanceledException ex)
        {
            System.Diagnostics.Debug.WriteLine(nameof(Auth0LoginPageRenderer) + nameof(Login) + ": " + ex);
            page.LoginCancelled();
        }
        catch (TaskSchedulerException ex)
        {
            System.Diagnostics.Debug.WriteLine(nameof(Auth0LoginPageRenderer) + nameof(Login) + ": " + ex);
            page.LoginFailed();
        }
    }

}

`

jerriep commented 7 years ago

@gitizenme Unfortunately I have no knowledge of Xamarin Forms in order to assist with this at this stage :(

As time allows in the future I can look into this for you if you are unable to find a solution.

gitizenme commented 7 years ago

I've gone another direction on this and am now using the Xamarin Dependency Service. I'm able to get through the login process up the point where the Android method protected override async void OnNewIntent(Intent intent) should be called on upon completion of the Auth0 login through Chrome. I've set a debug breakpoint in this method and it is not getting called.

Any guidance?

gitizenme commented 7 years ago

Okay, I'm stuck with an exception being generated from the Auth0Client constructor:

System.NullReferenceException: Object reference not set to an instance of an object. at Auth0.OidcClient.Auth0Client..ctor (Auth0.OidcClient.Auth0ClientOptions options) [0x00029] in <e5a765d3d03346a78f40e6ec304e7fac>:0 at BCXMobile.Droid.Auth0LoginImplemenation+<LoginAsync>d__7.MoveNext () [0x0001d] in /Users/joe/Projects/Convergence/Dev/projects/BCX/projects/mobile/BCX-Mobile/Droid/Auth0LoginImplemenation.cs:44 with a call: client = new Auth0Client(new Auth0ClientOptions { Domain = "FOOBAR.auth0.com", ClientId = "BASH", Activity = this });

Any chance I can grab the source code for the client?

jerriep commented 7 years ago

Yes, sure. Source code is over here: https://github.com/auth0/auth0-oidc-client-net

jerriep commented 7 years ago

@gitizenme Did you manage to get this one sorted?

gitizenme commented 7 years ago

No, we have a use case where we need to pass extra parameters to the underlying OIDC implementation that are not exposed in the Auth0 implementation.

jerriep commented 7 years ago

Can you please expand?

Do you need to pass parameters to Auth0? If so you can see an example of that over here: https://auth0.github.io/auth0-oidc-client-net/documentation/advanced-scenarios/api-authorization.html

dagostinelli commented 7 years ago

@gitizenme On this line, can you check that the Activity reference doesn't end up null after the as cast?

Activity = Context as Android.App.Activity

I also keep having problems. I'm interested in how you end up solving this.

jerriep commented 6 years ago

@gitizenme Are you still interested in Xamarin Forms support? I have something ready, and would like someone to play around with it

gitizenme commented 6 years ago

Yes, what are the details?

--
Joe Chavez

From: Jerrie Pelser notifications@github.com(mailto:notifications@github.com) Reply: auth0-community/auth0-xamarin-oidc-samples reply@reply.github.com(mailto:reply@reply.github.com) Date: April 11, 2018 at 5:17:25 AM To: auth0-community/auth0-xamarin-oidc-samples auth0-xamarin-oidc-samples@noreply.github.com(mailto:auth0-xamarin-oidc-samples@noreply.github.com) CC: Joe Chavez joe@izen.me(mailto:joe@izen.me), Mention mention@noreply.github.com(mailto:mention@noreply.github.com) Subject: Re: [auth0-community/auth0-xamarin-oidc-samples] Support for Xamarin.Forms on Android (#6)

@gitizenme(https://github.com/gitizenme) Are you still interested in Xamarin Forms support? I have something ready, and would like someone to play around with it

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub(https://github.com/auth0-community/auth0-xamarin-oidc-samples/issues/6#issuecomment-380431153), or mute the thread(https://github.com/notifications/unsubscribe-auth/AAnRsOYhuSP4E8QUQSzCFEixIzZDdGlCks5tnfRVgaJpZM4OewL4).

jerriep commented 6 years ago

@gitizenme

I have created a feed on MyGet with the beta packages: https://www.myget.org/F/auth0-oidcclient/api/v3/index.json

Please be sure to add this feed to your NuGet sources, so you can install packages from there.

Also, here is sample demonstrating how to use it: https://github.com/auth0-community/auth0-xamarin-oidc-samples/tree/XamarinForms/Samples/XamarinForms/FormsSample

That particular sample uses a shared project, but if you create seperate PCL or .NET Standard assembly for your Xamarin Forms, then this version includes a new package called Auth0.OidcClient.Core. This contains an IAuth0Client interface which you can use in your Forms assembly.

In that case you will also have to use Dependency Injection to inject the correct platform-specific instance.

Docs are a bit sparse at this stage, so feel free to ping me in you have any uncertainty. I would like to understand you use-case, so I can be sure we cater for as many scenarios as possible.

andrekiba commented 6 years ago

Hi and thanks in advance. I'm also very interested in Xamarin.Forms support for both Android and iOS. Is Auth0.Oidclient.Core reliable? A plan to publish it on "regular" nuget?

jerriep commented 6 years ago

@andrekiba Yes, the plan is definitely to release it on NuGet. But I need to get feedback from actual developers using this beta. So if you can check it out and give me feedback, it will be very helpful

andrekiba commented 6 years ago

ok! I try during the next days and I'll let you know before the weekend :-) Thank you! And a small question, for iOS the only thing I need to do (apart calling LoginAsync) is add the URL type inside Info.plist? In Android I still need to manage intent filers and OnNewIntent inside the MainActivity?

jerriep commented 6 years ago

Great, thanks!

for iOS the only thing I need to do (apart calling LoginAsync) is add the URL type inside Info.plist?

Yes

In Android I still need to manage intent filers and OnNewIntent inside the MainActivity?

Yes. Please also ensure to set the LaunchMode for the activity to SingleTask. See https://github.com/auth0-community/auth0-xamarin-oidc-samples/blob/XamarinForms/Samples/XamarinForms/FormsSample/Droid/MainActivity.cs#L13-L20

andrekiba commented 6 years ago

Hi @jerriep, the Auth0.Oidclient.Core seems to work correctly. I have a question: is there a way to retrieve user_metadata? In Auth0ClientOptions I have "openid profile email".

jerriep commented 6 years ago

You will need to write a rule and use custom claims. Please see this document: https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims

sdkraemer commented 6 years ago

@jerriep Xamarin noob here. Could you please provide a .net standard example project?

sdkraemer commented 6 years ago

@jerriep I asked too soon. This noob finally figured it out. Whether or not this is considered a correct way of doing it, I created an IAuth0ClientFactory interface on the main project side. Then created a platform specific classes that implement the interface and create an Auth0Client. I still think an example project provided by Auth0 might help out some people.

jerriep commented 6 years ago

Yes, the correct way is to reference IAuth0Client in your view model, and then instantiate and inject the correct implementation on each platform.

One of the reasons I have not done a sample like this is because I was not sure which dependency injection framework is the most common on Xamarin Forms and makes the most sense.

Which DI framework did you use?

sdkraemer commented 6 years ago

I used DependencyService from Xamarin.Forms. I'm not sure what is most common, but for someone starting out this is what I found first.

jerriep commented 6 years ago

Thanks @sdkraemer , I will add it to my to-do list to create a .NET Standard sample for Xamarin Forms.

lcm98 commented 6 years ago

Hey man, first of all, I'd like to really thank you for making this as it makes my life a million times easier.

Secondly, I'd like to ask if I'm using it correctly (lol). So I'm also using a project that uses the .Net Standard assembly in Xamarin.Form, and have added the Auth0.OidcClient.Core to the main project. Then I'll be using Dependency Injection based on the IAuth0Client interface for the platform specific implementation.

My question comes in here, do I want to implement those platform specific implementations myself, or should I be adding the nuget package for each platform respectively (Auth0.OidcClient.Andoird/iOS) and then the platform specific "implementations" would be me just returning the classes provided by the nuget packages.

Thanks again for the work you've done, and for your help!

jerriep commented 6 years ago

@lcm98 Yes, as you said, the main Xamarin Forms project should reference the Auth0.OidcClient.Core NuGet package and use IAuth0Client interface.

For each platform, you reference platform specific NuGet package (Auth0.OidcClient.Andoird/iOS) and set up your DI to inject an instance of the Auth0Client for that platform which is found in the relevant NuGet package.

The code to create a platform specific instance is as follows:

new Auth0Client(new Auth0ClientOptions
{
    Domain = "your_auth0_domain", // e.g. abc.auth0.com
    ClientId = "your_client_id"
});

How you inject that instance will depend on the DI framework you are using

lcm98 commented 6 years ago

Perfect, thanks again!

joshuatantonflynn commented 6 years ago

I'm getting the same error as OP! Android was working fine until I updated my NuGet to 2.0.0. Now there is no longer the Activity parameter in Auth0ClientOptions. I removed the parameter. But Now I am getting this NullReference Exception after defining my Auth0Client. Did anyone resolve this issue?

jerriep commented 6 years ago

Can you supply some sort of stack trace or, preferably, a sample project demonstrating the problem?

joshuatantonflynn commented 6 years ago

Jerrie,

Not sure how exactly to provide you with a stack trace without writing a bunch of logs in my code. Which would be about as helpful as my debugging attempts as the nullreference error happens in external code (constructor of Auth0Client).

The project is much to big to provide to you, I don't exactly have the time to prepare a sample project right now, but when I do have the time I will put one together for you.

For now I rolled back my packages to 1.2.0 as I know that works using the Activity parameter.

Do you have any knowledge of the reason for this (and the corresponding controller parameter for iOS) was removed? Is it possible that not having this is the cause of the error? But then why would this not happen on iOS when I removed the Controller parameter?

I seam to be having a similar problem as the one posted here, yet He was using the old version (which works for me). https://github.com/auth0-community/auth0-xamarin-oidc-samples/issues/6

Thanks,


Joshua Tanton Mobile and Web Developer Flynn Group of Companies C:+1.416.994.3012 joshua.tanton@flynncompanies.com https://flynncompanies.com From: Jerrie Pelser notifications@github.com Sent: Tuesday, June 19, 2018 11:21:32 AM To: auth0-community/auth0-xamarin-oidc-samples Cc: Joshua Tanton; Comment Subject: Re: [auth0-community/auth0-xamarin-oidc-samples] Support for Xamarin.Forms on Android (#6)

Can you supply some sort of stack trace or, preferably, as sample project demonstrating the problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/auth0-community/auth0-xamarin-oidc-samples/issues/6#issuecomment-398438600, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfEe1J-x9ncw2cPJY0qkmnEpan_0YThiks5t-Rb8gaJpZM4OewL4.

jerriep commented 6 years ago

@joshuatantonflynn I understand your difficulty. Though, please understand that it is also difficult for me to track the issue down without some reliable way to reproduce it.

  1. Can you please send me the section of code where you create the instance of Auth0Client ?

  2. When configuring the Auth0Client, I need to determine the package name of your Android package. This is what I used the Activity property for previously. In the new version I determine the package name using the following line of code:

string packageName = Android.App.Application.Context.PackageName;

It is possible that that is the offending line of code which results in the NullReferenceException. Can you please execute that line in your own code and let me know the result? Does it return a value? Or does it throw an exception?

joshuatantonflynn commented 6 years ago

Jerrie,

As far as I'm aware I follow the documentation here exactly: https://auth0.com/docs/quickstart/native/xamarin/01-login

I don't see any string packageName set in the docs. Where is that string used.

These are my following relevant code snippets:

Activity declaration:

[Activity(Label = "Flynn Coaching",
          Theme = "@style/Theme.DesignDemo",
          Icon = "@drawable/Icon",
          LaunchMode = LaunchMode.SingleTask)]

if DEBUG

[IntentFilter(
            new[] { Intent.ActionView },
            Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
            DataScheme = "com.flynncompanies.coachingandroid",
            DataHost = "flynn.auth0.com",
            DataPathPrefix = "/android/com.flynncompanies.coachingandroid/callback")]

else

[IntentFilter(
            new[] { Intent.ActionView },
            Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
            DataScheme = "com.flynncompanies.coachingandroid.prod",
            DataHost = "flynn.auth0.com",
            DataPathPrefix = "/android/com.flynncompanies.coachingandroid.prod/callback")]

endif

as you can see I have two sets depending on DEBUG or RELEASE. Both fail with 2.0.0

Auth0Client Declaration (inside onCreate method, global variable to the LaunchActivity):

client = new Auth0Client( new Auth0ClientOptions { Domain = ConstantsData.Auth0Domain, ClientId = ConstantsData.Auth0ClientId } );

You should note that I've kept my ClientId out of this email for security purposes. I assure you it is correct as the same id works with iOS and on droid with 1.2.0. I also have different ClientIds for PROD and DEV as they have different package names. Only difference from docs I've noticed is that in the docs client is declared as a var, while in my code it's declared as an Auth0Client, exact declaration is:

Auth0Cient client;

Finally, launching the login:

With 1.2.0 I use:

authorizeState = await client.PrepareLoginAsync();

var uri = Android.Net.Uri.Parse("googlechrome://navigate?url=" + authorizeState.StartUrl); var intent = new Intent(Intent.ActionView, uri); intent.AddFlags(ActivityFlags.NoHistory);

        StartActivity(intent);

I've tried this and

var loginResult = await client.LoginAsync();

with 2.0.0. However since the app crashed long before this code was excuted I don't think this is relevant.

Finally I just noticed in the docs after scrolling down a bit they tell you to do it slightly differently with android.

var loginResult = await client.ProcessResponseAsync(intent.DataString, authorizeState);

But as I said this code is never executed and clearly not the source of my problem.

Thanks,

[https://cdn2.auth0.com/docs/media/social-media/fb-card.png]https://auth0.com/docs/quickstart/native/xamarin/01-login

Auth0 Xamarin SDK Quickstarts: Loginhttps://auth0.com/docs/quickstart/native/xamarin/01-login auth0.com This tutorial will show you how to use the Auth0 Xamarin SDK to add authentication and authorization to your mobile app.


Joshua Tanton Mobile and Web Developer Flynn Group of Companies C:+1.416.994.3012 joshua.tanton@flynncompanies.com https://flynncompanies.com From: Jerrie Pelser notifications@github.com Sent: Tuesday, June 19, 2018 8:56:32 PM To: auth0-community/auth0-xamarin-oidc-samples Cc: Joshua Tanton; Mention Subject: Re: [auth0-community/auth0-xamarin-oidc-samples] Support for Xamarin.Forms on Android (#6)

@joshuatantonflynnhttps://github.com/joshuatantonflynn I understand your difficulty. Though, please understand that it is also difficult for me to track the issue down without some reliable way to reproduce it.

  1. Can you please send me the section of code where you create the instance of Auth0Client ?

  2. When configuring the Auth0Client, I need to determine the package name of your Android package. This is what I used the Activity property for previously. In the new version I determine the package name using the following line of code:

string packageName = Android.App.Application.Context.PackageName;

It is possible that that is the offending line of code which results in the NullReferenceException. Can you please execute that line in your own code and let me know the result? Does it return a value? Or does it throw an exception?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/auth0-community/auth0-xamarin-oidc-samples/issues/6#issuecomment-398590597, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfEe1G2C7mLqCRoTd20aS_1u60XtAFw4ks5t-Z3AgaJpZM4OewL4.

jerriep commented 6 years ago

The line

string packageName = Android.App.Application.Context.PackageName;

is not mentioned in the documentation, because it is not something you need to do. As I stated, it is executed in the constructor of the Auth0Client and as far as I can see, it can be the cause of the NullReferenceException.

But I need you to confirm that for me.

So can you please execute that line in your code and let me know what the result is?

joshuatantonflynn commented 6 years ago

Hi Jerrie,

I understand now what you mean. Sorry for my confusion. I executed that line prior to where I initiate the Auth0Client. It successfully returned my package name.

Thanks,


Joshua Tanton Mobile and Web Developer Flynn Group of Companies C:+1.416.994.3012 joshua.tanton@flynncompanies.com https://flynncompanies.com From: Jerrie Pelser notifications@github.com Sent: Wednesday, June 20, 2018 7:35:12 PM To: auth0-community/auth0-xamarin-oidc-samples Cc: Joshua Tanton; Mention Subject: Re: [auth0-community/auth0-xamarin-oidc-samples] Support for Xamarin.Forms on Android (#6)

The line

string packageName = Android.App.Application.Context.PackageName;

is not mentioned in the documentation, because it is not something you need to do. As I stated, it is executed in the constructor of the Auth0Client and as far as I can see, it can be the cause of the NullReferenceException.

But I need you to confirm that for me.

So can you please execute that line in your code and let me know what the result is?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/auth0-community/auth0-xamarin-oidc-samples/issues/6#issuecomment-398929974, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfEe1I0nC4oOSjeVlLCgLodmSplo0u7jks5t-twwgaJpZM4OewL4.

jerriep commented 6 years ago

Very interesting... and disappointing ;) I sorta hoped that was the issue.

I'll keep looking into it, but I also want to ask you if you can find time to try and create a sample for me which demonstrates this issue. Unless I have some reliable way to reproduce this, I am just making guesses about possible causes.

BTW, when you call

client = new Auth0Client( new Auth0ClientOptions { Domain = ConstantsData.Auth0Domain, ClientId = ConstantsData.Auth0ClientId } );

Does ConstantsData.Auth0Domain and ConstantsData.Auth0ClientId have values? Are one of them not perhaps null?

joshuatantonflynn commented 6 years ago

Hi Jerrie,

I thought you might ask that, that's why I mentioned in my previous emails that they do work for iOS and with 1.2.0 Nuget on droid. Two sets, one for prod, one for dev. But they are definitely set properly.

I have a deadline for this application so I'm focused on reaching that target and will look into 2.0.0 for the next one, since I have it stable with 1.2.0. At that point I can put together a sample project for, maybe some time next week.

Thanks,


Joshua Tanton Mobile and Web Developer Flynn Group of Companies C:+1.416.994.3012 joshua.tanton@flynncompanies.com https://flynncompanies.com From: Jerrie Pelser notifications@github.com Sent: Wednesday, June 20, 2018 8:39:55 PM To: auth0-community/auth0-xamarin-oidc-samples Cc: Joshua Tanton; Mention Subject: Re: [auth0-community/auth0-xamarin-oidc-samples] Support for Xamarin.Forms on Android (#6)

Very interesting... and disappointing ;) I sorta hoped that was the issue.

I'll keep looking into it, but I also want to ask you if you can find time to try and create a sample for me which demonstrates this issue. Unless I have some reliable way to reproduce this, I am just making guesses about possible causes.

BTW, when you call

client = new Auth0Client( new Auth0ClientOptions { Domain = ConstantsData.Auth0Domain, ClientId = ConstantsData.Auth0ClientId } );

Does ConstantsData.Auth0Domain and ConstantsData.Auth0ClientId have values? Are one of them not perhaps null?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/auth0-community/auth0-xamarin-oidc-samples/issues/6#issuecomment-398940469, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfEe1OsJ0LW8O3DVHd6BCmOkEdHcSlF-ks5t-utbgaJpZM4OewL4.

jerriep commented 6 years ago

That would be very much appreciated 😀

andrekiba commented 6 years ago

I'm sorry but I don't understand why the base classes Auth0Client and Auth0ClientOptions are no more inside the Core nuget package. Inside my login viewmodel in the Xamarin Forms .net standard pcl I have something like this:

var auth0Client = new Auth0Client(new Auth0ClientOptions
{
   Domain = Constants.Auth0Domain,
   ClientId = Constants.Auth0ClientId,
   Scope = "openid profile email"
});

but now it doesn't work anymore. I don't want to create my own implementation of the IAuth0Client. I don't understand.

jerriep commented 6 years ago

It has never been inside the Core package. Auth0Client and Auth0ClientOptions has always been in the platform-specific packages.

The new core package was introduced specifically to introduce an non-platform specific IAuth0Client interface which you could reference inside your Xamarin Forms project. You will need to inject the actual platform-specific Auth0Client implementation via something like dependency injection.

andrekiba commented 6 years ago

mmm...maybe when the package was "unofficial" ?? ...

jerriep commented 6 years ago

Hmm, I cannot remember those being in the Core package even while "unofficial". You say that you had it working in a PCL. Please tell me what version you were referencing in your PCL in which this worked.

As I stated, you will need to reference the Core package and use IAuth0Client in your PCL and then use dependency injection to inject the platform-specific Auth0Client implementation.

Unfortunately, however, I do not yet have a sample of how to do that for you.

andrekiba commented 6 years ago

do you mean something like this?

//PCL
public class LoginViewModel : BaseViewModel
{
    #region Fields

    private readonly IAuth0Client auth0Client;

    #endregion

    #region Lifecycle

    public LoginViewModel(IAuth0Client auth0Client)
    {
        this.auth0Client = auth0Client;
    }

    #endregion
}

//iOS
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();

    #region Auth0

    var auth0Client = new Auth0Client(new Auth0ClientOptions
    {
        Domain = Constants.Auth0Domain,
        ClientId = Constants.Auth0ClientId,
        Scope = "openid profile email"
    });

    FreshIOC.Container.Register<IAuth0Client>(auth0Client);

    #endregion

    LoadApplication(new App());

    return base.FinishedLaunching(app, options);
}

//Android
protected override void OnCreate(Bundle bundle)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);

    #region Auth0

    var auth0Client = new Auth0Client(new Auth0ClientOptions
    {
        Domain = Constants.Auth0Domain,
        ClientId = Constants.Auth0ClientId,
        Scope = "openid profile email"
    });

    FreshIOC.Container.Register<IAuth0Client>(auth0Client);

    #endregion

    LoadApplication(new App());
}

In my case the IOC container is FreshIOC, the one provided by FreshMVVM.

jerriep commented 6 years ago

Yes. I am not familiar with FreshIOC, but that seems to be what I have in mind.

Does that work for you?

andrekiba commented 6 years ago

sorry for the delay! yes it works. But...is there also another way to login with uath0 without leaving the app and open a browser?? Personally I think that the user experience is not so beautiful... 😅

jerriep commented 6 years ago

@andrekiba I am not sure. I will investigate.

jerriep commented 6 years ago

@luminousAvocado What do you mean by being unable to create an instance? Do you get errors? If so, what sort of errors? Compiler errors? Or errors at runtime?

Without a more detailed explanation, preferably with some screenshots, it is not possible for me to assist you.

jerriep commented 6 years ago

I am closing this issue are the original issue (adding support for Xamarin Forms) have been addressed. If any new issues come up, pleases open a separate issue on GH.

luminousAvocado commented 6 years ago

@sdkraemer , would it be possible for me to see your solution using dependency injection?

joshuatantonflynn commented 6 years ago

My iOS version (which was working with the 2.0 upgrade) has now started having this exact same problem with a null reference exception. Why was the Controller/Activity property removed from the Auth0ClientOptions!?! It is just causing problems. Now it'll be a mess to downgrade to 1.0 so my Auth0 will actually work.

jerriep commented 6 years ago

I was removed because that was the only way to get it working for Xamarin Forms. We cannot have platforms specific stuff in the Auth0ClientOptions otherwise it will not work on Xamarin Forms.

Please see if you can get some sort of stack trace or some way for me to reproduce it and then open an issue for that.

joshuatantonflynn commented 6 years ago

I just downgraded to 1.0 for iOS, took a while. But even with the Controller specified I'm getting the same NullReferenceException. How do I get you a stack trace? Is there a simple way to output this in VS without it being just a bunch of junk data? I'm going to go back to 2.1.0 where I'm having the same issue, there has got to be a way to prevent this NullReferenceException. In android you said it checked Android.App.Application.Context.PackageName; what does it check on iOS?

jerriep commented 6 years ago

@joshuatantonflynn Please, I am asking you nicely: Open a separate issue for this

This issue is closed and not related to your issue. We cannot track this properly if you do not open an issue for your problem.

As far as the stack trace is concerned, you will need to debug your application, and then when it break on the exception, you will need to look at the stack trace of the exception being thrown.