Google auth with token helps you to easily create google authentication available for your users with idToken. It uses the official google-auth-library library to execute the actions. You can get it working in seconds in your application. EASY!
npm install strapi-google-auth-with-token
Google auth with token helps you to easily create Google authentication for your users using the Sign In With Google button.
It uses the official google-auth-library to execute the actions and verify the token. You can get it working in seconds 🫰.
> Google makes One Tap authentication for smooth authentication with just one click, no need for redirection URL
1. Install the plugin using npm or yarn
``bash`
npm install strapi-google-auth-with-tokenor
yarn add strapi-google-auth-with-token
2. Add the following lines of code in the file: config/plugins.js or config/plugins.ts
`js
module.exports = {
'strapi-google-auth-with-token': {
enabled: true,
fullNameField: 'fullName', // (Optional) This is the attribute name in Strapi user entity where you will save the user full name
firstNameField: 'firstName', // (Optional) This is the attribute name in Strapi user entity where you will save the user first name
lastNameField: 'lastName', // (Optional) This is the attribute name in Strapi user entity where you will save the user last name
pictureField: 'profileImage', // (Optional) This is the attribute name in Strapi user entity where you will save the user Gmail picture
pictureFolderName: 'profiles', // (Optional) The name of the folder where user Gmail picture will be stored
// PS: You can use only some of them or none of them
// BTW: You need to create these attributes in the Strapi user entity if you provide them in this config
},
};
// or in typescript for config/plugins.ts
export default () => ({
"strapi-google-auth-with-token": {
enabled: true,
fullNameField: 'fullName', // (Optional) This is the attribute name in Strapi user entity where you will save the user full name
firstNameField: 'firstName', // (Optional) This is the attribute name in Strapi user entity where you will save the user first name
lastNameField: 'lastName', // (Optional) This is the attribute name in Strapi user entity where you will save the user last name
pictureField: 'profileImage', // (Optional) This is the attribute name in Strapi user entity where you will save the user Gmail picture
pictureFolderName: 'profiles', // (Optional) The name of the folder where user Gmail picture will be stored
// PS: You can use only some of them or none of them
// BTW: You need to create these attributes in the Strapi user entity if you provide them in this config
},
});
`
1. Create a Google project from the Google Cloud Console.
2. Create OAuth Consent Screen (Nav Menu -> APIs & Services -> OAuth consent screen).
3. Go to Credentials, click create credentials -> OAuth Client ID
4. Put the CLIENT_ID in the Strapi Content Management page > Google Credential, and save it.
`js``
{
method: 'POST',
path: 'STRAPI_BACKEND_URL/strapi-google-auth-with-token/auth', // like: http://localhost:1337/strapi-google-auth-with-token/auth
data: {
token: idToken // get the token from the Google sign-in button
}
}