将应用程序发布到 Google Workspace Marketplace 以查询其他组织的目录

Publishing an app to Google Workspace Marketplace to query other organisation's directories

Google 的文档并不清楚这是否可行。

我在组织的应用程序中为 SSO 配置了 OAuth,该应用程序运行正常。

我还希望创建一个 Google Workspace Marketplace 应用程序 (https://workspace.google.com/marketplace),它可以由其他组织安装,这将允许我查询(或可能接收更改通知)他们的用户目录,最终的最终目标是在我的应用程序中自动配置他们的用户(此应用程序将是一个后端应用程序,将 运行 定期)。

这可能吗?

所以这是可能的。您必须按照此处所述创建一个 Marketplace 应用程序:

https://developers.google.com/workspace/marketplace/how-to-publish

同时启用全域委派:

https://developers.google.com/admin-sdk/directory/v1/guides/delegation

然后您将能够模拟特定的管理员用户(我想不出不执行模拟的身份验证方法)

C# 代码片段 - 非生产级代码

using Google.Apis.Auth.OAuth2;
using Google.Apis.Admin.Directory.directory_v1;
using Google.Apis.Admin.Directory.directory_v1.Data;
using Google.Apis.Services;
using System.Linq;

namespace AdminSDKDirectoryQuickstart
{
    class Program
    {
        static string[] Scopes = { DirectoryService.Scope.AdminDirectoryUserReadonly };
        static void Main(string[] args)
        {
            var credential = GoogleCredential.FromFile("credentials.json")
                .CreateWithUser("YOUR_ADMIN_USER@ORGANIZATION.COM")
                .CreateScoped(Scopes);

            var service = new DirectoryService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential
            });

            var request = service.Users.List();
            request.Customer = "my_customer"; // Alias for the customer of the admin user specified in the credential
            request.MaxResults = 500;
            var result = request.Execute();

            foreach (var user in result.UsersValue)
            {
                // Do something with the user
            }
        }
    }
}