patternfly/angular-patternfly

Issue with using angular-bootstrap-prettify and keycloak.js adapter

Closed this issue · 7 comments

keycloak.js has this function called decodeToken, .Which decodes the jwt token and works fine.

 function decodeToken(str) {
        .......
          str = decodeURIComponent(escape(atob(str)));

          str = JSON.parse(str);
          return str;
      }

str would look like this

str ="{"jti":"8d95f811-7e4b-4874-9b7c-4d9908e234","exp":151434601,"nbf":0,"iat":1510849601,"iss":"https://localhost/auth/realms/demo","aud":"productapp","sub"..,"resource_access":{"account":{"roles":["dsf","view-profile"]}}}"

Now this will jump to escape function in
angular-bootstrap-prettify.js

function escape(text) {
  return text.
    replace(/\&/g, '&').
    replace(/\</g, '&lt;').
    replace(/\>/g, '&gt;').
    replace(/"/g, '&quot;');
}

Which will replace " to &quot

"{&quot;jti&quot;:&quot;85fa15e8-1435-47c5-833d-f15d77c79e22&quot;,&quot;exp&quot;:1510884333,&quot;nbf&quot;:0,&quot;iat&quot;:1510848333,&quot;iss&quot;:&quot;https://auth.dev.redhat.com/auth/realms/demoquot;,&quot;aud&quot;:&quot;performance-develop-jstest&quot;,&quot;sub&quot;:&quot;0203bd27-279b-47e1-916e-....&quot;]}}}"

Now in keycloak.js (decodeToken) will fail to parse the str due to replace characters.
str = JSON.parse(str);

Looks like the issue is with including angular-bootstrap-prettify.js rather than an issue with angular-patternfly.

@jeff-phillips-18: yeah, to be more correct. I saw this #108 and #109. Is angular-bootstrap-prettify has been removed from the package or going to discontinue once the mentioned issue got fixed?

It is still in our docs area but that should not effect applications. Are you doing development in angular-patternfly? I will look into removing it from our docs area.

@jeff-phillips-18: yes, we are using angular-patternfly for our application. thanks

@jeff-phillips-18: Previous developer on this application was using this library. I think, we don't need this one. I removed it.

OK @akoserwal, going to close this issue then.