当前位置: 首页 > 知识库问答 >
问题:

请求的身份验证范围不足

翟功
2023-03-14

我第一次尝试使用Google Firestore,通过Google api身份验证进行身份验证。我要做的第一件事是用几个方法来填充数据库,当我等待批处理任务时,会出现以下错误:

Error: Status(StatusCode=PermissionDenied, Detail="Request had insufficient authentication scopes.") ;

我几乎找不到谷歌认证连接firestore的方法。首先,我使用google console为我的应用程序提供的密码使用此方法进行身份验证:

    public async Task<GoogleOAuthState> GetUserCredentialAsync(string user = null, GoogleOAuthState oAuthState = null)
    {
        using (ClientSecretStream)
        {
            string credPath = System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.Personal);

            if (oAuthState == null)
            {
                try
                {
                    var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(ClientSecretStream).Secrets,
                        _Scopes,
                        string.IsNullOrEmpty(user) ? "user" : user,
                        CTS.Token,
                        new FileDataStore(credPath, true));

                    return new GoogleOAuthState(credential, _AppName);
                }
                catch (Exception e)
                {
                    SetErrorMessage(e, "Error al intentar identificarse en google");
                    return null;
                }
            }
            else
            {
                try
                {
                    await GoogleWebAuthorizationBroker.ReauthorizeAsync(
                        oAuthState.Credential,
                        CTS.Token);
                    return oAuthState;
                }
                catch (Exception e)
                {
                    SetErrorMessage(e, "Error al intentar volver a identificarse en google");
                    return null;
                }
            }
        }
    }

使用在我的google控制台中为应用程序html" target="_blank">配置的相同作用域(我在同一应用程序中使用google drive):

            SheetsService.Scope.Spreadsheets
            DriveService.Scope.DriveFile
            DriveService.Scope.Drive
            DriveService.Scope.DriveAppdata
            DriveService.Scope.DriveMetadata
            "https://www.googleapis.com/auth/datastore"
            "https://www.googleapis.com/auth/cloud-platform"

GoogleOAuthState只是一个用来保存和传递凭证的对象,而不是什么。之后,我通过以下连接到firestore:

    public async Task ConnectDB(GoogleLogin.GoogleOAuthState oAuthState)
    {
        var channelCredentials = oAuthState.Credential.ToChannelCredentials();
        var channel = new Channel(FirestoreClient.DefaultEndpoint.ToString(), channelCredentials);
        var client = FirestoreClient.Create(channel);
        _DB = FirestoreDb.Create(Properties.Settings.Default.FirebaseProjectName, client);
    }

我在这个问题上看到了这种方法,认为它是最可靠的。

与此同时,我已经设置了这样的火力恢复规则:

service cloud.firestore {
match /databases/{database}/documents {
  match /{document=**} {
    allow read, write: if true;
    }
  }
}

谷歌认证工作正常,我可以毫无问题地使用谷歌硬盘。我还在firestore控制台中添加了google作为身份验证方法,并添加了应用程序id(我不确定这是否真的有必要)。

我想我误会了什么...有可能做到这一点吗?还是我必须使用服务号?

共有1个答案

冀弘厚
2023-03-14

嗯,根据我的测试和阅读,似乎不可能通过oAuth从桌面应用程序登录Firestore:您使用服务帐户或什么都不用。我甚至不确定是否可以从桌面应用程序进行登录,它完全是移动或web,仅此而已。

不管怎样,即使使用服务帐户,现在我也有另一个问题,所以我要提出另一个问题。

 类似资料:
  • null 所用程序: 获取身份验证响应后创建Google analytics service对象。/li> 脚本: null

  • 这是我为Google Sheets API编写的代码。我有这是我找到的解决此问题的方法,但这并不能解决我的问题。我已经删除了我的.Credentials文件夹,它不提示我登录。

  • 我是新来的,我不是程序员,那我需要你的帮助。 我正在测试说明管理老师和学生在这里找到:https://developers.google.com/classroom/guides/manage-users 我尝试使用身份验证和作用域,就像在PHP QuickStart中一样:https://developers.google.com/classroom/quickstart/php 我成功运行了q

  • 我正试着从我的swift项目中写到谷歌表单。 现在,我遇到的问题是,当我运行该代码试图写入工作表时,我得到的响应是这样的(工作表ID被我故意删除了): 在进一步研究中,我还发现了这一点,我认为这将解决我的问题,但当我尝试添加时,它告诉我中找不到'kGTLRAuthScopeSheetsSpreadsheets'。 我觉得在这一点上,我被困在我下一步可以尝试的东西上了。如有任何建议,不胜感激!

  • 问题内容: 我正在使用nodejs上的以下脚本编写脚本以从Google电子表格读取数据: 但是在每个获取请求时,我都会收到此错误: 我检查了Google开发人员控制台以启用Google Drive API并启用了它,所以我真的不知道这可能是什么。 问题答案: 首先删除凭据文件(取决于您的设置) 从更改用于从Google Spreadsheets读取单元格的作用域变量 var SCOPES = [‘