title: Google Oauth Error: redirect_uri_mismatch
body: <p>I'm trying to use google Oauth 2 to authenticate with google calendar API for a web server running on AWS EC2.</p>
  
  <p>When I generated the credentials I selected 'OAuth Client ID' and then 'Web Application'. For the Authorised redirect URIs I have entered:</p>
  
  <p><a href="http://ec2-XX-XX-XX-XXX.eu-west-1.compute.amazonaws.com" rel="nofollow noreferrer">http://ec2-XX-XX-XX-XXX.eu-west-1.compute.amazonaws.com</a>
  (I've blanked out the IP of my EC2 instance). I have checked this is the correct URL that I want the callback to go to. </p>
  
  <p>The link that is generated in the server logs is of the form:</p>
  
  <p><a href="https://accounts.google.com/o/oauth2/auth?access_type=offline&amp;client_id=XXXXXXXXXXXX-XXXXXXXXXXXXXX.apps.googleusercontent.com&amp;redirect_uri=http://localhost:47258/Callback&amp;response_type=code&amp;scope=https://www.googleapis.com/auth/calendar.readonly" rel="nofollow noreferrer">https://accounts.google.com/o/oauth2/auth?access_type=offline&amp;client_id=XXXXXXXXXXXX-XXXXXXXXXXXXXX.apps.googleusercontent.com&amp;redirect_uri=http://localhost:47258/Callback&amp;response_type=code&amp;scope=https://www.googleapis.com/auth/calendar.readonly</a></p>
  
  <p>When I follow the link I get the error
  'Error: redirect_uri_mismatch'.</p>
  
  <p>I've read <a href="https://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch">this SO question</a> and have checked that I am using HTTP and there is no trialing '/'</p>
  
  <p>I suspect that the URL generated should not have 'localhost' in it but I've reset the client_secret.json several times and each time I restart tomcat with the new client secret I still get a link with localhost but just over a different port. </p>
  
  <p>Locally, I had selected Credentials type of 'other' previously and was not given an option for the Authorised redirect URI. I did try this for the EC2 instance but this won't give me the control I want over the redirect URI and sends the redirect over localhost.</p>