Migrate all users from email to GitLab SSO as sysadmin

We have had a Mattermost server running for a couple of years, and a lot of our users have created an account with their email, as that was all we had available. Now we have the ability to use GitLab authentication and we want to migrate all users to that solution to be able to use SSO and a single password for multiple services.

I first saw this feature in the mattermost, and thought it was perfect:

mattermost user migrate_auth {from_auth} {to_auth} {match_field}

Well, that didn’t work because Mattermost has not built support for migrating to_auth = gitlab. Gitlab is only supported as from_auth.

So my next thought was using the Mattermost API to first change the password to a temporary one

https://your-mattermost-url.com/api/v4/users/{user_id}/password

followed by using this to change the authentication method:

https://your-mattermost-url.com/api/v4/users/login/switch

However, that gives you a follow-link that need to authenticate with the new method. So I can’t script it and do it for all users.

So, how do I change all users at once to GitLab auth?

If you have the user’s all become required to sign in using GitLab, that may be an option to force your users to create/link their accounts with GitLab and skip migrating entirely. User signup can still be restricted to a specific email domain, of course.