Kris Swat
Kris Swat

Reputation: 1006

Error 400: redirect_uri_mismatch - Google Computer Engine - nginx - SpringBoot - google OAuth

I have a spring boot app running on 8080 (not https as I am not sure if this also need https enabled) There is an nginx server that redirects requests from 80 (or 443/8443) to 8080

The nginx is secured using letsencrypt. I see this domain file in sites-enabled folder

created certificate using

sudo certbot --nginx -d {dom}.co.uk -d www.{dom}.co.uk
server {

    root /var/www/{mydomain}.co.uk/html;
    index index.html index.htm index.nginx-debian.html;

    server_name {mydomain}.co.uk www.{mydomain}.co.uk;

    location / {
            #try_files $uri $uri/ =404;
            proxy_set_header   X-Forwarded-For $remote_addr;
            proxy_set_header   Host $http_host;
            proxy_pass         "http://127.0.0.1:8080";
    }

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/{mydomain}.co.uk/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/{mydomain}.co.uk/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = www.{mydomain}.co.uk) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
if ($host = {mydomain}.co.uk) {
    return 301 https://$host$request_uri;
} # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name {mydomain}.co.uk www.{mydomain}.co.uk;
return 404; # managed by Certbot

}

OAuth 2 settings

In OAuth Credentials

Authorized Javascript urls (For use with requests from a browser)

https://{dom}.co.uk

Authorized redirect URIs (For use with requests from a web server)

https://{dom}.co.uk/login/oauth2/code/google

Configured redirect URL

  private static API_BASE_URL = "https://{dom}.co.uk/";
  private static OAUTH2_URL = AppConstants.API_BASE_URL + "oauth2/authorization/";

Question:

How to fix my

Authorisation Error Error 400: redirect_uri_mismatch

Do I need to make my spring app also https enabled

(OR)

Any config issue nginx or redirect url etc ?

enter image description here

Upvotes: 0

Views: 1095

Answers (1)

ixe013
ixe013

Reputation: 10171

The redirect_uri you send to Google when initiating the flow must match what you put in the console.

Here you have:

  • https://example.co.uk/oauth2/authorization/ in the code and
  • https://example.co.uk/login/oauth2/code/google in the console.

Change either one to match the other. I suggest that you change your code to avoid waiting a good 5 minutes for the changes in the console to propagate.

Upvotes: 1

Related Questions