Add 3rd Party Authentication (Google, Twitch etc.)
BookStack supports third-party authentication, allowing users to log in with services like Google, GitHub, Twitter, and others. By default, these services are disabled, but you can enable them by configuring the necessary credentials from each external service.
This guide will walk you through setting up third-party authentication, focusing on the most popular services: Google, GitHub, Twitter, Facebook, Slack, AzureAD, Okta, GitLab, Twitch, and Discord.
Step 1: Enable Automatic Registration (Optional)
If you want to auto-register users when they log in via a third-party service, add the following option to your .env
file or to your docker-compose.yaml
:
{SERVICE}_AUTO_REGISTER=true
For example, if you're setting up Google authentication:
GOOGLE_AUTO_REGISTER=true
This will allow users to register through third-party login services even if general registration is disabled.
Step 2: Enable Automatic Email Confirmation (Optional)
You can also enable automatic email confirmation, skipping the confirmation step for trusted third-party login services:
{SERVICE}_AUTO_CONFIRM_EMAIL=true
For example, for Google:
GOOGLE_AUTO_CONFIRM_EMAIL=true
Step 3: Configure Individual Third-Party Services
Google Authentication
-
- Open the Google Developers Console.
- Create a new project (May have to wait a short while for it to be created).
- In ‘API and Services’ go to the ‘OAuth consent screen’ section and enter a product name (‘BookStack’ or your custom set name) along with any other required details until you can save your consent screen.
- Now in the ‘API and Services’ > ‘Credentials’ section click ‘Create Credentials’ > ‘OAuth client ID’.
- Choose an application type of ‘Web application’ and enter the following urls under ‘Authorized redirect URIs’, changing
https://example.com
to your own domain where BookStack is hosted:https://example.com/login/service/google/callback
https://example.com/register/service/google/callback
- Hit ‘Create’ then take note of the ‘Client ID’ and ‘Client secret’ which you’ll use in the next step.
- Add or set the following items in your
.env
file like so:
# Replace the '{client_id}' and '{client_secret}' below with your Google Client ID and Client secret GOOGLE_APP_ID={client_id} GOOGLE_APP_SECRET={client_secret}
All done! Users should now be able to link their social accounts in their account profile pages and also register/login using their Google accounts.
Users can now register and log in using their Google accounts.
GitHub Authentication
- While
Gologgedtoin, open up your GitHubDeveloperdeveloperApplicationsapplications. - Click
click‘Register newapplicationapplication’. Enter an application name (‘BookStack’ or your custom set name) and
adda link to your app instance under ‘Homepage URL’. The ‘Authorization callback URL’ can be the root (homepage) URL for your BookStackinstanceinstance.URLOnceunderthoseHomepagedetailsURLare set, select ‘Register application’.- A ‘Client ID’ and
Authorizationacallback URL.
beSave the‘ClientIDSecret’andvalueClientwillSecret.shown. - Add
Addor set the followingtoitems in your BookStack.env
fileorlikedocker-compose.yaml:so:# Replace the '{client_id}' and '{client_secret}' below with your GitHub Client ID and Client secret GITHUB_APP_ID={client_id} GITHUB_APP_SECRET={client_secret}
Users can now log in with their GitHub accounts.
Twitter Authentication
Before creating a Twitter application for signing in, you will need to have signed up and be approved on the Twitter Developer site. Part of this will require describing your use of the API.
- Go
Signtoup at theyour Twitter Developer Portal, after being approved by twitter as described above. Navigate to ‘Projects andgetApps’approved> ‘Overview’ and under ‘Standalone Apps’ click ‘Create App’. - Enter an application name and save/continue to the next step.
- You’ll now be shown some keys and tokens. Copy out the shown ‘API key’ and ‘API secret key’ values for
APItheaccess.next step. - Within
CreateyouraBookStack.env
file add in extra options for your token and secret like so:
Back within the Twitter developer dashboard, find your new# Replace the below '{api_key}' and '{api_secret}' with your Twitter API key and API secret TWITTER_APP_ID={api_key} TWITTER_APP_SECRET={api_secret}
app,standalone app and click on ‘App Settings’ thenaddclick on edit within the ‘Authentication settings’ section.
- Enable the ‘3-legged OAuth’ and ‘Request email address from users’ options.
- Enter the following
callbackURLs(replaceunder ‘Callback URLs’, changinghttps://example.com
withto yourdomain):
owndomain where BookStack is hosted:
https://example.com/login/service/twitter/callback
https://example.com/register/service/twitter/callback
AddFilltheinAPIanykeyremainingandrequiredAPIURLssecretthenkeyclickto your.envfile ordocker-compose.yaml:TWITTER_APP_ID={api_key} TWITTER_APP_SECRET={api_secret}
Users can now log in with their Twitter accounts.
Facebook Authentication
Users can now log in with their Facebook accounts.
Slack Authentication
Go to the Slack
Appsapps page andcreateselecta‘Create An App’, then ‘From scratch’ when prompted.- Enter an app name (‘BookStack login’ or something custom) and your workspace then select “Create App”.
- Within an “App Credentials” section, you should find your client ID and secret. Copy these details and add them as new
app.variables InOAuth & Permissions, add your BookStack URL to theRedirect URLs.Add theClient IDandClient Secrettoin your.env
fileorlikedocker-compose.yaml:so:# Replace the below '{client_id}' and '{client_secret}' with your Slack client ID and secret SLACK_APP_ID={client_id} SLACK_APP_SECRET={client_secret}
- In your slack app go to ‘OAuth & Permissions’, find the ‘Redirect URLs’ section then ‘Add New Redirect URL’. Enter your BookStack base URL then ‘Add’ before pressing ‘Save URLs’.
Users can now log in with their Slack accounts.
AzureAD (Microsoft) Authentication
Note: If you intend all users to access your instance via Azure, then using an alternative primary authentication option like OIDC or SAML 2.0 will provide a better user experience while having more features like auto-login and group sync. A video guide for setting up OIDC with AzureAD can be found here.
- Login
Into your your azure portal and navigate to the ‘AzurePortal,ActivitygoDirectory’ area. - Under ‘Manage > App registrations’ select ‘New application registration’.
- Enter a name (‘BookStack’). Set the ‘Redirect URI’ to
AzuretheActive“Web”Directoryplatform>App registrationsand create a new registration.
toAddwith thefollowingvalueredirectsetURIs:the following, replacing ‘https://example.com/' with your base BookStack url:
https://example.com/login/service/azure/callback
AddOnce created, View theAppapplicationID,‘Overview’App Secret,page andTenantnoteIDthe ‘Application (client) ID’ and ‘Directory (tenant) ID’ values. These are the APP_ID and TENANT values for step 9.- Within your application in azure, Navigate to ‘Certificates & secrets’ then choose ‘New client secret’.
- Enter any description you want and set an expiry duration. Then click ‘Save’.
- Copy the string of characters under ‘Value’. This is the APP_SECRET value for step 9 and is only shown once.
- Navigate to ‘API permissions’ for your app. You should already have a “Microsoft Graph” > “User.Read” permission assigned. If not choose ‘Add a permission’. Find the ‘Microsoft Graph’ option within this, then select ‘Delegated permissions’ then find & select the ‘User.Read’ permission. Then select ‘Add permissions’ at the bottom of the page.
- Copy these details and add them as new variables in your
.env
fileorlikedocker-compose.yaml:so:
# Replace the below '{APP_ID}', '{APP_SECRET}' and '{TENANT}' values with your Azure APP_ID and APP_SECRET and TENANT AZURE_APP_ID={
app_id}APP_ID} AZURE_APP_SECRET={app_secret}APP_SECRET} AZURE_TENANT={tenant_id}TENANT}
Users can now log in with their AzureAD accounts.
Okta Authentication
Note: If you intend all users to access your instance via Okta, then using an alternative primary authentication option like OIDC or SAML 2.0 will provide a better user experience while having more features like auto-login and group sync.
- Login
Into Okta and, once logged in, Note theOktacurrent URL. This is used for the ‘base_url’ in step 6. - Navigate to the Admin
Panel,panelcreatethen ‘Applications’ then select ‘Add Application’. Then select ‘Create New App’ on the left. - For the ‘Platform’ choose ‘Web’. For the ‘Sign on method’ choose ‘OpenID Connect’ then click ‘Create’.
- Give the app a
newnameappsuchwithasWeb‘BookStack’platformorand‘OurOpenIDdocumentation’.Connectmethod.
URIs’AddUnder thefollowing‘LogincallbackredirectURLs:option add both of the below URLs, Changing
https://example.com
to the base URL of your BookStack instance:https://example.com/login/service/okta/callback
https://example.com/register/service/okta/callback
AddSave and scroll down to the ‘ClientID,Credentials’ area. Copy the ‘ClientSecret,ID’ andBase‘ClientURLsecret’tovalues for the next step.- Copy these details and add them as new variables in your
.env
fileorlikedocker-compose.yaml:so:
# Replace the below '{client_id}' and '{client_Secret}' with your Okta client ID and secret OKTA_APP_ID={client_id} OKTA_APP_SECRET={client_secret} # Replace the '{base_url}' below with the URL from step 1 # but with everything after the domain (okta.com) removed. OKTA_BASE_URL={base_url}
Users can now log in with their Okta accounts.
Twitch Authentication
To allow Twitch sign-in you’ll first need to create an application from the Twitch developer site. Here’s the process:
- Login
Ininto the TwitchDeveloperdeveloperDashboardwebsite,. - Navigate to your ‘Dashboard’ then ‘Apps’ and select ‘Register Your Application’.
- Set a
newnameapplication.to
asAddidentify thefollowingapplication,redirectsuchURIs:‘BookStack Authentication’, and in the ‘OAuth Redirect URI’ input add the below URL, Changing
https://example.com
to the base URL of your BookStack instance:https://example.com/login/service/twitch/callback
AddUnder theClient‘ApplicationIDCategory’ option select ‘Website Integration’ then hit ‘Register’.- Click the ‘New Secret’ button and accept the prompt that appears. You should now see both a ‘Client
SecretID’toand ‘Client Secret’ value which you’ll use in the next step. - Copy the below details and add them as new variables in your
.env
fileorlikedocker-compose.yaml:so:
# Replace the below '{client_id}' and '{client_secret}' with your Twitch client ID and secret values. TWITCH_APP_ID={client_id} TWITCH_APP_SECRET={client_secret}
Users can now log in with their Twitch accounts.
Discord Authentication
To allow Discord sign-in you’ll first need to create an application on the Discord developer site. Here’s the process:
- Login
Ininto the DiscordDeveloperdeveloperPortalwebsite,. - Select ‘Create an application’.
- Set a
newnameapplication.to identify the application, such as ‘BookStack Authentication’, and save.
theAddIn thefollowingsidebar,redirectOpenURIs:OAuth2 settings for your application and add a redirect. Input the below URL, Changing
https://example.com
to be the base URL of your BookStack instance then save:https://example.com/login/service/discord/callback
AddBack in the ‘General Information’ section find the ‘ClientIDID’ and ‘ClientSecretSecret’tovalues which you’ll use in the next step.- Copy the below details and add them as new variables in your
.env
fileorlikedocker-compose.yaml:so:
# Replace the below '{client_id}' and '{client_secret}' with your Discord client ID and secret values. DISCORD_APP_ID={client_id} DISCORD_APP_SECRET={client_secret}
Users can now log in with their Discord accounts.