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://www.youtube.com/watch?v=TJQ4NJrMvkw)
25 - [Azure Active Directory OIDC Guide](https://www.youtube.com/watch?v=CL5kMFkopHY)
26 - [Authentik BookStack OIDC Guide](https://www.youtube.com/watch?v=M1_WPhR4hRc)
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.
37 ### BookStack Configuration
39 To set up OIDC based authentication add or modify the following variables in your `.env` file:
42 # Set OIDC to be the authentication method
45 # Control if BookStack automatically initiates login via your OIDC system
46 # if it's the only authentication method. Prevents the need for the
47 # user to click the "Login with x" button on the login page.
48 # Setting this to true enables auto-initiation.
49 AUTH_AUTO_INITIATE=false
51 # Set the display name to be shown on the login button.
55 # Name of the claims(s) to use for the user's display name.
56 # Can have multiple attributes listed, separated with a '|' in which
57 # case those values will be joined with a space.
58 # Example: OIDC_DISPLAY_NAME_CLAIMS=given_name|family_name
59 OIDC_DISPLAY_NAME_CLAIMS=name
61 # OAuth Client ID to access the identity provider
64 # OAuth Client Secret to access the identity provider
65 OIDC_CLIENT_SECRET=def456
68 # Must start with 'https://'
69 OIDC_ISSUER=https://instance.authsystem.example.com
71 # Enable auto-discovery of endpoints and token keys.
72 # As per the standard, expects the service to serve a
73 # `<issuer>/.well-known/openid-configuration` endpoint.
74 OIDC_ISSUER_DISCOVER=true
76 ############################################################
77 ## NOTE: The below are only needed if not using the above ##
78 ## auto-discovery option. ##
79 ############################################################
81 # Path to identity provider token signing public RSA key
82 OIDC_PUBLIC_KEY=file:///keys/idp-public-key.pem
84 # Full URL to the OIDC authorize endpoint
85 OIDC_AUTH_ENDPOINT=https://instance.authsystem.example.com/v1/authorize
87 # Full URL to the OIDC token endpoint
88 OIDC_TOKEN_ENDPOINT=https://instance.authsystem.example.com/v1/token
91 A user in BookStack will be linked to an OIDC provided account via the `sub` claim.
92 If the value of this ID changes in the identity provider it can be updated in BookStack,
93 by an admin, by changing the "External Authentication ID" field on the user's profile.
97 Should your OIDC provider require a callback URL, the following can be used: `https://example.com/oidc/callback`.
98 Change `https://example.com` to be the base URL of your BookStack instance.
100 ### Switching to OIDC with Existing Users
102 When switching `AUTH_METHOD` from `standard` to `oidc`, BookStack will not
103 link OIDC user accounts to existing BookStack users, where the email address is
104 matching, since the "External Authentication ID" value of the existing BookStack user does
105 not match the unique user ID provided by the OIDC system.
107 You can overcome this situation by logging into BookStack with an admin account while `AUTH_METHOD=standard`.
108 While logged in, change `AUTH_METHOD` to `oidc`.
109 This change of authentication method will show an "External Authentication ID" text
110 field, below the name and email inputs, when viewing a user account in BookStack.
111 Here you can enter the unique user ID that would be provided by your OIDC provider.
112 Once saved BookStack will then use this value to match OIDC and BookStack user
113 accounts upon next login attempt.
115 If you need to update accounts in bulk, you could instead directly update the
116 `external_auth_id` field of the `users` table within your BookStack database.
120 To help when setting up or configuring BookStack to use your OIDC system, the below
121 `.env` option can help provide more insight:
124 # Dump out the details fetched from the identity provider.
125 # Only set this option to true if debugging since it will block logins
126 # and potentially show private details.
127 OIDC_DUMP_USER_DETAILS=false
130 Further to this, details of any BookStack errors encountered can be found by following
131 our [general debugging documentation](/docs/admin/debugging/).
133 ### Using a Different ID Claim
135 By default, BookStack will use the `sub` claim as a unique identifier to match up a user
136 between BookStack and the identify provider.
137 For the vast majority of use-cases, this is fine since this claim is part of the
140 In some very select scenarios, you may want to use a different claim as the unique identifier.
141 This can be done by setting an `OIDC_EXTERNAL_ID_CLAIM` option in your `.env` like shown below,
142 where the value of the option is the name of the claim:
145 # Configure a custom ID Token claim to be used as the
146 # "External Authentication ID" within BookStack.
147 OIDC_EXTERNAL_ID_CLAIM=upn
150 Note that changing this with existing BookStack OIDC users, without changing their "External Authentication ID" values,
151 may cause issues upon future login since their existing store ID in BookStack may no longer align.
155 BookStack has the ability to sync OIDC user groups with BookStack roles.
156 By default this will match OIDC group names with the BookStack role display names with casing ignored.
157 This can be overridden by via the 'External Authentication IDs' field which can be seen when editing a role while OIDC authentication is enabled.
158 If filled, the names in this field will be used and the BookStack role display name will be ignored.
159 You can match on multiple names by separating them with a comma.
160 Commas can be escaped with a backslash (`\,`) if you need to map using a literal comma character.
162 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.
164 This feature requires the OIDC server to provide a claim in the ID token with an array of group names.
165 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).
167 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.
169 Here are the settings required to be added to your `.env` file to enable group syncing:
172 # Enable OIDC group sync.
173 OIDC_USER_TO_GROUPS=true
175 # Set the attribute from which BookStack will read groups names from.
176 OIDC_GROUPS_CLAIM=groups
178 # Additional scopes to send with the authentication request.
179 # By default BookStack only sends the 'openid', 'profile' & 'email' scopes.
180 # Many platforms require specific scopes to be requested for group data.
181 # Multiple scopes can be added via comma separation.
182 OIDC_ADDITIONAL_SCOPES=groups
184 # Remove the user from roles that don't match OIDC groups upon login.
185 # Note: While this is enabled the "Default Registration Role", editable within the
186 # BookStack settings view, will be considered a matched role and assigned to the user.
187 OIDC_REMOVE_FROM_GROUPS=true
190 #### Nested Groups Claim Example
192 The below shows a reduced example of JSON data for an ID token, that has group data within a nested property,
193 along with the `OIDC_GROUPS_CLAIM` value that would be used for this structure to detect the provided "Editor" and "Admin" roles.
196 OIDC_GROUPS_CLAIM=resource_access.bookstack.roles