akoshodi/laravel-gsuite

帮助您从Laravel应用程序中管理您的GSuite账户

dev-main 2021-01-30 00:23 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:32 UTC


README

这是一个Google Admin SDK的包装器。它允许您在Laravel应用程序中管理您的G-Suite账户。

警告:处于积极开发中,请自行承担风险。当准备测试时,将标记版本。

安装

您可以通过composer安装此包

composer require akoshodi/laravel-gsuite

安装完成后,发布配置文件

php artisan vendor:publish

配置

  1. 设置您的账户为伪装
// .env
GOOGLE_SERVICE_ACCOUNT=email@domain.com
  1. 更新 credentials_path,确保您已将凭证文件添加到 .gitignore。您可以从Google管理控制台下载此文件。
'credentials_path' => storage_path('credentials.json'),
  1. 设置您的域
// .env
GSUITE_DOMAIN=example.com
  1. 根据需要更改配置文件中的缓存设置

  2. 添加任何账户、别名或组,您希望禁用删除功能。用于确保没有人可以删除您的服务账户。您仍然可以通过G-Suite管理员界面手动删除它们。

用法

GSuite账户管理

// Create a new G-Suite account
GSuite::accounts()->create([
    [
        'first_name' => 'John',
        'last_name' => 'Doe',
    ],
    'email' => 'john.doe@email.com',
    'default_password' => 'password'
]);

// Get a G-Suite account
GSuite::accounts()->get('john.doe@example.com');

// Get a collection of all G-Suite accounts in your domain
GSuite::accounts()->all();

// Delete a G-Suite account
GSuite::accounts()->delete('john.doe@example.com');

// Suspend a G-Suite account
GSuite::accounts()->suspend('john.doe@example.com');

// Add an alias to a G-Suite account
GSuite::accounts()->alias('john.doe@example.com', 'support@example.com');

GSuite组管理

// Create a new G-Suite group
GSuite::groups()->create('group.email@example.com', 'Group Name', 'Group description');

// Get a G-Suite group
GSuite::groups()->get('group.email@example.com');

// Get a collection of all G-Suite groups in your domain
GSuite::groups()->all();

// Delete a G-Suite group
GSuite::groups()->delete('group.example@example.com');

// Add a member to a G-Suite group
GSuite::groups()->addMember('group.email@example.com', 'john.doe@example.com');

缓存

默认情况下,accountsgroups 都被缓存。如果您选择不缓存结果,请求时间将会很长。当您删除、插入或更新资源时,缓存将自动刷新。您可以在任何时候刷新缓存,以下是一些示例。

// Flush accounts and groups cache
GSuite::flushCache();

// Flush only accounts cache
GSuite::accounts()->flushCache();

// Flush only groups cache
GSuite::groups()->flushCache();

// Via the CLI
php artisan gsuite:flush-cache

其他资源

您可以使用 GoogleServicesClient 类获取其他Google服务的API客户端,例如,如果您想管理您的域的组织单元

您可以这样获取组织单元的API客户端

$client = GSuiteServicesClient::getService('orgunit');

测试

composer test

变更日志

请参阅CHANGELOG以获取更多有关最近更改的信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全性

如果您发现任何安全相关的问题,请通过akoshodi@protonmail.com发送电子邮件,而不是使用问题跟踪器。

鸣谢

许可

MIT许可(MIT)。请参阅许可文件以获取更多信息。

Laravel包模板

此包是使用Laravel包模板生成的。