Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google oauth - Restrict sign-in to a particular google group

Is it possible to restrict login to my web application only the accounts that are in a google group ?

I don't want everyone can just login with their private gmail but only the users who are in my google group.

like image 817
mohamed haleem Avatar asked Jul 13 '16 09:07

mohamed haleem


People also ask

Does sign-in with Google use OAuth?

Google Sign-In manages the OAuth 2.0 flow and token lifecycle, simplifying your integration with Google APIs. A user always has the option to revoke access to an application at any time. This document describes how to complete a basic Google Sign-In integration.

How do I set the Consent screen in OAuth Google?

Configure OAuth consent & register your appIn the Google Cloud console, go to the OAuth consent screen. Select the user type for your app, then click Create. Complete the app registration form, then click Save and Continue.


1 Answers

I've been researching this, there are a few options to achieve this. First, if you are using G Suite on a hosted domain you can provide the hd parameter in the Sign In Oauth request, and set it to your domain. This would not allow anyone with a gmail address not @yourhost.com to authenticate. In that same step, you can request access (authorization) to make calls to the Groups API on behalf of that user (per @jwilleke's response). At that point you can use the token you get back and make a request on your back end for the private group and see if that user is part of it. If they are, let them in, if they aren't, deny access.

I've been searching for other ways to accomplish this however I haven't found a method that allows you to simply provide group authorization by virtue of applying some role to the Oauth client ID you spin up in GCP. The only other thing I can think of that would work is somehow creating your app in a way that allows you to provide it as a scope in your original authentication request. I know you can make your own API's and what not with Cloud Endpoints, however I'm not sure if that will ultimately get you what you want. Service providers like Ping / Okta have this kind of functionality because they can middle-man / provide the interface for the oidc flow.

like image 64
jlank Avatar answered Sep 20 '22 17:09

jlank