Mattermost, Inc.

I get Bad Request response from OAuth

Summary

Trying to obtain OAuth token from Mattermost, I get 400 Bad Request

Steps to reproduce

I have successfully sent a GET request to /oauth/authorize with response_type=code, client_id, redirect_url. Mattermost has called me back at the redirect_url, and sent a code in its GET request.

Then I POSTed to /oauth/authorize with a json object, but received a 400 Bad Request instead of the token information I expected. See log below.

Expected behavior

See above

Observed behavior

	Sent -> Method: POST, RequestUri: 'http://ubuntu:8065/oauth/authorize', Version: 2.0, Content: System.Net.Http.StringContent, Headers:
	{
	  Authorization: Bearer (removed)
	  Accept: application/json
	  Accept: text/html
	  Accept: */*
	  User-Agent: XR
	  User-Agent: Mattermost
	  User-Agent: Tool
	  Content-Type: application/json; charset=utf-8
	}:{
	  "grant_type": "authorization_code",
	  "client_id": "(removed)",
	  "redirect_uri": "http://localhost:9998/",
	  "client_secret": "(removed)",
	  "code": "(removed)"
	}

The response was thus:

	Received -> StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
	{
	  X-Request-ID: tjpnqwkuyb8ffe3cxk35ydydsr
	  X-Version-Id: 5.11.0.5.11.0.368dcfca505c267d13c6d7f53aaceb93.false
	  Date: Thu, 27 Jun 2019 16:30:36 GMT
	  Content-Type: text/html
	  Content-Length: 614
	}

I just realised from studying the source that I should be calling oauth/access_token not oauth/authorize.

I changed that, and now I get a page containing “invalid_request: Bad grant_type”. Looking at the source, the grant_type should be ACCESS_TOKEN_GRANT_TYPE, and this is defined in access.go as "authorization_code". But that is what I am using, so I’m confused.

Hi @nikkilocke,

Is your issue related to Gitlab? Wondering if this might help: Bad response from token request after team creation auth.

No, nothing to do with GitLab. Just plain OAuth with Mattermost and my app.