Monthly Archives: December 2018

Goodbye, 2018

It’s has been a good year. There are some ups and downs, but I think it’s mostly up because I chose not to remember the downs.

This year, I exceeded my expectation on the number of books I read. I read a total of 25 books. It partially thanks to the (re-)discovery of public library. Not only I have access to many books, but I got more motivation to finish a book whenever I could because there was a due date return a book. I also got a new Kindle with backlight so I could read with the lights off when my children needed company in their room when they were going to sleep. (I actually didn’t know if it’s good for my eyes to read on a Kindle with backlight on.)

Each year, there were some books gave me new perspectives. Bored with Brilliant was one of them. It reminded me how screen time affected us and I was more aware of how I used my devices. The Pragmatic Programmer and Clean Coder were the books that every programmer should read once in their career. Start with Why and ReWork gave me inspiration and reflection on my working habit. Michael Lewis is still my favorite author.

Having two kids is not an easy task. They want your full attention all the time. I don’t think it’s wrong to have some “me-time” when you are a parent, but it just needs some work. In 2018, I started to wake up at 5am in the morning, even in the weekends, so I could have some “me-time” before the children woke up. To be honest, I didn’t do productive things all the time during “me-time”. When I was not reading, watching LaraCast and conference videos from YouTube, or doing my side project, I found myself watching Netflix. (No, I don’t feel guilty about it, but I think it’s something that I can improve in 2019.)

As of exercise, I picked up swimming in the summer. It’s basically because my son was learning to swim this year. I wanted to make sure I could swim so I could understand what he was going through. My swimming ability was at the “I can survive if I accidentally fell into the pool” level. I started off with holding a kicking board to today that I can swim in 3 different styles completely on my own. I did look funny at the beginning when swimming with a kicking board while the others were swimming with ease. However The experts in anything was once a beginner is the phase that I hold on to so I could go on without thinking about others. (It also helps to swim at 6AM when there were only few serious swimmers focusing on their own exercise.)

I went to two conferences this year, Laracon US and AWS reInvent. I learned a tons from these two conferences. I also got myself certified as a AWS DevOps Professional. It was a difficult exam, but the time I spent preparing for the exam helped me to understand more about DevOps and the tools to help delivering software more quickly and reliably. Having a certification is a bonus, but I value more about the process from learning the new things.

It’s a wrap of my 2018. I did well.

Thanks you, 2018. Goodbye.

Update Laravel Socialite from using Google+ API

68747470733a2f2f6c61726176656c2e636f6d2f6173736574732f696d672f636f6d706f6e656e74732f6c6f676f2d736f6369616c6974652e737667

The Laravel Socialite uses Google+ API to authenticate user, but since Google+ API is shutting down, the https://www.googleapis.com/plus/v1/people/me will no longer works.

If you are currently using Google+ API for Socialite Google OAuth2 authentication, you should upgrade Socialite version 4.

If are stuck with Socialite version 3.x because you need to run Laravel with lower or equal to version 5.5 (or because of PHP 7.0), change the composer package to 3.0.x-dev and run composer update as of this writing.

I am expecting Laravel Socialite 3.x Google OAuth API will be updated soon, but the package has not yet released.

Public reach

A tweet from @dhh

I think this can be done. (or should be done.) More than happy to join the team.

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