Learn how to create a social login with SPRING OAUTH + GOOGLE.
-
Google Oauth2,
-
We will need to set up Google OAuth2 and obtain OAuth credentials (ID + Secret) as described in the following link. https://developers.google.com/identity/openid-connect/openid-connect#appsetup
-
Be aware that when creating Google Credentials you will need to set this value http://localhost:8080/login/oauth2/code/google in the Authorized redirect URIs section.
-
You also need to set http://localhost:8080 value in the Authorized JavaScript origins section.
-
-
Java 17.
Set environment variables
The following environment variables must be created, and their values must be taken from the Google OAuth credentials. Do not share these credential values with anyone.
GOOGLE_CLIENT_ID = {Client ID}
GOOGLE_CLIENT_SECRET = {Client secret}
Execute following commands to build and run the project.
# Build project & install dependencies
./gradlew build
# Run project
./gradlew bootRun
Open a web browser and access the URL http://localhost:8080/personalInfo. Once this is completed you will be requested to log in with a Google account.
Step 1
Step 2
Step 3
Finally, by completing the login, information related to the logged user will be displayed. This information is provided by Google and can be used for multiple purposes in your application.