larsvanteeffelen / silverstripe-google-sso
Silverstripe module for Google SSO
Installs: 37
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
Type:silverstripe-vendormodule
pkg:composer/larsvanteeffelen/silverstripe-google-sso
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/callbackReplace
your-domain.comwith your actual domain. - After creating the client ID, you will get a
Client IDand 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-idandyour-google-client-secretwith the values obtained from the Google Developer Console. - Replace
email1@example.com,email2@example.comwith 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
/adminURL and click the 'Sign in with Google' button. This button appears after clicking the SilverStripe logo 3 times or pressing 'CTRL + G'. - If the user is authorized (i.e., their email is in the
ALLOWED_EMAILSlist), 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.