Summary
I’m trying to setup gitlab auth integration and I get a “Bad response from token request” error
Steps to reproduce
Self-Hosted Mattermost 7.8.5 + Nginx proxy with self signed certificate and tls termination (nginx configuration from official doc)
Self-Hosted Gitlab Omnibus 15.7 with self-signed certificate
Mattermost and Gitlab on separate servers
Expected behavior
Working Mattermost loging through Gitlab auth
Observed behavior
Hello community, I’m trying to setup Gitlab auth for Mattermost but I’m having issue, I saw a lot of post about “bad response from token request” error but I cannot find a solution for my case.
As described before, I have a self hosted Mattermost with an Nginx proxy with self signed certificate and tls termination, and a self hosted Gitlab with self signed certificate too.
Here is my Mattermost config (relevant part for Gitlab integration) :
"SiteURL": "http://chat.example.local"
...
"EnableInsecureOutgoingConnections": true
...
"GitLabSettings": {
"Enable": true,
"Secret": "mysecret",
"Id": "myid",
"Scope": "",
"AuthEndpoint": "https://gitlab.example.local/oauth/authorize",
"TokenEndpoint": "https://gitlab.example.local/oauth/token",
"UserAPIEndpoint": "https://gitlab.example.local/api/v4/user",
"DiscoveryEndpoint": "",
"ButtonText": "",
"ButtonColor": ""
}
Gitlab configuration :
external_url 'https://gitlab.example.local'
...
mattermost_external_url 'http://chat.example.local'
mattermost_nginx['redirect_http_to_https'] = false
mattermost_nginx['ssl_certificate'] = "/etc/gitlab/ssl/mattermost-nginx.crt"
mattermost_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/mattermost-nginx.key"
...
mattermost['gitlab_auth_endpoint'] = "https://gitlab.example.local/oauth/authorize"
mattermost['gitlab_token_endpoint'] = "https://gitlab.example.local/oauth/token"
mattermost['gitlab_user_api_endpoint'] = "https://gitlab.example.local/api/v4/user"
When I try to authenticate myself I get the “bad response from token request error” :
Mattermost logs:
{"timestamp":"2023-05-23 11:58:36.143 +02:00","level":"error","msg":"Bad response from token request.","caller":"web/context.go:117","path":"/signup/gitlab/complete","request_id":"7uz4xxxxxxxxxxxqt4h","ip_addr":"xxx.xxx.xxx.xxx","user_id":"","method":"GET","err_where":"AuthorizeOAuthUser","http_code":500,"error":"AuthorizeOAuthUser: Erreur lors de la récupération du jeton, response_body={\"error\":\"invalid_grant\",\"error_description\":\"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.\"}, status_code=400, error=<nil>"}
Gitlab logs:
xxx.xxx.xxx.xxx - - [23/May/2023:12:02:31 +0200] "GET /oauth/authorize?response_type=code&client_id=zexxxxxxxxxxxxxxg25Yw&redirect_uri=http%3A%2F%2Fchat.example.local%2Fsignup%2Fgitlab%2Fcomplete&state=eyJhY3xxxxxxxxxxxxxxxxxxxxFsc2UiLCJ0b2tlbiI6ImV3amhxxxxxxxxxxxxxxxxxzh0NTk5xxxxxxxxxxxxxxxxh6Zng1NnFjZjxxxxxxxxxxxxxxG4ifQ%3D%3D HTTP/2.0" 200 588 "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" 2.35
yyy.yyy.yyy.yyy (Mattermost IP) - - [23/May/2023:12:02:31 +0200] "POST /oauth/token HTTP/1.1" 400 213 "" "Mattermost-Bot/1.1" -
I have tried different parameters but I cannot get it to work, I don’t see what I’m missing, can anyone help me ?
Best regards,
Frédérick