Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google oAuth login - How to allow only whitelisted emails to log into my app

I'm creating a web app and decided to use google authentication for its ease of use. Thing is, I want to only let certain emails login. All other emails should not be able to login!

How do I do that?

I'm aware that I can send the auth token to the backend, verify it with google's library, and then filter the emails but... there should be an easier way, I hope?

like image 957
John The Tester Avatar asked Jan 31 '26 04:01

John The Tester


1 Answers

You need to consider how Open id and oauth work. You are technically forwarding a user over to googles login page. They login and approve any apis on Googles site you have no way of knowing who they are until they are redirected back to you.

Nor is there any way to limit the users who can login to your client directly in Googles Developer console for your project. TBH i think that would be really hard for them to administrate.

Your best bet is going to be checking the users email when they return and decide that that time if they may login or not. It would be also be a good idea to do a revoke on any credentials google returns to you if you dont want them to have access.

like image 63
DaImTo Avatar answered Feb 03 '26 09:02

DaImTo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!