<div dir="ltr">Hey Bill, <div><br></div><div>thanks for the clarification! We&#39;re also building a pure client side JavaScript application which calls a bunch of stateless REST services. I&#39;m looking for the best way to secure those REST services and add a log-in mechanism to the UI. </div>
<div><br></div><div>Now I looked at the new example customer-app-js which will be included in the Alpha 3 release and saw that you are using bearer tokens there. So far, I thought that the HttpOnly cookie mechanism was the preferred way to handle OAuth in a pure client side app which uses stateless REST services. In that scenario, I was just going to add a request interceptor in my JS application, where I would handle unauthorized responses with either a refresh token or a redirect to the log-in page. What do you think?</div>
<div><br></div><div>Cheers,</div><div>Nils</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Mar 11, 2014 at 2:14 PM, Bill Burke <span dir="ltr">&lt;<a href="mailto:bburke@redhat.com" target="_blank">bburke@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The adapters do not set any cookies except the temporary OAUTH *state*<br>
cookie.  The demo examples remember authenticated sessions by storing<br>
the token in the HttpSession.<br>
<br>
The admin console is really just a bunch of stateless REST services<br>
which is why it sets the Identity cookie.  What you&#39;re seeing is a bug<br>
in Resteasy as the cookie is created with HttpOnly set to true.<br>
<br>
<a href="https://issues.jboss.org/browse/RESTEASY-1026" target="_blank">https://issues.jboss.org/browse/RESTEASY-1026</a><br>
<div class=""><br>
On 3/11/2014 8:59 AM, Nils Preusker wrote:<br>
&gt; digging a bit deeper... I looked for usages of HttpFacade.setCookie and<br>
&gt; noticed that HttpOnly always seems to be set to false... If I understood<br>
&gt; the log-in mechanism for pure client side JavaScript applications<br>
&gt; correctly, it was supposed to be based on a HttpOnly cookie, which makes<br>
&gt; it impossible for scripts (so the JavaScript application) to access the<br>
&gt; cookie.<br>
&gt;<br>
&gt; Am I missing something?<br>
&gt;<br>
&gt; Cheers,<br>
&gt; Nils<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Mar 11, 2014 at 12:08 PM, Nils Preusker &lt;<a href="mailto:n.preusker@gmail.com">n.preusker@gmail.com</a><br>
</div><div class="">&gt; &lt;mailto:<a href="mailto:n.preusker@gmail.com">n.preusker@gmail.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     Hey guys,<br>
&gt;<br>
&gt;     I just looked at the login mechanism and the communication between<br>
&gt;     the admin console and the backend in the alpha 2 release again. If<br>
&gt;     I&#39;m not mistaken, you used to use HTTP-only for the<br>
&gt;     KEYCLOAK_SAAS_IDENTITY cookie. Did something change about that in<br>
&gt;     alpha 2? When I look at the HTTP requests in the chrome developer<br>
&gt;     console, I don&#39;t see the HttpOnly flag anywhere.<br>
&gt;<br>
&gt;     Cheers,<br>
&gt;     Nils<br>
&gt;<br>
&gt;<br>
&gt;     On Thu, Jan 30, 2014 at 5:23 PM, Stian Thorgersen &lt;<a href="mailto:stian@redhat.com">stian@redhat.com</a><br>
</div><div class="">&gt;     &lt;mailto:<a href="mailto:stian@redhat.com">stian@redhat.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         ----- Original Message -----<br>
</div><div><div class="h5">&gt;          &gt; From: &quot;Bill Burke&quot; &lt;<a href="mailto:bburke@redhat.com">bburke@redhat.com</a> &lt;mailto:<a href="mailto:bburke@redhat.com">bburke@redhat.com</a>&gt;&gt;<br>
&gt;          &gt; To: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt;         &lt;mailto:<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>&gt;<br>
&gt;          &gt; Sent: Thursday, 30 January, 2014 3:46:52 PM<br>
&gt;          &gt; Subject: Re: [keycloak-user] Keycloak and OAuth 2.0 Resource<br>
&gt;         Owner Password Credentials Grant<br>
&gt;          &gt;<br>
&gt;          &gt;<br>
&gt;          &gt;<br>
&gt;          &gt; On 1/30/2014 9:29 AM, Nils Preusker wrote:<br>
&gt;          &gt; &gt; Hey Bill, thanks for the clarification, I didn&#39;t realize<br>
&gt;         that the cookie<br>
&gt;          &gt; &gt; was Http-only, neat!<br>
&gt;          &gt; &gt;<br>
&gt;          &gt; &gt; We are building a pure HTML5 client that is also hosted<br>
&gt;         separately from<br>
&gt;          &gt; &gt; the REST-backends. The thing is that we use a reverse proxy<br>
&gt;         so for the<br>
&gt;          &gt; &gt; browser it all looks like one app since everything comes<br>
&gt;         from different<br>
&gt;          &gt; &gt; paths in the same domain.<br>
&gt;          &gt; &gt;<br>
&gt;          &gt; &gt; I&#39;ll try to clarify the last part of my last mail: We are<br>
&gt;         currently<br>
&gt;          &gt; &gt; using<br>
&gt;         org.jboss.resteasy.skeleton.key.as7.OAuthAuthenticationServerValve<br>
&gt;          &gt; &gt; (skeleton-key-as7) in our REST-backend modules. If I&#39;m not<br>
&gt;         mistaken,<br>
&gt;          &gt; &gt; some parts of the code base and concepts are the same as in<br>
&gt;         keycloak,<br>
&gt;          &gt; &gt; right?<br>
&gt;          &gt; &gt;<br>
&gt;          &gt; &gt; So far, in the AngularJS application we&#39;ve been adding<br>
&gt;         bearer tokens to<br>
&gt;          &gt; &gt; the HTTP Authorization header. Since the backend uses<br>
&gt;         JAX-RS/ RestEasy,<br>
&gt;          &gt; &gt; the verification of the bearer tokens was done transparently by<br>
&gt;          &gt; &gt; OAuthAuthenticationServerValve and RESTEasy automatically<br>
&gt;         added the<br>
&gt;          &gt; &gt; roles etc. to the HttpServletRequest. Now in the REST<br>
&gt;         backend of the<br>
&gt;          &gt; &gt; admin app in keycloak you&#39;re doing the same thing<br>
&gt;         (validating the tokens<br>
&gt;          &gt; &gt; and extracting the roles) manually with the<br>
&gt;         AuthenticationManager<br>
&gt;          &gt; &gt; (authenticateSaasIdentityCookie(...)). So I was just<br>
&gt;         wondering whether<br>
&gt;          &gt; &gt; you are planning to make that process more transparent in<br>
&gt;         the future?<br>
&gt;          &gt; &gt;<br>
&gt;          &gt;<br>
&gt;          &gt; We&#39;re doing it manually because the original idea was that<br>
&gt;         the admin<br>
&gt;          &gt; service could manage multiple organizations  (a SaaS), so<br>
&gt;         you&#39;d have to<br>
&gt;          &gt; set up the cookie path&#39;s correctly.<br>
&gt;          &gt;<br>
&gt;          &gt; For your app, it sounds like @RolesAllowed will work.  You<br>
&gt;         just have to<br>
&gt;          &gt; set up the appropriate web.xml security constraints for your<br>
&gt;         REST urls<br>
&gt;          &gt; in web.xml.  Just set up the REST apis to require<br>
&gt;         authentication and let<br>
&gt;          &gt; @RolesAllowed do the rest.  The keycloak jboss/wildfly<br>
&gt;         adapter can<br>
&gt;          &gt; handle BEARER token auth at the same time as regular browser<br>
&gt;         oauth.  If<br>
&gt;          &gt; the server is initiating the login, then you can just follow<br>
&gt;         the current<br>
&gt;          &gt; keycloak examples.  If not, then the Javascript lib Stian<br>
&gt;         wrote is an<br>
&gt;          &gt; option (and something we&#39;ll have to document).<br>
&gt;<br>
&gt;         JS lib needs a bit of work as well, if it&#39;s something you want I<br>
&gt;         can make it a priority<br>
&gt;<br>
&gt;          &gt;<br>
&gt;          &gt;<br>
&gt;          &gt;<br>
&gt;          &gt; --<br>
&gt;          &gt; Bill Burke<br>
&gt;          &gt; JBoss, a division of Red Hat<br>
&gt;          &gt; <a href="http://bill.burkecentral.com" target="_blank">http://bill.burkecentral.com</a><br>
&gt;          &gt; _______________________________________________<br>
&gt;          &gt; keycloak-user mailing list<br>
&gt;          &gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
</div></div>&gt;         &lt;mailto:<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>&gt;<br>
<div class="">&gt;          &gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt;          &gt;<br>
&gt;         _______________________________________________<br>
&gt;         keycloak-user mailing list<br>
</div>&gt;         <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a> &lt;mailto:<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>&gt;<br>
<div class="HOEnZb"><div class="h5">&gt;         <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; keycloak-user mailing list<br>
&gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt;<br>
<br>
--<br>
Bill Burke<br>
JBoss, a division of Red Hat<br>
<a href="http://bill.burkecentral.com" target="_blank">http://bill.burkecentral.com</a><br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</div></div></blockquote></div><br></div>