---
title: Integrate with Mattermost Team Edition
sidebar_label: Mattermost Team Edition
support_level: community
---

import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";

## What is Mattermost Team Edition

> Mattermost is an open source, real-time collaboration platform. It provides chat, audio/video calling, screen sharing, and a plugin architecture for extending its capabilities. Mattermost Team Edition is the free, open-source version of the product.
>
> -- https://mattermost.com/

## Preparation

The following placeholders are used in this guide:

- `mattermost.company` is the FQDN of the Mattermost installation.
- `authentik.company` is the FQDN of the authentik installation.

:::info
This documentation lists only the settings that you need to change from their default values. Be aware that any changes other than those explicitly mentioned in this guide could cause issues accessing your application.
:::

## Configuration methods

You can configure Mattermost to use either OIDC or SAML, and this guide explains both options.

<Tabs
  defaultValue="oidc"
  values={[
    { label: "Log in with OIDC", value: "oidc" },
    { label: "Log in with SAML", value: "saml" },
  ]}>
  <TabItem value="oidc">

:::info Mattermost OIDC support
Mattermost Team Edition does not natively support generic single sign-on. However, you can manually configure Mattermost to use its GitLab integration for authentication via authentik's OAuth2/OpenID Provider. This requires editing the `config.json` file directly, as the necessary settings are not available through the web interface. If you are using a hosted version of Mattermost without filesystem access, you will not be able to complete this setup.

Once configured, Mattermost will display a login button with the GitLab icon, but authentication will be handled entirely by authentik. GitLab itself is not required or used in any way.
:::

## authentik configuration

To support the integration of Mattermost Team Edition with authentik, you need to create property mappings and an application/provider pair in authentik.

### Create property mappings

1. Log in to authentik as an administrator and open the authentik Admin interface.
2. Navigate to **Customization** > **Property Mappings** and click **Create**. Create a **Scope Mapping** with the following settings:
    - **Name**: `mattermost-username`
    - **Scope Name**: `username`
    - **Description**: `Maps the user's authentik username to the username field for Mattermost authentication.`
    - **Expression**:
        ```python
        return {
            "username": request.user.username,
        }
        ```

:::info
The following `id` property mapping is optional. If omitted, Mattermost will generate user IDs based on email addresses, resulting in names such as `person-example.com` for `person@example.com`. Since these IDs serve as nicknames, this format may be undesirable.
:::

3. If desired, click **Create** again, and create another **Scope Mapping** with the following settings:
    - **Name**: `mattermost-id`
    - **Scope Name**: `id`
    - **Description**: `Maps the user's Mattermost ID or primary key to the id field for Mattermost authentication.`
    - **Expression**:
        ```python
        return {
            "id": request.user.attributes.get("mattermostId", request.user.pk),
        }
        ```

### Create an application and provider in authentik

1. Log in to authentik as an administrator and open the authentik Admin interface.
2. Navigate to **Applications** > **Applications** and click **Create with Provider** to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
    - **Application**: provide a descriptive name, an optional group for the type of application, and the policy engine mode. Take note of the **Slug** value because it will be required later.
    - **Choose a Provider type**: select **OAuth2/OpenID Connect** as the provider type.
    - **Configure the Provider**: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations.
        - Note the **Client ID** and **Client Secret** values because they will be required later.
        - Set a `Strict` redirect URI to `https://mattermost.company/signup/gitlab/complete`.
        - Select any available signing key.
        - Under **Advanced protocol settings**, add the scopes you just created to the list of selected scopes.
    - **Configure Bindings** _(optional)_: you can create a [binding](/docs/add-secure-apps/bindings-overview/) (policy, group, or user) to manage the listing and access to applications on a user's **My applications** page.

3. Click **Submit** to save the new application and provider.

## Mattermost Team Edition configuration

To support the integration of Mattermost Team Edition with authentik, you'll need to update the `config.json` file of your Mattermost deployment:

1. Modify the `GitLabSettings` section to look like the following:

```json showLineNumbers title="/opt/mattermost/config/config.json"
"GitLabSettings": {
    "Enable": true,
    "Secret": "<client_secret>",
    "Id": "<client_id>",
    "Scope": "",
    "AuthEndpoint": "https://authentik.company/application/o/authorize/",
    "TokenEndpoint": "https://authentik.company/application/o/token/",
    "UserAPIEndpoint": "https://authentik.company/application/o/userinfo/",
    "DiscoveryEndpoint": "https://authentik.company/application/o/<application_slug>/.well-known/openid-configuration",
    "ButtonText": "Log in with authentik",
    "ButtonColor": "#000000"
},
```

2. Log in to Mattermost as an administrator and navigate to the System Console. Go to **Authentication** > **Signup** options (`https://mattermost.company/admin_console/authentication/signup`) and make sure that **Enable Account Creation** is set to **true**.
3. Restart Mattermost to apply the changes.

</TabItem>

  <TabItem value="saml">

