Error: The name AuthenticationState does not exist in the current context

828 Views Asked by At

I am doing google signin for my project . I am getting this error: 'The name AuthenticationState does not exist in the current context' in the MainActivity.cs page .Please see the attached screenshot. will it be removed by adding some nuget packages? i have added only xamarin.auth package. How to solve this error?

enter image description here

1

There are 1 best solutions below

0
On

I got the same error while following the steps at Authenticating Users with an Identity Provider. That page doesn't make it clear at all what you're supposed to do here.

The AuthenticationState class is a class in the sample project that has a reference to the authenticator. The authenticator is an instance of OAuth2Authenticator that you might have created as a local variable in the method where you are starting the login flow. Since that same authenticator is needed when your app is re-launched after the login flow has finished, it's better to add it as a static property to another class that can be used by both the login flow and when your app is re-launched.

For example, the AuthenticationState class could look something like this:

public class AuthenticationState
{
    public static OAuth2Authenticator Authenticator { get; } =
        new OAuth2Authenticator(clientId, clientSecret, scopes,
            new Uri(authorizeUrl), new Uri(redirectUrl),
            new Uri(tokenUrl), null, true);
}

Replace the parameters to the OAuth2Authenticator constructor based on the remote service you're connecting to.