Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Latest commit

 

History

History
180 lines (123 loc) · 4.95 KB

README.md

File metadata and controls

180 lines (123 loc) · 4.95 KB

G-Suite Admin SDK Wrapper

This is a wrapper around the Google Admin SDK. It allows you to manage your G-Suite account in your Laravel application. There is an example application if you'd like to check that out.

Warning: under active development, use at your own risk. A version will be tagged when ready for testing.

UPDATE: This package development has been paused, I would love to continue to build this package, but no longer have a GSuite account and using a personal account was to pricey. I may pick this back up if I can get either a work sponsored GSuite account, or some form of GSuite Dev credits.

Installation

You can install the package via composer:

composer require wyattcast44/gsuite

Once the install has finished, publish the configuration file

php artisan vendor:publish

Configuration

  1. Set your account to impersonate
// .env
GOOGLE_SERVICE_ACCOUNT=email@domain.com
  1. Update the credentials_path, ensure you add your credentials file to your .gitignore. You can download this file from the Google admin console
'credentials_path' => storage_path('credentials.json'),
  1. Set your domain
// .env
GSUITE_DOMAIN=example.com
  1. Change cache settings as desired in config file

  2. Add any accounts, alias, or groups that you want to disable the ability to delete. Used to ensure no one can delete your service account. You can still delete them manually via the G-Suite Administrator interface.

Usage

G-Suite Account Management

// 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');

G-Suite Group Management

// 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');

Caching

By default accounts and groups are cached. If you choose not to cache results, request times will be lengthy. The cache will automatically flush when you delete, insert, or update resources. You can flush the cache at any time, see examples below.

// 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

Other Resources

You can use the GoogleServicesClient class to get api clients for other google services, for example let's say you wanted to manage your domain's organizational units.

You can get a api client for the org units like so:

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

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email wyatt.castaneda@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.