错误:名称AuthenticationState在当前上下文中不存在

时间:2018-08-09 06:43:59

标签: xamarin xamarin.forms google-authentication xamarin.auth

我正在为我的项目使用google登录。我收到此错误:MainActivity.cs页面中的“名称AuthenticationState在当前上下文中不存在”。请参阅所附的屏幕截图。通过添加一些nuget软件包将其删除?我只添加了xamarin.auth软件包。如何解决此错误?

enter image description here

1 个答案:

答案 0 :(得分:0)

按照Authenticating Users with an Identity Provider中的步骤操作时,我遇到了相同的错误。该页面并没有明确说明您应该在这里做什么。

AuthenticationState类是sample project中具有对身份验证器的引用的类。身份验证器是OAuth2Authenticator的一个实例,您可能已在启动登录流程的方法中将其创建为局部变量。由于在登录流程完成后重新启动您的应用程序时需要使用相同的身份验证器,因此最好将它作为静态属性添加到可以由登录流程使用和重新启动您的应用程序的另一个类中。

例如,AuthenticationState类可能看起来像这样:

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

根据您要连接的远程服务,将参数替换为OAuth2Authenticator构造函数。