Category Archives: Web Development

Develop with TailwindCSS

TLDR; I just did a project using Tailwind CSS. It’s as good as it advertised.

I came from working with Bootstrap for a long time. It has been my go to HTML/CSS framework. I can quickly build a good business looking website quickly with Bootstrap.

I just had a small project that I needed to work on. It’s not difficult so I got to spend sometimes on it using Tailwind.

At first, since coming from Bootstrap, there’s some initial learning curve needed to overcome with. Once I got it setup and running, I see the benefit of using a Utility First Framework approach to develop the front-end. It’s quick, easy to customize, and importantly, easy to read. (We spend 10 times more to read code than writing code, maybe 20 times more to read HTML/CSS more than writing HTML/CSS code ).

It’s good to have more tools to tackle problems and I think both Bootstrap and Tailwind are good tools to have in the toolbox.

Advertisements

Working with G Suite Admin SDK

On occasion, you want to build an application to interact with G Suite without logging to the console. The G Suite Admin SDK is a tool for the purpose. 

In authentication, there are two ways to do it. 

  1. Using service account and impersonate an account with administrative access. 
  2. Use OAuth to authenticate access through SDK. (Recommended)

The first option is great for automate tasks, such as generating reports, but not recommended for web app with access from anyone.

Let’s look at how to implement option #2 with Laravel

  1. Use composer to download and include the Admin SDK. composer require google/apiclient:2.0
  2. Create a OAuth 2.0 client ID in https://console.developers.google.com/apis
  3. Place the client_id and client_secret the same way you when setting up Socialite using Google OAuth. 
  4. In the Socialite login code, set scopes that you want the account with administrative access. The Admin SDK scopes are listed in here. For example to retrieve group, group alias, and member information, uses: j
return Socialite::driver(‘google’)
->scopes([ 'https://www.googleapis.com/auth/admin.directory.group.readonly',
])
->redirect();
  • When retrieving user detail after login, store the $user->token somewhere. 

6. Back to using Google client, create a $client as below 

$client = new Google_Client();
$client->setApplicationName('G Suite Directory Demo');
$client->setAccessToken([User Token here]);
$service = new Google_Service_Group($client);
$optParams = array(
'userKey' => 'administrative-account@example.com',
'maxResult' => 10
);
$results = $service->groups->listGroups($optParams);

7. Done