ADAL错误消息:MainActivity不包含实例的定义

时间:2018-08-03 12:59:43

标签: xamarin.forms azure-active-directory adal

我正在使用ADAL从AzureAD访问令牌。 Forms.Context已过时。因此,请尝试以下但有以下错误消息。如何解决?

更改此内容:

var platformParams = new PlatformParameters((Activity)Forms.Context);

对此:

var platformParams = new PlatformParameters(MainActivity.Instance,true,PromptBehavior.Always);

错误消息:

MainActivity不包含实例的定义

public class AuthenticationService:IAuthenticationService

{

public async Task<AuthenticationResult> Authenticate(string authority, string resource, string clientId, string returnUri)
        {

var authContext = new AuthenticationContext(authority);


if (authContext.TokenCache.ReadItems().Any())


authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().First().Authority);


var uri = new Uri(returnUri);


//var platformParams = new PlatformParameters((Activity)Forms.Context);


var platformParams = new PlatformParameters(MainActivity.Instance, true, PromptBehavior.Always);


var authResult = await authContext.AcquireTokenAsync(resource, clientId, uri, platformParams);


return authResult;

}

}

谢谢

0 个答案:

没有答案