:::info License required
SAML authentication with encryption requires Mattermost Enterprise Edition or a licensed version. Mattermost Team Edition does not natively support SAML. If you are using Mattermost Team Edition, use OIDC instead.
:::

## Preparation

Before configuring SAML, you need to generate a certificate key pair for Mattermost to use for signing and decryption.

### Generate a certificate key pair for Mattermost

Generate a public certificate and private key pair for Mattermost:

```bash
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
    -keyout mattermost-private.key \
    -out mattermost-public.crt \
    -subj "/CN=mattermost.company"
```

Keep these files safe. You will upload the public certificate to authentik and both files to Mattermost.

## authentik configuration

To support the integration of Mattermost with authentik via SAML, you need to upload the Mattermost certificate and create an application/provider pair in authentik.

### Upload Mattermost's certificate to authentik

1. Log in to authentik as an administrator and open the authentik Admin interface.
2. Navigate to **System** > **Certificates** and click **Import**.
3. Give it a name like `Mattermost Certificate`.
4. Paste the contents of `mattermost-public.crt` into the **Certificate** field.
5. Leave the **Private Key** field empty (authentik only needs the public certificate for verification and encryption).
6. Click **Create**.

### Create an application and provider in authentik

1. Log in to authentik as an administrator and open the authentik Admin interface.
2. Navigate to **Applications** > **Applications** and click **Create with Provider** to create an application and provider pair.
    - **Application**: provide a descriptive name (e.g., `Mattermost`), an optional group for the type of application, and the policy engine mode. Take note of the **slug** as it will be required later.
    - **Choose a Provider type**: select **SAML Provider** as the provider type.
    - **Configure the Provider**: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations:
        - Set the **ACS URL** to `https://mattermost.company/login/sso/saml`.
        - Set the **Issuer** to `authentik`.
        - Set the **Service Provider Binding** to `Post`.
        - Under **Advanced protocol settings**:
            - Set the **Signing Certificate** to any available authentik certificate (e.g., the default self-signed certificate).
            - Enable **Sign assertions**.
            - Enable **Sign responses**.
            - Set the **Verification Certificate** to the Mattermost certificate you uploaded earlier.
            - Set the **Encryption Certificate** to the Mattermost certificate you uploaded earlier.
    - **Configure Bindings** _(optional)_: you can create a [binding](/docs/add-secure-apps/bindings-overview/) (policy, group, or user) to manage the listing and access to applications on a user's **My applications** page.

3. Click **Submit** to save the new application and provider.

### Download the authentik signing certificate

1. Navigate to **System** > **Certificates**.
2. Find the certificate you selected as the **Signing Certificate** for the SAML provider.
3. Click the certificate name, then click **Download Certificate** to download the public certificate file.

## Mattermost configuration

1. Log in to Mattermost as an administrator.
2. Navigate to **Channels** > **System Console** > **Authentication** > **SAML 2.0**.
3. Configure the following settings:
    - Enable **Enable Login With SAML 2.0**.
    - Set **SAML SSO URL** to `https://authentik.company/application/saml/<application_slug>/sso/binding/redirect/`.
    - Set **Identity Provider Issuer URL** to `authentik`.
    - Set **Identity Provider Public Certificate** to the contents of the authentik signing certificate you downloaded.
    - Enable **Verify Signature**.
    - Set **Service Provider Login URL** to `https://mattermost.company/login/sso/saml`.
    - Set **Service Provider Identifier** to `authentik`.
    - Set **Service Provider Private Key** to `mattermost-private.key`.
    - Set **Service Provider Public Certificate** to `mattermost-public.crt`.
    - Enable **Enable Encryption**.
    - Enable **Sign Request**.
    - Set **Signature Algorithm** to `RSAwithSHA256`.
    - Set **Email Attribute** to `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress`.
    - Set **Username Attribute** to `http://schemas.goauthentik.io/2021/02/saml/username`.
    - Set **Id Attribute** to `http://schemas.goauthentik.io/2021/02/saml/uid` (optional).
4. Click **Save**.

</TabItem>
</Tabs>

## Configuration verification

To verify the integration of authentik with Mattermost, log out and attempt to log back in. You should see a login button for authentik on the login page, and a successful login should redirect you to Mattermost without any errors.

## Troubleshooting

- **Missing email or username error**: If logging in with SAML, ensure that any users logging into Mattermost from authentik have both an email address and username set in their authentik profile.

## Resources

- [Mattermost on Github](https://github.com/mattermost/mattermost)
- [Mattermost GitLab Authentication documentation](https://docs.mattermost.com/configure/authentication-configuration-settings.html#gitlab-oauth-2-0-settings)
- [Mattermost SAML Configuration documentation](https://docs.mattermost.com/configure/authentication-configuration-settings.html#saml-2-0)
- [Related blog post, in German, explaining the OIDC technique](https://ayedo.de/posts/mattermost-self-hosted-sso-mit-authentik/)
