2 title = "OpenID Connect Authentication"
3 description = "How to use an OpenID Connect identity provider as your primary way to access BookStack"
8 OpenID Connect (OIDC) can be used within BookStack as a primary method of authentication.
9 This replaces the default email & password authentication mechanism.
10 BookStack supports a simple level of auto-discovery to ease endpoint and key management.
12 When used, BookStack will attempt to match the OIDC user to an existing BookStack user
13 based on the "External Authentication ID" value stored against the Bookstack user.
14 If this match cannot be made, BookStack will effectively auto-register that user to
15 provide a seamless access experience. They will be given the default role set under the
16 "Default user role after registration" option in the application settings.
22 We have a range of videos available that can help show, for a range of identity platforms, the exact steps required to set-up a BookStack OpenID Connect authentication integration:
24 - [General setup guide (Using Okta as an example)](https://foss.video/w/1b6sc98un7ugGv98v9UaRC)
25 - [Azure Active Directory OIDC Guide](https://foss.video/w/n67qNijhf8BdTRQys8SDYf)
26 - [Authentik BookStack OIDC Guide](https://foss.video/w/a744K8GxFF1LqBFSadAsuV)
28 ### Requirements & Limitations
30 Listed below are some considerations to keep in mind in regard to BookStack's OIDC implementation:
32 - Only RS256 is currently supported as a token signing algorithm, Token encryption is not supported.
33 - Discovery covers fetching the auth & token endpoints, in addition to parsing any keys at the JWKS URI,
34 from the `<issuer>/.well-known/openid-configuration` endpoint.
35 - Issuer discovery is not supported.
36 - RP-initiated logout is supported if enabled, but any other logout mechanisms are not supported.
38 ### BookStack Configuration
40 To set up OIDC based authentication add or modify the following variables in your `.env` file:
43 # Set OIDC to be the authentication method
46 # Control if BookStack automatically initiates login via your OIDC system
47 # if it's the only authentication method. Prevents the need for the
48 # user to click the "Login with x" button on the login page.
49 # Setting this to true enables auto-initiation.
50 AUTH_AUTO_INITIATE=false
52 # Set the display name to be shown on the login button.
56 # Name of the claims(s) to use for the user's display name.
57 # Can have multiple attributes listed, separated with a '|' in which
58 # case those values will be joined with a space.
59 # Example: OIDC_DISPLAY_NAME_CLAIMS=given_name|family_name
60 OIDC_DISPLAY_NAME_CLAIMS=name
62 # OAuth Client ID to access the identity provider
65 # OAuth Client Secret to access the identity provider
66 OIDC_CLIENT_SECRET=def456
69 # Must start with 'https://'
70 OIDC_ISSUER=https://instance.authsystem.example.com
72 # The "end session" (RP-initiated logout) URL to call during BookStack logout.
73 # By default this is false which disables RP-initiated logout.
74 # Setting to "true" will enable logout if found as supported by auto-discovery.
75 # Otherwise, this can be set as a specific URL endpoint.
76 OIDC_END_SESSION_ENDPOINT=false
78 # Enable auto-discovery of endpoints and token keys.
79 # As per the standard, expects the service to serve a
80 # `<issuer>/.well-known/openid-configuration` endpoint.
81 OIDC_ISSUER_DISCOVER=true
83 ############################################################
84 ## NOTE: The below are only needed if not using the above ##
85 ## auto-discovery option. ##
86 ############################################################
88 # Path to identity provider token signing public RSA key
89 OIDC_PUBLIC_KEY=file:///keys/idp-public-key.pem
91 # Full URL to the OIDC authorize endpoint
92 OIDC_AUTH_ENDPOINT=https://instance.authsystem.example.com/v1/authorize
94 # Full URL to the OIDC token endpoint
95 OIDC_TOKEN_ENDPOINT=https://instance.authsystem.example.com/v1/token
98 A user in BookStack will be linked to an OIDC provided account via the `sub` claim.
99 If the value of this ID changes in the identity provider it can be updated in BookStack,
100 by an admin, by changing the "External Authentication ID" field on the user's profile.
102 ### Authentication System Configuration
104 With OIDC you don't often need to configure much specifically for BookStack.
105 Most often, you'll just need to ensure any callback/redirect URIs are set as below:
107 - **Login Callback/Redirect URI:** `https://example.com/oidc/callback`
108 - **Logout Callback/Redirect URIs:**
109 - `https://example.com`
110 - `https://example.com/login`
111 - `https://example.com/login?prevent_auto_init=true`
112 - *Only one URL will actually be used but it depends upon specific configuration set. Some systems will allow you to instead use a wildcard like `https://example.com/*`.*
114 Change `https://example.com` to be the base URL of your BookStack instance.
116 Since v24.02 BookStack will make use of Proof Key for Code Exchange (PKCE) during authentication.
117 If your authentication system provides the option, you should enforce PKCE to be required for extra security.
119 ### Switching to OIDC with Existing Users
121 When switching `AUTH_METHOD` from `standard` to `oidc`, BookStack will not
122 link OIDC user accounts to existing BookStack users, where the email address is
123 matching, since the "External Authentication ID" value of the existing BookStack user does
124 not match the unique user ID provided by the OIDC system.
126 You can overcome this situation by logging into BookStack with an admin account while `AUTH_METHOD=standard`.
127 While logged in, change `AUTH_METHOD` to `oidc`.
128 This change of authentication method will show an "External Authentication ID" text
129 field, below the name and email inputs, when viewing a user account in BookStack.
130 Here you can enter the unique user ID that would be provided by your OIDC provider.
131 Once saved BookStack will then use this value to match OIDC and BookStack user
132 accounts upon next login attempt.
134 If you need to update accounts in bulk, you could instead directly update the
135 `external_auth_id` field of the `users` table within your BookStack database.
139 To help when setting up or configuring BookStack to use your OIDC system, the below
140 `.env` option can help provide more insight:
143 # Dump out the details fetched from the identity provider.
144 # Only set this option to true if debugging since it will block logins
145 # and potentially show private details.
146 OIDC_DUMP_USER_DETAILS=false
149 Further to this, details of any BookStack errors encountered can be found by following
150 our [general debugging documentation](/docs/admin/debugging/).
152 ### Using a Different ID Claim
154 By default, BookStack will use the `sub` claim as a unique identifier to match up a user
155 between BookStack and the identify provider.
156 For the vast majority of use-cases, this is fine since this claim is part of the
159 In some very select scenarios, you may want to use a different claim as the unique identifier.
160 This can be done by setting an `OIDC_EXTERNAL_ID_CLAIM` option in your `.env` like shown below,
161 where the value of the option is the name of the claim:
164 # Configure a custom ID Token claim to be used as the
165 # "External Authentication ID" within BookStack.
166 OIDC_EXTERNAL_ID_CLAIM=upn
169 Note that changing this with existing BookStack OIDC users, without changing their "External Authentication ID" values,
170 may cause issues upon future login since their existing store ID in BookStack may no longer align.
174 BookStack has the ability to sync OIDC user groups with BookStack roles.
175 By default this will match OIDC group names with the BookStack role display names with casing ignored.
176 This can be overridden by via the 'External Authentication IDs' field which can be seen when editing a role while OIDC authentication is enabled.
177 If filled, the names in this field will be used and the BookStack role display name will be ignored.
178 You can match on multiple names by separating them with a comma.
179 Commas can be escaped with a backslash (`\,`) if you need to map using a literal comma character.
181 When matching OIDC groups with role names or 'External Authentication IDs' values, BookStack will standardise the names of OIDC groups to be lower-cased and spaces will be replaced with hyphens. For example, to match a OIDC group named "United Kingdom" an 'External Authentication IDs' value of "united-kingdom" could be used.
183 This feature requires the OIDC server to provide a claim in the ID token with an array of group names.
184 You'll need to specify the attribute using the `OIDC_GROUPS_CLAIM` to tell BookStack what claim it can find groups on. This value can use dot-notation to access nested properties in the ID token JSON data, an example of which can be [found below](#nested-groups-claim-example).
186 Keep in mind you can use the `OIDC_DUMP_USER_DETAILS` option, as shown in the above [debugging](#debugging) section to dump out claim values provided by your authentication system to help understand what is being provided by your authentication system.
188 Here are the settings required to be added to your `.env` file to enable group syncing:
191 # Enable OIDC group sync.
192 OIDC_USER_TO_GROUPS=true
194 # Set the attribute from which BookStack will read groups names from.
195 OIDC_GROUPS_CLAIM=groups
197 # Additional scopes to send with the authentication request.
198 # By default BookStack only sends the 'openid', 'profile' & 'email' scopes.
199 # Many platforms require specific scopes to be requested for group data.
200 # Multiple scopes can be added via comma separation.
201 OIDC_ADDITIONAL_SCOPES=groups
203 # Remove the user from roles that don't match OIDC groups upon login.
204 # Note: While this is enabled the "Default Registration Role", editable within the
205 # BookStack settings view, will be considered a matched role and assigned to the user.
206 OIDC_REMOVE_FROM_GROUPS=true
209 #### Nested Groups Claim Example
211 The below shows a reduced example of JSON data for an ID token, that has group data within a nested property,
212 along with the `OIDC_GROUPS_CLAIM` value that would be used for this structure to detect the provided "Editor" and "Admin" roles.
215 OIDC_GROUPS_CLAIM=resource_access.bookstack.roles