0

I am using keycloakjs version 10.0.2 and my keycloak server is of version 10.0.2, I am not able to authorize user in keycloakjs, browser console gets the following error,I tried configuring keycloak for this realm web origins * + nothing did work. Please give me some idea on where I am going wrong :

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://yyyy.xxxx.com/auth/realms/test/protocol/openid-connect/token. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 401

code part :

         <html><head>

   <script src="http://localhost:81/auth/js/keycloak.js" type="text/javascript">             </script>

    <script type="text/javascript">
     const keycloak = Keycloak({
       "realm": "test",
       "auth-server-url": "https://yyyy.xxxx.com/auth",
       "ssl-required": "external",
       "resource": "account",
       "public-client": true,
       "confidential-port": 0,
       "url": 'https://yyyy.xxxx.com/auth',
        "clientId": 'account',
        "enable-cors": true
       });
      const loadData = () => {
         console.log(keycloak.subject);
         if (keycloak.idToken) {
           document.location.href = "?user="+keycloak.idTokenParsed.preferred_username;
          console.log('IDToken');
          console.log(keycloak.idTokenParsed.preferred_username);
          console.log(keycloak.idTokenParsed.email);
          console.log(keycloak.idTokenParsed.name);
          console.log(keycloak.idTokenParsed.given_name);
         console.log(keycloak.idTokenParsed.family_name);

      } else {
keycloak.loadUserProfile(function() {
    console.log('Account Service');
    console.log(keycloak.profile.username);
    console.log(keycloak.profile.email);
    console.log(keycloak.profile.firstName + ' ' + keycloak.profile.lastName);
    console.log(keycloak.profile.firstName);
    console.log(keycloak.profile.lastName);
}, function() {
    console.log('Failed to retrieve user details. Please enable claims or account role');
          });
         }
       };

        const loadFailure =  () => {
           console.log('Failed to load data.  Check console log');
        };
        const reloadData = () => {
            keycloak.updateToken(10)
                .success(loadData)
         .error(() => {
            console.log('Failed to load data.  User is logged out.');
        });
     }
        keycloak.init({ onLoad: 'login-required' }).success(reloadData);
      </script>
      </head>
       <body>

       </body>
      </html>

Regards Kris

chiku
  • 485
  • 2
  • 8
  • 23
  • the problem is keycloak configuration, can I get some inputs from keycloak professional? referred to this link https://stackoverflow.com/questions/45051923/keycloak-angular-no-access-control-allow-origin-header-is-present the inputs were not useful – chiku May 23 '22 at 15:22
  • https://www.keycloak.org/docs/latest/securing_apps/#_java_adapter_config – Quentin May 23 '22 at 15:48
  • @Quentin thanks for the info, this issue is resolved – chiku May 24 '22 at 03:38

0 Answers0