External accounts
Let people connect Google and Yandex accounts and any mail or calendar server for the calendar and mail.
People can connect their Google or Yandex account, or any mail or calendar server with an app password, in Settings → Accounts. The federation server keeps the connection and works with the account on its own, so the calendar stays up to date even when all of a person's devices are off. Provider tokens never reach the devices; an app password is sent once, when connecting. On the server, tokens and passwords are stored encrypted with your key.
Without this setting nobody can connect an account.
Create a Google OAuth client
- In Google Cloud Console create a project and enable the Google Calendar API.
- Configure the OAuth consent screen: external, the app name, a support address and your domain as an authorized domain.
- Add the scopes
openid,emailandhttps://www.googleapis.com/auth/calendar.readonly, and for mail alsohttps://mail.google.com/. Calendar access is a sensitive scope and mail access a restricted one: until Google verifies your app, only the test users you list on the consent screen can connect (up to 100). - Create an OAuth client of type "Web application" with the redirect URI
https://<your server>/accounts/oauth/callback. - Save the client secret to a file only the server can read.
Create a Yandex OAuth app
- At oauth.yandex.ru create an app of type "Web services" with the
redirect URI
https://<your server>/accounts/oauth/callback. - Give it the access
login:infoandlogin:email, and for mail alsomail:imap_fullandmail:smtp. - Save the client secret to a file only the server can read.
Connecting with a password
This needs nothing from you: once the file is given, people can connect any IMAP/SMTP or CalDAV
server with an app password. The server checks the password before it keeps it, and connects only
to addresses on the public internet. If your people's mail server is on your own network, add
"server_accounts": {"private_networks": true}; "server_accounts": {"enabled": false} turns
password accounts off.
Create an encryption key
head -c 32 /dev/urandom | base64 > external-accounts-current.key
chmod 600 external-accounts-current.keyKeep the key with your database backups: without it, connected accounts cannot be read and people will have to connect them again.
Turn it on
Write a configuration file next to the keys:
{
"secret_keys": ["external-accounts-current.key"],
"google": {
"client_id": "1234567890-abc.apps.googleusercontent.com",
"client_secret_file": "google-client.secret"
},
"yandex": {
"client_id": "0123456789abcdef0123456789abcdef",
"client_secret_file": "yandex-client.secret"
}
}and start the server with --external-accounts=<file> (all options). With several
server processes, every one needs the same file and keys.
Change the key
Put the new key first in secret_keys and keep the old one after it. Tokens move to the new key as
they are refreshed. Remove the old key once every account has synchronized since; an account still
sealed with a removed key asks its owner to connect it again.
Troubleshooting
| What you see | What to do |
|---|---|
| Google says "Access blocked" or "app not verified" | Add the person as a test user on the consent screen, or get the app verified. |
| Google says the redirect URI does not match | The redirect URI of the OAuth client must be exactly https://<your server>/accounts/oauth/callback. |
| An account shows "Authorize again" | Google refused the saved access: the password changed, access was removed in the Google account, or the test user was removed. The person authorizes it again in Settings → Accounts. |
Server log external_account_sync_failed | Google did not answer or answered an error; the server retries on its own, at least once an hour. |