Google OAuth Installed Application Flow: redirect_uri_mismatch
<p>I am trying to follow this guide: <a href="https://developers.google.com/identity/protocols/OAuth2InstalledApp#example" rel="noreferrer">Using OAuth 2.0 for Installed Applications</a></p>

<p>I get past the first part OK where a user can authorize my app to access their Google Drive. I have successfully retrieved the authorization code after the user grants permission.</p>

<p>Unfortunately I get stuck on the second part: I keep hitting a <code>redirect_uri_mismatch</code> error when sending the POST request to exchange the authorization code for an access token.</p>

<p>The guidance says I should use "The redirect URI you obtained from the Developers Console". I downloaded the credentials from this link in the developers console:</p>

<p><a href="https://i.stack.imgur.com/IDdoo.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/IDdoo.jpg" alt="Google developer console"></a></p>

<p>Which contained a JSON with the following property:</p>

<pre><code>"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
</code></pre>

<p>I have tried the request setting <code>redirect_uri</code> to each of these options; I have tried with setting it to an empty string; I have also tried with it missing altogether. Nothing works.</p>

<p>Each time I hit the <code>redirect_uri_mismatch</code> error.</p>

<p>I have also tried posting to this URL from the downloaded credentials:</p>

<pre><code>"token_uri":"https://accounts.google.com/o/oauth2/token"
</code></pre>

<p>and also the URL from the guidance page (<a href="https://www.googleapis.com//oauth2/v4/token" rel="noreferrer">https://www.googleapis.com//oauth2/v4/token</a>) but each time I hit the same error.</p>

<p>How can I resolve this error and successfully exchange the authorisation code for an access token?</p>

<p>Screenshot example from Fiddler showing one of the many requests I have attempted:</p>

<p><a href="https://i.stack.imgur.com/r9z2Z.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/r9z2Z.jpg" alt="Fiddler screenshot"></a></p>

<p>Or a raw HTTP Request example:</p>

<pre><code>POST https://accounts.google.com/o/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: accounts.google.com
Content-Length: 253
Expect: 100-continue
Connection: Keep-Alive

client_id=175836713882-m783k1ksu2rc6vepq35j4o8hhpk94ndj.apps.googleusercontent.com&amp;client_secret=A---removed-for-security---A&amp;code=4---removed-for-security---E&amp;grant_type=authorization_code&amp;redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob
</code></pre>

<p><strong>N.B. I am aware there are many answered questions on SO about this error with respect to miss-spells of redirect URIs for those following the <a href="https://developers.google.com/identity/protocols/OAuth2WebServer" rel="noreferrer">Web App Authentication flow</a> but this specifically relates to the <a href="https://developers.google.com/identity/protocols/OAuth2InstalledApp" rel="noreferrer">Installed application flow</a>. I could find no answered questions relating to this error message on the Installed Application flow</strong></p>