I’m using Google’s APIs Client Library for PHP to enable a Sign In With Google Button and using Composer to install the dependencies.
The client library readme states:
There are over 200 Google API services. The chances are good that you will not want them all. In order to avoid shipping these dependencies with your code, you can run the GoogleTaskComposer::cleanup task and specify the services you want to keep in composer.json:
Which services do I need to keep to enable just the authentication functionality of the button?
Edit: To be clear, the button functionality works well, but I’m including 60MB of services like YouTube and Analytics that I don’t need, so I’m looking for what I need to add in my composer.json to exclude those services from the build.
2
Answers
After some tinkering, adding the below
scripts
andextra
key removes all other services leaving just 3 folders in the /vendor folder:apiclient
,apiclient-services
, andauth
. All others are removed on build.The Google API Client library doesn’t have anything specific for that – it’s a more general action. There are a few useful libraries to help you though – one of the most popular, and well used, is from "The League of Extraordinary Packages" – https://oauth2-client.thephpleague.com/usage/
To provide a ‘Sign in with Google’, and to collect some account information to use on your own site, there is the specific provider – https://github.com/thephpleague/oauth2-google that pulls in all the other packages that are required, from its own composer.json.
Both pages have examples on how to use the library, and the callback-URL of that page (be it simple .php URL, or when used as part of a framework), which is set as part of the configuration will receive the data –
'redirectUri'
, as well as the'clientId'
&'clientSecret'
.I would suggest including that code, with relevant information in the configuration, and doing some sample logins, and
var_dump
‘ing the returned information to see for yourself what is being returned, until you can receive the$ownerDetails
and other information about the $token, as demontrated in the sample code.