I am trying to create a login page for iOS in Xamarin.Forms with the Auth0 API but every time I call my login method, it freezes at “client.LoginAsync()”. had this working at first but suddenly I was unable to retrieve a login page and the iPhone screen froze. The only output I receive is: Thread started. I thought it might be due to incorrect callback URL configurations or mixed client IDs but I don’t think this is the case. Here is my iOS code:
using Auth0.OidcClient;
using System.Diagnostics;
using IdentityModel.OidcClient;
using System.Threading.Tasks;
using IdentityModel.OidcClient.Browser;
using App3.Data;
using App3.Models;
[assembly: Xamarin.Forms.Dependency(typeof(App3.iOS.Auth))]
namespace App3.iOS
{
public class Auth : IAuthentication
{
async public Task<User> Login()
{
Auth0Client client = new Auth0Client(new Auth0ClientOptions
{
Domain = "{domain name}",
ClientId = "{client id}",
});
Debug.WriteLine("This prints");
var loginResult = await client.LoginAsync(new LoginRequest());
Debug.WriteLine("This never prints");
if (loginResult.IsError)
{
Debug.WriteLine($"An error occurred during login: {loginResult.Error}");
return null;
}
Debug.WriteLine($"id_token: {loginResult.IdentityToken}");
Debug.WriteLine($"access_token: {loginResult.AccessToken}");
Debug.WriteLine($"name: {loginResult.User.FindFirst(c => c.Type == "name")?.Value}");
Debug.WriteLine($"email: {loginResult.User.FindFirst(c => c.Type == "email")?.Value}");
User user = new User();
user.id = 0;
user.name = loginResult.User.FindFirst(c => c.Type == "name")?.Value;
user.email = loginResult.User.FindFirst(c => c.Type == "email")?.Value;
//user.token = new Token(loginResult.IdentityToken, loginResult.AccessToken);
return user;
}
}
}
}
This is what my Info.plist looks like:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleURLName</key>
<string>Auth0</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.companyname.App3</string>
</array>
</dict>
</array>
Any help or ideas as to what may be causing this problem would be greatly appreciated. I have been stuck on this problem for a while now.