<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi Davide,<br>
      <br>
      I would suggest to change your flow a bit. You have frontend JEE
      servlet application, which is authenticated with Keycloak. So I
      think that you don't need any Keycloak accessTokens to be shared
      with your AngularJS dashboard at all. I would suggest that your
      AngularJS dashboard won't communicate directly with your JAX-RS
      backend application, but instead it will communicate just with
      your servlet JEE application, which will then re-send request to
      JAX-RS application with the usage of KeycloakSecurityContext as
      shown in the customer-portal example. So assuming that your
      frontend application is on <br>
      <a class="moz-txt-link-rfc2396E" href="http://localhost:8080/frontend">"http://localhost:8080/frontend"</a> and your JAX-RS is at
      <a class="moz-txt-link-rfc2396E" href="http://localhost:8080/backend">"http://localhost:8080/backend"</a> you can do:<br>
      <pre style="color:rgb(0,0,0)">1- The user call <a class="moz-txt-link-freetext" href="http://.../frontend">http://.../frontend</a></pre>
      <pre style="color:rgb(0,0,0)">2- The&nbsp;<span style="font-family:arial">frontend </span><span style="font-family:arial">server redirects to the keycloak login</span></pre>
      <pre style="color:rgb(0,0,0)">3- Keycloak authenticates the user and redirects to frontend <span style="font-family:arial">server</span></pre>
      <pre style="color:rgb(0,0,0)">4- The frontend server serves the AngularJS dashboard but NOT injecting the token (So angularJS and your browser don't have direct access to token at all)

5- User clicks to something in AngularJS app, which will send request to <a class="moz-txt-link-freetext" href="http://localhost:8080/frontend/someEndpoint">http://localhost:8080/frontend/someEndpoint</a>

6- Frontend will re-send this to <a class="moz-txt-link-freetext" href="http://localhost:8080/backend/someBackendEndpoint">http://localhost:8080/backend/someBackendEndpoint</a> similarly as shown in examples, which will ensure that frontend application will attach Bearer token to the request

7- After backend request is done and received in "frontend" app, it will resend it back to AngularJS with all the data.

So your frontend app will be defacto  proxy between AngularJS and "backend" JAX-RS application. With this design, you won't see any CORS related issues, which you currently have. And also you won't need to solve things like 
refreshing tokens etc.  as this is done automatically by adapter of JEE frontend application. So that's my suggestion.

Marek
</pre>
      <br>
      <br>
      On 15.4.2014 01:43, Davide Ungari wrote:<br>
    </div>
    <blockquote
cite="mid:CA+TL3n1e_bpPiGkR+R5dizYwEAKD0mFALDMFiLrgDjsT+7qbGg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <pre style="color:rgb(0,0,0)">Hi Bill,
<span style="font-family:arial">it's a mixed approach, maybe this is confusing you.</span></pre>
        <pre style="color:rgb(0,0,0)">&gt; I don't understand what the flow is below.  In your flow above you said 
&gt; your server is making a call to the backend service with the token and 
&gt; is authenticated correctly, right?</pre>
        <pre style="color:rgb(0,0,0)">My frontend is a WAR running on Tomcat and i<span style="font-family:arial">t is secured by keycloak.</span></pre>
        <pre style="color:rgb(0,0,0)"><span style="font-family:arial">&gt; What I don't understand is what you are doing below.  Are you saying you 
</span><span style="font-family:arial">&gt; have a Browser client (Javascript) making a call to your backend?</span></pre>
        <pre style="color:rgb(0,0,0)">The WAR serves also an AngularJS dashboard, in this dashboard I "inject" the token from the server but then I make client side calls.</pre>
        <pre style="color:rgb(0,0,0)">The flow is:</pre>
        <pre style="color:rgb(0,0,0)">1- The user call <a class="moz-txt-link-freetext" href="http://.../dashboard">http://.../dashboard</a></pre>
        <pre style="color:rgb(0,0,0)">2- The&nbsp;<span style="font-family:arial">frontend </span><span style="font-family:arial">server redirects to the keycloak login</span></pre>
        <pre style="color:rgb(0,0,0)">3- Keycloak authenticates the user and redirects to frontend <span style="font-family:arial">server</span></pre>
        <pre style="color:rgb(0,0,0)">4- The frontend server serves the AngularJS dashboard injecting the token</pre>
        <pre style="color:rgb(0,0,0)">5- The client side dashboard makes ajax calls to the backend to load data</pre>
        <pre style="color:rgb(0,0,0)">At point 5 I see my backend is logging that the call is AUTHENTICATED but on client side I see the response is failing.</pre>
        <pre style="color:rgb(0,0,0)">
</pre>
        <div>
          <div>--</div>
          Davide</div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </body>
</html>