]> BookStack Code Mirror - website/blob - content/docs/admin/third-party-auth.md
2e45a981dfe1d3a7553adda3985d391fd4e184ca
[website] / content / docs / admin / third-party-auth.md
1 +++
2 title = "Third Party Authentication"
3 description = "Enabling and configuring third-party authentication for easier logins"
4 date = "2017-01-01"
5 type = "admin-doc"
6 aliases = [
7     "/docs/admin/social-auth"
8 ]
9 +++
10
11 BookStack currently supports login via a range of third party and social applications. Once enabled options for these services will show up in the login, registration and user profile pages. By default these services are disabled. To enable them you will have to create an application on the external services to obtain the require application id's and secrets.
12
13 #### Available Services
14
15 * [Google](#google)
16 * [GitHub](#github)
17 * [Twitter](#twitter)
18 * [Facebook](#facebook)
19 * [Slack](#slack)
20 * [AzureAD (Microsoft)](#azuread-microsoft)
21 * [Okta](#okta)
22 * [GitLab](#gitlab)
23 * [Twitch](#twitch)
24 * [Discord](#discord)
25
26 #### Automatic Registration
27
28 You may find that you'd like to auto-register users, from the login screen, when they use a social authentication option. To do this add the following `.env` option, altering the `{SERVICE}` to match the login service you are using:
29
30 ```bash
31 {SERVICE}_AUTO_REGISTER=true
32
33 # Examples
34 GOOGLE_AUTO_REGISTER=true
35 TWITCH_AUTO_REGISTER=true
36 ```
37
38 This will allow registration using these services even if registrations are disabled.
39 It also allows registration if using LDAP as your main authentication option.
40
41 #### Automatic Email Confirmation
42
43 If you trust a third-party login service you can enable automatic email confirmation. This skips the 'Confirm Email' setting, even if domain restrictions are enabled although the domain of the email address provided by the social service will still be checked. To do this add the following `.env` option, altering the `{SERVICE}` to match the login service you are using and trust:
44
45 ```bash
46 {SERVICE}_AUTO_CONFIRM_EMAIL=true
47
48 # Examples
49 GOOGLE_AUTO_CONFIRM_EMAIL=true
50 TWITCH_AUTO_CONFIRM_EMAIL=true
51 ```
52
53 ---
54
55 ### Google
56
57 1. Open the [Google Developers Console](https://console.developers.google.com/).
58 2. Create a new project (May have to wait a short while for it to be created).
59 3. In 'Credentials' choose the 'OAuth consent screen' tab and enter a product name ('BookStack' or your custom set name).
60 4. Back in the 'Credentials' tab click 'New credentials' > 'OAuth client ID'.
61 5. 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:
62     - `https://example.com/login/service/google/callback`
63     - `https://example.com/register/service/google/callback`
64 6. Add or set the following items in your `.env` file like so:
65 ```bash
66 # Replace the below (including '{}' braces) with your Google API_KEY and API_SECRET
67 GOOGLE_APP_ID={google_app_id}
68 GOOGLE_APP_SECRET={google_app_secret}
69
70 # APP_URL Needs to be set to your BookStack base url
71 APP_URL=http://mybookstackurl.com
72 ```
73 7. 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.
74
75 ---
76
77 ### GitHub
78
79 1. While logged in, open up your [GitHub developer applications](https://github.com/settings/developers).
80 2. Click 'Register new application'.
81 3. Enter an application name ('BookStack' or your custom set name) and a link to your app instance under 'Homepage URL'. The 'Authorization callback URL' can be the root (homepage) URL for your BookStack instance. Once those details are set, select 'Register application'.
82 4. A 'Client ID' and a 'Client Secret' value will be shown. Add these two values to the to the `GITHUB_APP_ID` and `GITHUB_APP_SECRET` variables, replacing the default false value, in the '.env' file found in the BookStack root folder.
83 5. Set the 'APP_URL' environment variable to be the same domain as you entered in step 3.
84 6. All done! Users should now be able to link their social accounts in their account profile pages and also register/login using their GitHub account.
85
86 ---
87
88 ### Twitter
89
90 Before creating a Twitter application for signing in, you will need to have signed up and be approved on the [Twitter Developer](https://developer.twitter.com/) site. Part of this will require describing your use of the API. 
91
92 1. Go to your [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard), after being approved by twitter as described above. Navigate to 'Projects and Apps' > 'Overview'  and under 'Standalone Apps' click 'Create App'.
93 2. Enter an application name and save/continue to the next step.
94 3. You'll now be shown some keys and tokens. Copy out the shown 'API key' and 'API secret key' values for the next step.
95 4. Within your BookStack `.env` add in extra options for your token and secret like so:
96 ```bash
97 # Replace the below (including '{}' braces) with your twitter API_KEY and API_SECRET
98 TWITTER_APP_ID={API_KEY}
99 TWITTER_APP_SECRET={API_SECRET}
100
101 # APP_URL Needs to be set to your BookStack base url
102 APP_URL=http://mybookstackurl.com
103 ```
104 5. Back within the Twitter developer dashboard, find your new standalone app and click on 'App Settings'  then click on edit within the 'Authentication settings' section.
105 6. Enable the '3-legged OAuth' and 'Request email address from users' options.
106 7. Enter the following URLs under 'Callback URLs', changing `https://example.com` to your own domain where BookStack is hosted:
107     - `https://example.com/login/service/twitter/callback`
108     - `https://example.com/register/service/twitter/callback`
109 8. Fill in any remaining required URLs then click save.
110 9. All done! Users should now be able to link their Twitter account in their account profile pages and also register/login using their Twitter account. You may want to review the other options for the Twitter Standalone app such as setting a logo and description.
111
112 ---
113
114 ### Facebook
115
116 1. Navigate to the [Facebook developers page](https://developers.facebook.com) then go 'My Apps' -> 'Add a New App'.
117 2. Enter an app name ('BookStack login' or something custom) and contact email then continue.
118 3. In your new app select 'Add Product' on the left sidebar then choose 'Facebook Login' by clicking the 'Get Started' button. Select the 'Web' option if asked to choose a platform.
119 4. Enter the your base BookStack url into the 'Site URL' box and save.
120 5. On the left sidebar again go to 'Facebook Login' -> 'Settings'.
121 6. Enter the following URLs under 'Valid OAuth Redirect URIs', changing `https://example.com` to your own domain where BookStack is hosted:
122     - `https://example.com/login/service/facebook/callback`
123     - `https://example.com/register/service/facebook/callback`
124 7. Navigate back to the app 'Dashboard' in the sidebar to find your app id and secret. Add or set these to your `.env` file like so:
125 ```bash
126 # Replace the below (including '{}' braces) with your facebook APP_KEY and APP_SECRET
127 FACEBOOK_APP_ID={APP_KEY}
128 FACEBOOK_APP_SECRET={APP_SECRET}
129
130 # APP_URL Needs to be set to your BookStack base url
131 APP_URL=http://mybookstackurl.com
132 ```
133 7. All done! Users should now be able to link their Facebook account in their account profile pages and also register/login using their Facebook account.
134
135 ---
136
137 ### Slack
138
139 1. Go to the [Slack apps page](https://api.slack.com/apps) and select 'Create An App', then 'From scratch' when prompted.
140 2. Enter an app name ('BookStack login' or something custom) and your workspace then select "Create App".
141 3. Within an "App Credentials" section, you should find your client ID and secret. Copy these details and add them as new variables in your `.env` file like so:
142 ```bash
143 # Replace the below (including '{}' braces) with your slack CLIENT_ID and CLIENT_SECRET
144 SLACK_APP_ID={CLIENT_ID}
145 SLACK_APP_SECRET={CLIENT_SECRET}
146
147 # APP_URL Needs to be set to your BookStack base url
148 APP_URL=http://mybookstackurl.com
149 ```
150 4. 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'.
151 5. All done! Users should now be able to link their Slack account in their account profile pages and also register/login using their Slack account.
152
153 ---
154
155 ### AzureAD (Microsoft)
156
157 ***Note:** If you intend all users to access your instance via Azure, then using an alternative primary authentication option like [OIDC](/docs/admin/oidc-auth/) or [SAML 2.0](/docs/admin/saml2-auth/) 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](https://foss.video/w/n67qNijhf8BdTRQys8SDYf).*
158
159 1. Login to your your azure portal and navigate to the 'Azure Activity Directory' area.
160 2. Under 'Manage > App registrations' select 'New application registration'.
161 3. Enter a name ('BookStack'). Set the 'Redirect URI' to the "Web" platform with the value set to the following, replacing 'https://example.com/' with your base BookStack url: 
162     - `https://example.com/login/service/azure/callback`
163 4. Once created, View the application 'Overview' page and note the 'Application (client) ID' and 'Directory (tenant) ID' values. These are the APP_ID and TENANT values for step 9.
164 5. Within your application in azure, Navigate to 'Certificates & secrets' then choose 'New client secret'.
165 6. Enter any description you want and set an expiry duration. Then click 'Save'.
166 7. Copy the string of characters under 'Value'. This is the APP_SECRET value for step 9 and is only shown once.
167 8. 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.
168 9. Copy these details and add them as new variables in your `.env` file like so:
169 ```bash
170 # Replace the below (including '{}' braces) with your azure APP_ID and APP_SECRET and TENANT
171 AZURE_APP_ID={APP_ID}
172 AZURE_APP_SECRET={APP_SECRET}
173 AZURE_TENANT={TENANT}
174
175 # APP_URL Needs to be set to your BookStack base url, likely already configured
176 APP_URL=http://mybookstackurl.com
177 ```
178 10. All done! Users should now be able to link their AzureAD account in their account profile pages and also register/login using their AzureAD account.
179
180 ---
181
182 ### Okta
183
184 ***Note:** If you intend all users to access your instance via Okta, then using an alternative primary authentication option like [OIDC](/docs/admin/oidc-auth/) or [SAML 2.0](/docs/admin/saml2-auth/) will provide a better user experience while having more features like auto-login and group sync.*
185
186 1. Login to Okta and, once logged in, Note the current URL. This is used for the 'BASE_URL' in step 6.
187 2. Navigate to the Admin panel then 'Applications' then select 'Add Application'. Then select 'Create New App' on the left.
188 3. For the 'Platform' choose 'Web'. For the 'Sign on method' choose 'OpenID Connect' then click 'Create'.
189 4. Give the app a name such as 'BookStack' or 'Our documentation'. Under the 'Login redirect URIs' option add both of the below URLs, Changing `https://example.com` to the base URL of your BookStack instance:
190     - `https://example.com/login/service/okta/callback`
191     - `https://example.com/register/service/okta/callback`
192 5. Save and scroll down to the 'Client Credentials' area. Copy the 'Client ID' and 'Client secret' values. These are your 'APP_ID' and 'APP_SECRET' values for step 6.
193 6. Copy these details and add them as new variables in your `.env` file like so:
194 ```bash
195 # Replace the below (including '{}' braces) with your okta APP_ID and APP_SECRET and BASE_URL.
196 OKTA_APP_ID={APP_ID}
197 OKTA_APP_SECRET={APP_SECRET}
198 # The base URL is the URL from step 1 but with everything after the domain (okta.com) removed.
199 OKTA_BASE_URL={BASE_URL}
200
201 # APP_URL Needs to be set to your BookStack base url
202 APP_URL=http://mybookstackurl.com
203 ```
204 7. All set up! Remember to assign the new application you created in Okta to your Okta users otherwise they will not be able to register/login using the service.
205
206 ---
207
208 ### GitLab
209
210 GitLab authentication works for both [gitlab.com](https://gitlab.com) and self-hosted GitLab instances.
211
212 1. Login to GitLab and go to your user settings.
213 2. In the left sidebar select 'Applications'.
214 3. Set a name to identify the application, such as 'BookStack Authentication', and in the 'Redirect URI' input add both of the below URLs, Changing `https://example.com` to the base URL of your BookStack instance:
215     - `https://example.com/login/service/gitlab/callback`
216     - `https://example.com/register/service/gitlab/callback`
217 4. Select the checkbox for the `read_user` scope.
218 5. Press 'Save application'. You will be shown the application ID and secret which you'll need for the next step.  
219 6. Copy the below details and add them as new variables in your `.env` file like so:
220 ```bash
221 # Replace the below (including '{}' braces) with your GitLab Application Id and Secret values.
222 GITLAB_APP_ID={APP_ID}
223 GITLAB_APP_SECRET={APP_SECRET}
224
225 # APP_URL Needs to be set to your BookStack base url
226 APP_URL=http://mybookstackurl.com
227
228
229 # ONLY REQURED FOR SELF-HOSTED GITLAB INSTANCES - REMOVE FOR GITLAB.COM
230 # The below needs to match the base URI of your GitLab install, including the trailing slash.
231 GITLAB_BASE_URI=http://my-custom-gitlab.example.com/
232 ```
233 7. All set up! Users will now be able to use GitLab to sign-in and register.
234
235 ---
236
237 ### Twitch
238
239 To allow twich sign-in you'll first need to create an application from the Twitch developer site. Here's the process:
240
241 1. Login into the [Twitch developer website](https://dev.twitch.tv/).
242 2. Navigate to your 'Dashboard' then ['Apps'](https://dev.twitch.tv/dashboard/apps) and select 'Register Your Application'.
243 3. Set a name to identify the application, such as '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:
244     - `https://example.com/login/service/twitch/callback`
245 4. Under the 'Application Category' option select 'Website Integration' then hit 'Register'.
246 5. Click the 'New Secret' button and accept the prompt that appears. You should now see both a 'Client ID' and 'Client Secret' value which you'll use in the next step.
247 6. Copy the below details and add them as new variables in your `.env` file like so:
248 ```bash
249 # Replace the below (including '{}' braces) with your Twitch Application Id and Secret values.
250 TWITCH_APP_ID={APP_ID}
251 TWITCH_APP_SECRET={APP_SECRET}
252
253 # APP_URL Needs to be set to your BookStack base url
254 APP_URL=http://mybookstackurl.com
255 ```
256 7. All set up! Users will now be able to use Twitch to sign-in and register.
257
258 ---
259
260 ### Discord
261
262 To allow Discord sign-in you'll first need to create an application on the Discord developer site. Here's the process:
263
264 1. Login into the [Discord developer website](https://discordapp.com/developers/applications/me).
265 2. Select 'Create an application'.
266 3. Set a name to identify the application, such as 'BookStack Authentication', and save.
267 4. In the sidebar, Open the 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:
268     - `https://example.com/login/service/discord/callback`
269 5. Back in the 'General Information' section find the 'Client ID' and 'Client Secret' values which you'll use in the next step.
270 6. Copy the below details and add them as new variables in your `.env` file like so:
271 ```bash
272 # Replace the below (including '{}' braces) with your Discord Application Id and Secret values.
273 DISCORD_APP_ID={APP_ID}
274 DISCORD_APP_SECRET={APP_SECRET}
275
276 # APP_URL Needs to be set to your BookStack base url
277 APP_URL=http://mybookstackurl.com
278 ```
279 7. All set up! Users will now be able to use Discord to sign-in and register.