Demo Project for Gmail API and Google Calendar API Using Spring Boot Rest API with OAuth2
In this page, I’ll walk through the Demo Project for Gmail API and Google Calendar API Using Spring Boot with OAuth2.
This post shows you how to build a sample web application doing various things with Google APIs using OAuth2 and Spring Boot. It starts with a simple, single-provider single-sign on, and works up to a self-hosted OAuth2 Authorization Server with a choice of authentication providers (Fitbit or Facebook or Github).
Find the source code for Gmail API With OAuth2 in GitHub
Find the source code for Google Calendar API With OAuth2 in GitHub
Gmail API and Google Calendar API – Spring Boot and OAuth2
This project implemented with below skills.
1) Spring Boot
2) Rest API
3) Google Gmail API
4) Google Calendar API
What do I do?
I am simple Spring Boot application which secured by Spring Security. Instead of using simple form based security, I am secured by Spring Security OAuth2 and the OAuth provider is Google.
Why am I required?
Developing a Spring Boot web application with Security enabled and integrated with Google is hard to implement. So this is a sample implementation of Spring Boot + Spring Security OAuth2 + Google API Provider.
The project is built with Maven so you can run the build using mvn clean build
The application.properties (in src/main/resources) contains the details of the Google application which it uses to authenticate details. Change the values of the following attributes to the values for your application google.client.id google.client.secret and etc.,
To register a Google App perform the following steps
Go to https://console.developers.google.com and login with your Google account (this will be the developer account and the email of this account will be published when someone tries to authenticate with the Google application)
If you don’t have a project create a new one and then click into the project.
In the menu on the left side select “APIs & auth” –> “Credentials” –> “Create a new client ID”
In the popup select the following
Application Type = SpringBoot Web Application
Authorized Redirect URI = , the URI for our application is http://localhost:9000/login/google and http://localhost:9000/login/gmailCallback on different lines.
Copy the client ID and client Secret and update the application.properties
Make sure you update the mandatory values on the “APIs & auth” –> “Consent screen” page as the application will not work without it.
When you have a the Google App configured and the Spring boot application and you navigate to http://localhost:9000/login/google or http://localhost:9000/login/gmail. It will redirect you to a Google login page.
Upon login it will ask you to authorize your application for access to your account to get email and profile data. On successful login it will render the basic HTML page which means the authentication was sucessful.
<!– Google Calendar API Maven Dependency–>
<!– Gmail API Maven Dependency–>
That’s it. Thank you for reading this post.
I want you to do something for me right now: Leave a comment !!!
Like this post? Don’t forget to share it!