Keycloak and Google OAuth 2.0 redirect URI mismatch

141 views Asked by At

i have site https://fm.xxxxx.com domain was register

and i use some load-balancer as nginx with redirect configuration for keycloak

server {
        listen 80;
        listen [::]:80;
        server_name fm.xxxxx.com;
        return 301 https://fm.xxxxx.com;
}

server {
  listen 443 ssl;
  server_name fm.xxxxx.com;

  ssl_certificate /etc/nginx/certificate/xxxxx.crt;
  ssl_certificate_key /etc/nginx/certificate/xxxxx.key;

 location /realms/fm-users/ {
    proxy_read_timeout 90;
    proxy_pass http://fm-keycloak:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Scheme $scheme;

    client_max_body_size 30m;
 }

 location /resources/ {
    proxy_read_timeout 90;
    proxy_pass http://fm-keycloak:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Scheme $scheme;

    client_max_body_size 30m;
 }...

when i try to setup google identity provider in keycloak i created google provider, and use Redirect URI in google configuration

enter image description here

but google doesnt like URI

enter image description here

i cant change redirect uri in keycloak identity provider and it is invalid for google

i tried use domain instead ip

enter image description here

but it send error when i try login use google

Error 400: redirect_uri_mismatch ofcourse

enter image description here

enter image description here

my site use https, keycloak not

how can i change redirect URI in identity provider in keycloak?

or what can i do?

i tried add redirectUri parameter to keycloak import.json file and add redirectUri parameter to identity_provider_config table in keycloak DB it doesnt help

when i used 127.0.0.1 and run all locally its works but i need it for prod and use domain in keycloak or ip in google

maybe i need to create some redirect using nginx.conf?

1

There are 1 answers

2
user22958704 On

I just needed to copy the redirect uri from the error to the url google credential.

The port was redundant.