larsvanteeffelen / silverstripe-google-sso
Silverstripe module for Google SSO
Installs: 28
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
Type:silverstripe-vendormodule
Requires
- league/oauth2-google: ^4.0
- silverstripe/admin: ^2.0
- silverstripe/cms: ^5.0
- silverstripe/framework: ^5.0
- silverstripe/login-forms: ^5.0
README
This SilverStripe module enables Google Single Sign-On (SSO) for your SilverStripe application. With this module, you can define a list of authorized email addresses and allow users to log in using their Google accounts.
Features
- Login using Google OAuth 2.0
- Restrict login to specific email addresses
- Automatically create and log in admin users
- Alternative (but basic) login UI
Installation
To install this module, you need to add it to your SilverStripe project. You can do this by downloading the module and placing it in the app
directory of your SilverStripe project.
Alternatively, you can install it via composer:
composer require larsvanteeffelen/silverstripe-google-sso
Configuration
Google OAuth 2.0 Setup
To use Google SSO, you need to create a Google OAuth 2.0 client ID and secret. Follow these steps:
- Go to the Google Developer Console.
- Create a new project or select an existing one.
- Navigate to the "Credentials" page.
- Create a new OAuth 2.0 Client ID.
- Set the redirect URI to the following:
https://your-domain.com/google-login/callback
Replace
your-domain.com
with your actual domain. - After creating the client ID, you will get a
Client ID
and aClient Secret
.
Environment Variables
Add the following environment variables to your .env
file in the SilverStripe project:
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
ALLOWED_EMAILS="email1@example.com,email2@example.com"
- Replace
your-google-client-id
andyour-google-client-secret
with the values obtained from the Google Developer Console. - Replace
email1@example.com,email2@example.com
with the comma-separated list of authorized email addresses.
URL Routing
This module registers the following routes:
/google-login/login
: Starts the Google OAuth 2.0 login process./google-login/callback
: Handles the OAuth 2.0 callback from Google and logs in the user if authorized.
These routes can be used if you want to create your own template. However, You can also just use the modified template included with this package.
Usage
- Visit the
/admin
URL and click the 'Sign in with Google' button - If the user is authorized (i.e., their email is in the
ALLOWED_EMAILS
list), they will be logged in and redirected to the SilverStripe admin panel. - If the user is not authorized, they will see an error message.
License
This module is licensed under the MIT License.