All Projects → ColoredCow → laravel-gsuite

ColoredCow / laravel-gsuite

Licence: MIT license
A Laravel package to setup Google OAuth and GSuite Admin SDK.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-gsuite

Gam
command line management for Google Workspace
Stars: ✭ 2,558 (+14947.06%)
Mutual labels:  gsuite, google-api
node-social-feed-api
Aggregates social media feeds and outputs them to use in an API
Stars: ✭ 20 (+17.65%)
Mutual labels:  google-api
google-oauth2-web-client
Login with Google using OAuth2 for client-side web app
Stars: ✭ 32 (+88.24%)
Mutual labels:  google-api
JFXGoogleDrive
A JavaFX Google Drive Client (For Demonstration Purposes Only).
Stars: ✭ 29 (+70.59%)
Mutual labels:  google-api
grasp
Essential NLP & ML, short & fast pure Python code
Stars: ✭ 58 (+241.18%)
Mutual labels:  google-api
gapi-to-graphql
Converts any Google Data Api to GraphQL
Stars: ✭ 82 (+382.35%)
Mutual labels:  google-api
Google-Docs-for-Mac
Native Google Docs app for Mac
Stars: ✭ 33 (+94.12%)
Mutual labels:  gsuite
goco
Connecting to Google API has never been easier!
Stars: ✭ 14 (-17.65%)
Mutual labels:  google-api
py translator
The end goal is a simple application for translating text in the terminal. Text can be generated interactively or programmatically in the shell environment.
Stars: ✭ 45 (+164.71%)
Mutual labels:  google-api
google-api-typings-generator
Updated and fixed version of TypeScript typings for Google APIs generator
Stars: ✭ 42 (+147.06%)
Mutual labels:  google-api
drive-zipextractor
Extract (decompress) ZIP files into Google Drive using the Google Drive API
Stars: ✭ 432 (+2441.18%)
Mutual labels:  gsuite
gsuite-signature-manager
Organization wide G Suite email signatures using Mustache templates
Stars: ✭ 27 (+58.82%)
Mutual labels:  gsuite
cMaps
🎨 Control options and customization of the Google Maps colors, just 1,7 KB.
Stars: ✭ 14 (-17.65%)
Mutual labels:  google-api
drive-music-player
Fully client side Music Player for Google Drive
Stars: ✭ 567 (+3235.29%)
Mutual labels:  gsuite
google-backup
Drive/Gmail/Calendar backups
Stars: ✭ 31 (+82.35%)
Mutual labels:  gsuite
google-it-telegram-bot
🤖 @Google_itBot 🔎 Search and share LINKS/IMAGES/VIDEOS in inline mode
Stars: ✭ 40 (+135.29%)
Mutual labels:  google-api
google maps
🗺 An unofficial Google Maps Platform client library for the Rust programming language.
Stars: ✭ 40 (+135.29%)
Mutual labels:  google-api
TSWorkflow
G Suite workflow automation highlighted in my presentation given at SheetsCon-2020 - "Automation with Apps Script"
Stars: ✭ 28 (+64.71%)
Mutual labels:  gsuite
Unity live caption
Use Google Speech-to-Text API to do real-time live stream caption on Unity! Best when combined with your virtual character!
Stars: ✭ 26 (+52.94%)
Mutual labels:  google-api
youtube-video-maker
📹 A tool for automatic video creation and uploading on YouTube
Stars: ✭ 134 (+688.24%)
Mutual labels:  google-api

Laravel GSuite

A Laravel package to setup Google OAuth and GSuite Admin SDK.

Installation

You can install the package using composer

composer require coloredcow/laravel-gsuite

Publish the configurations

php artisan vendor:publish --provider="ColoredCow\LaravelGSuite\Providers\GSuiteServiceProvider" --tag="config"

Setting up Google Oauth

Update your .env file with the Google OAuth 2.0 credentials

GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CLIENT_CALLBACK=your_google_callback_url

NOTE: If you wish to restrict users to your organization's domain, add to your .env

GOOGLE_CLIENT_HD=your_domain

Inside your app/Http/Controllers/Auth/LoginController.php, use the package trait GSuiteLogin

<?php

use ColoredCow\LaravelGSuite\Traits\GSuiteLogin;

class LoginController extends Controller
{

    use AuthenticatesUsers, GSuiteLogin;

    // ...

That's it! Go to your_app_url/auth/google and use your Google email to login.

Setting up GSuite Admin Service

In your .env file, add the following credentials:

GOOGLE_APPLICATION_CREDENTIALS=your_gsuite_service_account_crendentials
GOOGLE_SERVICE_ACCOUNT_IMPERSONATE=your_gsuite_admin_email

To know more about service account and steps to get one, visit the official Google Documentation.

NOTE: Make sure you enable Domain-wide Delegation when creating the service account for your project.

You can now use various services provided by the package. For example, if you want to fetch a user details, you can use the GSuiteUserService facade.

use ColoredCow\LaravelGSuite\Facades\GSuiteUserService;

// ...

$user = GSuiteUserService::fetch('[email protected]');

echo $user->getName(); // Jon Snow
echo $user->getJoinedOn(); // 2016-12-26 12:15:00
echo $user->getDesignation(); // Lord Commander

Enabling multitenancy

There are some additional steps required in case your application supports multitenancy.

Set multitenancy to true in your config/gsuite.php

'multitenancy' => true,

The default value for tenant connection is tenant. If you're using a different name for tenant connection, update config/gsuite.php

'connections' => [
    'tenant' => 'tenant_connection',
]

Since you'll have multiple tenants, and you may need different GSuite API credentials for each of them, the package will create a table in each tenant database. This table will store the required gsuite credentials.

Publish the tenant specific migrations using the following command. This will publish the migrations into database/migrations/tenant directory.

php artisan vendor:publish --provider="ColoredCow\LaravelGSuite\Providers\GSuiteServiceProvider" --tag="multitenancy"

Now, create your tenant databases.

NOTE: If you already have existing tenants, you may need to recreate those tenant databases. You may lose some data if not done carefully.

In every tenant database, you need to define the application credentials and service account impersonate user. You can add a seeder to your multitenancy implementation so that it runs everytime a new tenant database is created.

Your gsuite_configurations table should look this

id key value created_at updated_at
1 application_credentials full_path_to_credentials.json 2018-06-06 16:00:00 2018-06-06 16:00:00
2 service_account_impersonate [email protected] 2018-06-06 16:00:00 2018-06-06 16:00:00

More multitenancy configurations

If you prefer to have a different name for the gsuite_configurations table, update config/gsuite.php

'tables' => [
    'tenant' => [
        'gsuite-configurations' => 'your_gsuite_table_name',
    ]
]

If you prefer to override the package's GSuiteConfiguration model, create a custom model that must implement the ColoredCow\LaravelGSuite\Contracts\Tenant\GSuiteConfiguration contract. Then, update your config/gsuite.php and replace the default model with the new model.

'models' => [
    'tenant' => [
        'gsuite-configuration' => App\YourModelName::class
    ]
]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].