Authentication Through Google

Overview

Dex is able to use Google’s OpenID Connect provider as an authentication source.

The connector uses the same authentication flow as the OpenID Connect provider but adds Google specific features such as Hosted domain support and reading groups using a service account.

Configuration

  1. connectors:
  2. - type: google
  3. id: google
  4. name: Google
  5. config:
  6. # Connector config values starting with a "$" will read from the environment.
  7. clientID: $GOOGLE_CLIENT_ID
  8. clientSecret: $GOOGLE_CLIENT_SECRET
  9. # Dex's issuer URL + "/callback"
  10. redirectURI: http://127.0.0.1:5556/callback
  11. # Google supports whitelisting allowed domains when using G Suite
  12. # (Google Apps). The following field can be set to a list of domains
  13. # that can log in:
  14. #
  15. # hostedDomains:
  16. # - example.com
  17. # The Google connector supports whitelisting allowed groups when using G Suite
  18. # (Google Apps). The following field can be set to a list of groups
  19. # that can log in:
  20. #
  21. # groups:
  22. # - admins@example.com
  23. # Google does not support the OpenID Connect groups claim and only supports
  24. # fetching a user's group membership with a service account.
  25. # This service account requires an authentication JSON file and the email
  26. # of a G Suite admin to impersonate:
  27. #
  28. #serviceAccountFilePath: googleAuth.json
  29. #adminEmail: super-user@example.com

Fetching groups from Google

To allow Dex to fetch group information from Google, you will need to configure a service account for Dex to use. This account needs Domain-Wide Delegation and permission to access the https://www.googleapis.com/auth/admin.directory.group.readonly API scope.

To get group fetching set up:

  1. Follow the instructionsto set up a service account with Domain-Wide Delegation
  • During service account creation, a JSON key file will be created that contains authentication information for the service account. This needs storing in a location accessible by Dex and you will set the serviceAccountFilePath to point at it.
  • When delegating the API scopes to the service account, delegate the https://www.googleapis.com/auth/admin.directory.group.readonly scope and only this scope. If you delegate more scopes to the service account, it will not be able to access the API.
  1. Enable the Admin SDK
  2. Add the serviceAccountFilePath and adminEmail configuration options to your Dex config.
  • serviceAccountFilePath should point to the location of the service account JSON key file
  • adminEmail should be the email of a G Suite super user. The service account you created earlier will impersonate this user when making calls to the admin API. A valid user should be able to retrieve a list of groups when testing the API.