我正在使用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;
}
}
谢谢