Welcome to Part 12 of this series of guides on how to integrate Gmail with Angular and Spring Boot.
In this guide you'll find a plot twist.
I'm going to show you how to stop integrating with Gmail.
Yeah. You might need to do that sometimes.
Follow along and you'll learn how and why.
11 Guides of Marital Bliss
Thus far in the series, you have:
- Created an OAuth2 client ID and secret on Google Cloud Console
- Enabled the Gmail API via Google Cloud Console
- Set the necessary properties in your Spring Boot application.properties file
- Set up a DataStore implementation with its associated factory
- Set up a refresh listener
- Created a utility class that handles the Google authorization code flow
- Set up proper Gmail consent with the Google Cloud Platform
- Created a controller that handles a request to get the Google authorization code flow URL
- Used Postman to get the Google authorization code URL
- Used that URL to authorize your application to access your Gmail inbox
- Updated the controller so it handles a token request
- Updated the utility class so it creates the credential from a token
- Persisted that credential
- Used Postman to retrieve the token
- Learned why you didn't actually need to retrieve the token
- Learned about the structure of the Message object
- Learned about MIME
- Created an Email type that gets sent back to the client
- Wrote code that converts a Message object to an Email object
- Instantiated the Gmail service
- Used the Gmail service to retrieve just the messages you want to retrieve
- Used the Gmail service to extracted full Message objects from very lightweight objects
- Added a new endpoint to listen for inbox requests
- Used that endpoint to send back the user's most recent emails
And if you haven't done those things, then you should take a look at Part 1 and work forward from there.
But This Is Where It Ends
In this guide, you'll learn how to disallow your application from accessing your inbox.
You'll write the app a bill of divorcement, in other words.
And, believe it or not, you need to know how to do that.
Why would you grant your application access to your Gmail inbox only to turn around and rip it away again?
Because you're still in the testing phase. It's likely you'll want to go through the whole authorization code flow again and again just so you can repeatedly see what the end user sees.
Also, you'll only get back the refresh token when you authorize by going through that whole process for the first time. After that, every time you reauthorize you'll just get back an access token.
That token is only good for about an hour. So once that hour is up, you'll need to reauthorize.
But not so if you have a refresh token.
So yeah, you'll need to write that bill of divorcement.
With Google It's Possible
Good news: you don't need to write any code to make this happen. It's all handled via your Google account.
So zip on over to the page that handles your account's permissions. It will probably look something like this:
Check out that "Carey Development" at the bottom there. That's saying that Carey Development has access to my Gmail.
In fact, it does have access to my Gmail. I gave it access to my Gmail.
But maybe I don't want it to have access to my Gmail any more (see above). How do I eliminate that access?
It's easy. Just click on the name of any app that has access and you'll see something that looks like this:
All you have to do is smash that big blue button that says REMOVE ACCESS. You'll see a confirmation prompt asking you if you're sure you want to do that.
If you're sure, click OK on that confirmation prompt and it's over.
You and that app are officially divorced. The app can no longer read, compose, send, and permanently delete all of your email from Gmail.
Getting Back Together
So what happens if you two want to reconcile?
I think you'll end up granting and revoking access over and over again during the testing phase of your integration. That's perfectly normal.
After all, there are still quite a few kinks to work out.
Wrapping It Up
There you have it. An easy way to revoke any application's access to your Google account.
Now that you know how to do that, there's nothing stopping you from doing some really comprehensive testing.
Just make sure you have fun!
Photo by from