System.TypeInitializationException в Xamarin.Forms с ADAL - PullRequest
0 голосов
/ 17 мая 2019

Я пытаюсь реализовать ADAL в моем приложении. Я получаю следующую ошибку:

System.TypeInitializationException: инициализатор типа для Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache исключение.

Это мой код:

Authenticator

public interface IAuthenticator
{
    Task<AuthenticationResult> Authenticate(string authority, string resource, string clientId, string returnUri);
}

Код модели представления

public static string clientId = "client id";
public static string tenant = "tenant";
public static string authority = String.Format("https://login.microsoftonline.com/{0}", tenant);
public static string returnUri = "returnUri";
private const string graphResourceUri = "https://graph.windows.net";
private AuthenticationResult authResult = null;

async Task Authenticate()
{
    var auth = DependencyService.Get<IAuthenticator>();
    var data = await auth.Authenticate(authority, graphResourceUri, clientId, returnUri);
    GivenName = data.UserInfo.GivenName;
    FamilyName = data.UserInfo.FamilyName;
    return;
}

Код iOS

[assembly: Dependency(typeof(Authenticator))]
namespace AzureAD_1.iOS
{
    class Authenticator : IAuthenticator
    {
        public async Task<AuthenticationResult> Authenticate(string authority, string resource, string clientId, string returnUri)
        {
            AuthenticationContext authContext = new AuthenticationContext(authority);
            var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;
            var uri = new Uri(returnUri);
            var platformParams = new PlatformParameters(controller);
            var authResult = await authContext.AcquireTokenAsync(resource, clientId, uri, platformParams);
            return authResult;
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...