【问题标题】:Error: The name AuthenticationState does not exist in the current context错误:当前上下文中不存在名称 AuthenticationState
【发布时间】:2019-01-16 12:42:20
【问题描述】:

我正在为我的项目做谷歌登录。我收到此错误:MainActivity.cs 页面中的“当前上下文中不存在名称 AuthenticationState”。请参阅随附的屏幕截图。它会通过添加一些nuget包来删除吗?我只添加了 xamarin.auth 包。如何解决这个错误?

【问题讨论】:

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


    【解决方案1】:

    我在执行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 构造函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-01
      • 2010-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多