Download the PHP package nickbeen/socialiteproviders-google-one-tap without Composer

On this page you can find all versions of the php package nickbeen/socialiteproviders-google-one-tap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package socialiteproviders-google-one-tap

Google One Tap provider for Laravel Socialite

Latest version Total downloads PHP Version License

A provider for Laravel Socialite that allows authentication for Google through Google One Tap. The Google One Tap framework is build on top of OAuth2, but does not use the traditional OAuth authorize user flow. Instead of returning an access token, it returns an authenticating JWT token that expires after an hour.

Google One Tap does not sync with the session of your application, so you should solve this within your application. As long as the credentials of the user aren't revoked and the user is logged in with their Google account or Google Chrome browser, the application will be able to grab a new JWT token with minimal user interaction when necessary.

Installation

This package depends on google/apiclient (including 200+ google\api-clients-services packages) and will be also be included when installing this package.

You can run the google-task-composer-cleanup script in composer.json to only keep the Google API client packages needed for running this Socialite provider. DO NOT run this script if your application depends on google/apiclient.

Usage

Please see the Base Installation Guide if Laravel Socialite isn't installed yet into your application.

Setup Google project

First you might need to create a new project at Google Cloud console, set up the OAuth consent screen and create a new OAuth Client ID. Within the Credentials menu you will find the client ID and client secret which you will need for authenticating.

Add configuration

You will need to store the client ID and client secret in your .env file and add the configuration to config/services.php. You will also need to add a redirection url which will be used for logging in and registering with Google One Tap. This package refers to a specific .env value for Google One Tap to avoid any clashes with the standard Google Socialite provider.

Add provider event listener

Configure the package's listener to listen for SocialiteWasCalled events. Add the event to your boot() method in app/Providers/AppServiceProvider in Laravel 11 or add the event to your listen[] array in app/Providers/EventServiceProvider in Laravel 10. See the Base Installation Guide for detailed instructions.

With Laravel 11:

With Laravel 10:

Usage

Google One Tap requires a specific implementation both in the front-end as the back-end.

Front-end

On every page where you want to use Google One Tap, you will need to include the following script in the header of your html templates.

The actual Google One Tap prompt can be initiated with either javascript or html. The following code handles the response server side in html. It does not matter where you place this code. You can also append data-client_id and data-login_uri to any existing html element. Check references for more settings and variations such as a full javascript implementation.

Styling this element won't have any effect since Google One tap is migrating to FedCM which means the prompt will be handled by the browser itself if the browser supports it.

For signing out you should add a g_id_signout class to your sign-out button to avoid a redirection loop because of data-auto_select in the previous snippet.

Google One Tap has a cooldown period when a user closes the Google One Tap prompt. The more often a user closes the prompt, the longer it will take for the prompt to be able to reappear to the user. Therefore, you need to include a sign-in button for a fallback to a Google Sign-In prompt. You will likely only want to include this button on login and register pages. Only the data-type field is required.

Back-end

Google One Tap is build on top of OAuth, but works different with an authenticating JTW token instead of with access tokens and refresh tokens. The redirect() and refreshToken() method won't be used in this context and will throw a DisallowedMethodException as a reminder.

Your controller won't need to redirect the user and instead of resolving the user, you can immediately resolve the token.

This method will return the payload of the JWT token or throw an InvalidIdTokenException if the provided token was invalid.

Payload array

Field Type Description
avatar ?string The user's profile picture if present
email string The user's email address
email_verified boolean True, if Google has verified the email address
host_domain ?string The host domain of the user's GSuite email address if present
id string The user's unique Google ID
name string The user's name

Only use id field as identifier for the user as it is unique among all Google Accounts and never reused. Don't use email as an identifier because a Google Account can have multiple email addresses at different points in time.

Using the email, email_verified and host_domain fields you can determine if Google hosts and is authoritative for an email address. In cases where Google is authoritative the user is confirmed to be the legitimate account owner.

Handling the payload

With the payload containing the id you can now handle the user flow after the user finished interacting with the Google One Tap prompt. This usually involves either registering the user if the Google ID isn't present in your database or logging in the user if you have a user registered with this Google ID.

Optionally you can use email to check if the user already has a user account or Socialite credentials from another provider, and possibly connect the accounts or notify the user account. In basic Laravel code it would look something like this:

FAQ

How can I use authoritative scopes with Google One Tap to e.g. upload to Google Drive?

Google One Tap can only be used for authentication (who you are). For authorization, you need to use the built-in Google provider of Laravel Socialite. Both providers can be used simultaneously to give you the best of both worlds.

Can I check if a user logged in with One Tap, used an existing session, etc.?

The select_by field in the response from Google contains several possible values like auto, user and user_1tap that indicate how the user interacted with your application when signing up or signing in. In Laravel the value can be easily accessed in your controller.

References

License

This package is licensed under the MIT License (MIT). See the LICENSE for more details.


All versions of socialiteproviders-google-one-tap with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-json Version *
google/apiclient Version ^2.15
socialiteproviders/manager Version ^4.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nickbeen/socialiteproviders-google-one-tap contains the following files

Loading the files please wait ....