Prior to setting up any authentication, you will need to set up the base project using the make first-run
command. If you’ve already done so, and both configuration.yaml
and secrets.yaml
files have been generated, you can skip ahead.
By default, Toolkit does not enforce any authentication strategies. These can be enabled in your configuration.yaml
by using the auth.enabled_auth
list parameter and adding basic
, google_oauth
or oidc
.
For example:
auth:
enabled_auth:
- basic
- google_oauth
- oidc
Will enabled all 3 auth strategies. A secret_key
must then be added to the secrets.yaml
file for generating secure JWT tokens.
To generate an appropriate production auth.secret_key
value, you can use the following python code:
import secrets
print(secrets.token_hex(32))
Individual strategies might still require additional configuration, see below for more details.
BasicAuthentication: for email and password auth, no setup required.
secrets.yaml
file, update the auth.google_oauth.client_id
and auth.google_oauth.client_secret
variables.secrets.yaml
file, update the auth.oidc.client_id
, auth.oidc.client_secret
, and auth.oidc.well_known_endpoint
variables.When configuring your OAuth apps, make sure to whitelist the Redirect URI to the frontend endpoint, it should look like
<FRONTEND_HOST>/auth/<STRATEGY_NAME>
. For example, your Redirect URI will be http://localhost:4000/auth/google
if you’re running the GoogleOAuth class locally.
Many OIDC-compliant auth providers also implement PKCE for added protection. This involves generating code_verifier
and code_challenge
values in the frontend and using these values to validate that the same entity that initially logged in with the auth provider is the one requesting an access token from an authorization code.
For more details click here.
To enable the additional PKCE auth flow, you will need to first ensure your auth provider is PKCE-compliant, then set the PKCE_ENABLED
class attribute in your OIDCConnect auth strategy to True
.
To implement a new strategy, refer to the backend/services/auth/strategies
folder. Auth strategies will need to inherit from one of two base classes, BaseAuthenticationStrategy
or BaseOAuthStrategy
.
If your strategy requires environment variables, create a new <AUTH_METHOD>Settings
class, you can refer to the settings.py
file for more examples.
OAuth strategies should implement the authorize
method to verify an authorization code and return an access token.
Notes:
SCIM allows you organization to synchronize your users and groups from your identity provider to the Toolkit. This has the benefit of:
https://your-domain/scim/v2
In this step you will synchronize selected users. Note that while we can select groups here, it will only sync users in those groups, not the groups itself. This needs to be done in the next step.
This is optional but if groups should be synchronized, it needs to be configured like this: