1

I am using ADAL to access token from AzureAD. The Forms.Context is obsolete. So try the below But Have the below error message. How to fix it?

change this:

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

To this:

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

Error Message:

MainActivity does not contain a definition for Instance

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;

}

}

Thanks

MilkBottle
  • 4,242
  • 13
  • 64
  • 146
  • did you solve this? – lvin Sep 05 '18 at 22:19
  • Have you tried using passing "Android.App.Application.Context" instead. Please refer to this StackOverflow issue - https://stackoverflow.com/questions/47353986/xamarin-forms-forms-context-is-obsolete – SaurabhSharma Sep 07 '18 at 16:38

0 Answers0