CORS issue in JavaScript adapter

504 views
Skip to first unread message

Huy Banh

unread,
May 4, 2021, 1:56:14 AM5/4/21
to Keycloak User
Hello all,

I am running Keycloak standalone. I have a client setup with access type 'confidential' and authorization enabled.

I want to use the javascript adapter for our gwt application.

1. First issue, the doc says I need access type of 'public' to use the javascript adapter. However, with public access type I can't have authorization enabled. So, can I use the javascript adapter with confidential access type. It seems to work till the cors issue below.

2. I have Keycloak instantiated, init(), login() as below:

var keycloak = new Keycloak({
    realm: 'realm1',
    clientId: 'client1',
    'enable-cors': true
});

keycloak.init({onLoad: 'login-required'});

keycloak.login({'redirectUri':'http://localhost:9000/cc/'});

I have web-origins set up with + or * or http://localhost. I also have valid-redirect-urls setup properly.

The login is presented. I can login. It redirects to my second page properly.

In this second page I see cors error for a post request, which I believe by the adapter to exchange access code for access token.

Tried with all possible web-origins (+/*/http://localhost), but still cors error (No 'Access-Control-Allow-Origin' header is present on the requested resource

3- I tried NOT to use localhost for avoid cors issue. Tried to start with a specific IP neither work for me (./standalone.sh -b 192.168.86.61) (or -bmanagement or edit standalone.xml file). 

I am stuck. I would appreciate if someone can help, points out what I did wrong.

Thank you.

Huy Banh

unread,
May 4, 2021, 12:30:52 PM5/4/21
to Keycloak User
Updated: It was the firewall that failed the networking binding. With a specific IP address, the cors error has gone too.

I have also created the second client with public access type for the UI. The first client with confidential access type for the server app. This seems to all working for me.

Thanks.

Reply all
Reply to author
Forward
0 new messages